forked from filipg/aitech-eks-pub
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
#procedura napisywania plików ipynb (generowanie nagłówka i metadanych)
|
||
|
import json
|
||
|
import sys
|
||
|
|
||
|
|
||
|
def modjup(filen,numer,tytul,typ,author,email,lang,title,year):
|
||
|
zerocell=['![Logo 1](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech1.jpg)\n',
|
||
|
'<div class="alert alert-block alert-info">\n',
|
||
|
'<h1> %s </h1>\n'%(title),
|
||
|
'<h2> %s. <i>%s</i> [%s]</h2> \n'%(numer,tytul,typ),
|
||
|
'<h3> %s (%s)</h3>\n'%(author,year),
|
||
|
'</div>\n',
|
||
|
'\n',
|
||
|
'![Logo 2](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech2.jpg)']
|
||
|
zerodict={'cell_type': 'markdown','metadata': {'collapsed': False},'source': zerocell}
|
||
|
with open(filen, 'r+',encoding='utf-8') as f:
|
||
|
ll=json.load(f)
|
||
|
ll["metadata"]["author"]=author
|
||
|
ll["metadata"]["email"]=email
|
||
|
ll["metadata"]["lang"]=lang
|
||
|
subtitle="%s.%s[%s]"%(numer,tytul,typ)
|
||
|
ll["metadata"]["subtitle"]=subtitle
|
||
|
ll["metadata"]["title"]=title
|
||
|
ll["metadata"]["year"]=year
|
||
|
|
||
|
if not(ll['cells'][0]['source'][0]==zerocell[0]):
|
||
|
ll['cells'].insert(0,zerodict)
|
||
|
else:
|
||
|
ll['cells'][0]=zerodict
|
||
|
f.seek(0)
|
||
|
json.dump(ll,f,indent=4)
|
||
|
|
||
|
#zmodyfikuj te dane
|
||
|
filen=sys.argv[1]
|
||
|
|
||
|
numer="2"
|
||
|
tytul=sys.argv[2]
|
||
|
typ="wykład"
|
||
|
|
||
|
author="Filip Graliński"
|
||
|
email="filipg@amu.edu.pl"
|
||
|
lang= "pl"
|
||
|
title="Ekstrakcja informacji"
|
||
|
year="2021"
|
||
|
|
||
|
#uruchom procedurę
|
||
|
modjup(filen,numer,tytul,typ,author,email,lang,title,year)
|