{
"cells": [
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OrderedDict([('result', 'Success'),\n",
" ('pageid', 38082),\n",
" ('title', 'Test with the Diffbot'),\n",
" ('contentmodel', 'wikitext'),\n",
" ('oldrevid', 218752),\n",
" ('newrevid', 218753),\n",
" ('newtimestamp', '2022-05-31T10:39:36Z')])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import mwclient\n",
"\n",
"site = mwclient.Site('pzwiki.wdka.nl', path='/mw-mediadesign/')\n",
"site.login(\n",
" username='user',\n",
" password='pass'\n",
")\n",
"page = site.pages['Diffractive Cookbook']\n",
"text = page.text()\n",
"\n",
"text += 'A new edit'\n",
"\n",
"page.edit(text, 'A new little test')\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"def wiki_recipe(recipe):\n",
" steps = ''\n",
" for log in recipe['logs']:\n",
" steps+= f'# {log}\\n' \n",
"\n",
" # PROV TEMPLATE \n",
" content = f\"\"\"\n",
" === {recipe['title']} ===\n",
" ''{recipe['description']}'' \n",
"
\n",
" '''Nature of the input'''\n",
"
\n",
" {recipe['nature']}\n",
"
\n",
" ''' Process Log'''\n",
"
\n",
" {steps}\n",
" '''Who'''\n",
"
\n",
" {recipe['who']}\n",
" \"\"\"\n",
" return content"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" === Test test test ===\n",
" ''A super simple description'' \n",
"
\n",
" '''Nature of the input'''\n",
"
\n",
" methods\n",
"
\n",
" ''' Process Log'''\n",
"
\n",
" # first step\n",
"# second step\n",
"# third step\n",
"\n",
" '''Who'''\n",
"
\n",
" a friend of mine\n",
" \n"
]
}
],
"source": [
"r = {\n",
" \"title\": \"Test test test\",\n",
" \"description\": \"A super simple description\",\n",
" \"logs\": [\"first step\", \"second step\", \"third step\"],\n",
" \"who\": \"a friend of mine\",\n",
" \"nature\": 'methods'\n",
"}\n",
"\n",
"print(wiki_recipe(r))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "46172edbb966926a6ca6e2e167d7aaa1e3cb13ab137295bdbeca8b798134a9e0"
},
"kernelspec": {
"display_name": "Python 3.10.2 ('venv': venv)",
"language": "python",
"name": "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.10.2"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}