diff --git a/add-metadata.py b/add-metadata.py new file mode 100755 index 0000000..6a3a737 --- /dev/null +++ b/add-metadata.py @@ -0,0 +1,49 @@ +#!/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', + '
\n', + '

%s

\n'%(title), + '

%s. %s [%s]

\n'%(numer,tytul,typ), + '

%s (%s)

\n'%(author,year), + '
\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)