Szablon/json_script.ipynb
2021-09-23 13:15:46 +02:00

111 lines
3.1 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 92,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#procedura napisywania plików ipynb (generowanie nagłówka i metadanych)\n",
"import json\n",
"\n",
"def modjup(filen,numer,tytul,typ,author,email,lang,title,year):\n",
" zerocell=['![Logo 1](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech1.jpg)\\n',\n",
" '<div class=\"alert alert-block alert-info\">\\n', \n",
" '<h1> %s </h1>\\n'%(title),\n",
" '<h2> %s. <i>%s</i> [%s]</h2> \\n'%(numer,tytul,typ),\n",
" '<h3> %s (%s)</h3>\\n'%(author,year),\n",
" '</div>\\n',\n",
" '\\n',\n",
" '![Logo 2](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech2.jpg)']\n",
" zerodict={'cell_type': 'markdown','metadata': {'collapsed': False},'source': zerocell}\n",
" with open(filen, 'r+',encoding='utf-8') as f:\n",
" ll=json.load(f)\n",
" ll[\"metadata\"][\"author\"]=author\n",
" ll[\"metadata\"][\"email\"]=email\n",
" ll[\"metadata\"][\"lang\"]=lang\n",
" subtitle=\"%s.%s[%s]\"%(numer,tytul,typ)\n",
" ll[\"metadata\"][\"subtitle\"]=subtitle\n",
" ll[\"metadata\"][\"title\"]=title\n",
" ll[\"metadata\"][\"year\"]=year\n",
" \n",
" if not(ll['cells'][0]['source'][0]==zerocell[0]):\n",
" ll['cells'].insert(0,zerodict)\n",
" else:\n",
" ll['cells'][0]=zerodict\n",
" f.seek(0)\n",
" json.dump(ll,f,indent=4)"
]
},
{
"cell_type": "code",
"execution_count": 93,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"#zmodyfikuj te dane\n",
"filen=\"szablon-1.ipynb\"\n",
"\n",
"numer=\"Numer\"\n",
"tytul=\"Tytul materiału\"\n",
"typ=\"laboratoria/wykład\"\n",
"\n",
"author=\"Imię Nazwisko\"\n",
"email=\"adres@email.com\"\n",
"lang= \"pl\"\n",
"title=\"Nazwa przedmiotu\"\n",
"year=\"Rok\"\n",
"\n",
"#uruchom procedurę\n",
"modjup(filen,numer,tytul,typ,author,email,lang,title,year)"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (system-wide)",
"language": "python",
"metadata": {
"cocalc": {
"description": "Python 3 programming language",
"priority": 100,
"url": "https://www.python.org/"
}
},
"name": "python3",
"resource_dir": "/ext/jupyter/kernels/python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}