{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "from dateutil.parser import parse\n",
    "from datetime import datetime\n",
    "import mwclient \n",
    "from bs4 import BeautifulSoup\n",
    "\n",
    "import os\n",
    "from dotenv import load_dotenv\n",
    "from pathlib import Path\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "load_dotenv()\n",
    "\n",
    "# Page of the wiki with the pads\n",
    "padliography = 'Padliography2'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def add_pad(link, title, overview, categories, date):\n",
    "\n",
    "    parsed_date = parse(date)\n",
    "    date = datetime.strftime(parsed_date, '%Y-%m-%d')\n",
    "\n",
    "    return f'| {link} || {title} || {overview} || {categories} || {date} \\n|-\\n'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def get_pads():\n",
    "    \n",
    "    site = mwclient.Site('pzwiki.wdka.nl', path='/mw-mediadesign/')\n",
    "    site.login(\n",
    "    username=os.environ.get('MW_BOT'),\n",
    "    password=os.environ.get('MW_KEY'),\n",
    "\n",
    "    )\n",
    "\n",
    "    html = site.api('parse', prop='text', page=padliography)\n",
    "    table = BeautifulSoup(html['parse']['text']['*'], features=\"html.parser\").find(\"table\", attrs={\"class\":\"padliography\"})\n",
    "\n",
    "    headers = [header.text.lower().strip() for header in table.find_all('th')]\n",
    "    pads = [\n",
    "        {headers[i]: cell.text.rstrip('\\n') for i, cell in enumerate(row.find_all('td'))} \n",
    "        for row in table.find_all('tr')]\n",
    "    pads = [ pad for pad in pads if pad != {}]\n",
    "    return pads"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{| class = \"wikitable sortable padliography\"\n",
      "|-\n",
      "!link !! title !! overview !! categories !! date\n",
      "|-\n",
      "| https://pad.xpub.nl/p/o2jT2mUjNgH0Vk1uPZLR || Week_1 with Steve || Introduction to Reading, Writing and Research Methodologies + first reading, writing workshop || RWRM, Week_1 || 2021-09-22 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SP16_2107 || Introduction to prototyping || Knowledge and information organisation are deeply intimate acts || Prototyping, Week_1 || 2021-09-21 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SP16_2809 || Orientation/Navigation || Object relations are not just a story of how we use objects but rather how, through relating, we begin to inaugurate and structure our very capacity to position ourselves in reality and phantasy, and so, to the very work of thinking. || SP16, Week_2 || 2021-09-28 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/si16-protoyping-week-2 || Prototyping || Soupboat is born || SP16, Week_2 || 2021-09-27 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SP16_0510 || Language patterns experiments || Cat’s cradle is about patterns and knots || SP16, Week_3 || 2021-10-05 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SP_16_0610 || Reader 'prototypes' || since we are exposed to several topics relates to orientation / disorientation / editing / so we could help(?) the readers to navigate different texts || SP16, RWRM, Week_3 || 2021-10-06 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SP16_1210 || Transcription processes || interpretive decisions (What is transcribed?) epresentational decisions (How is it transcribed?) || SP16, Week_4 || 2021-10-12 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SP16_0510_texts || Magic Words Glossary || Little spells that can be used anywhere on the pad to indicate how we want to interact with the text || SP16, Week_3 || 2021-10-05 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/2021-10-11-protoyping || Prototyping XP8 + NLTK2 || Custom text corpus in NLTK || Prototyping, Week_4, NLTK || 2021-10-11 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/si16-protoyping-week-3 || Prototyping XP7 + NLTK1 || Introduction to NLTK + Explorative programming ch 7 || Prototyping, Week_3, NLTK || 2021-10-04 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/GroupMeeting_18102021 || Meeting SP16: Rejection? 🧠⚡ || First group meeting for the SP16 || SP16, Meeting, Rejection || 2021-10-18 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/Rejection_Glossary || Rejection Glossary || Approaching rejection from a lot of points of view || SP16, Rejection || 2021-10-18 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/GroupMeeting_27102021 || Group Meeting Structure || How do we want to work together? How can we structure future meetings? || SP16, Meeting, Rejection || 2021-10-27 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/si16-protoyping-week-7 || Prototyping || Collecting texts and creating our own corpora || Week_7, Prototyping, NLTK || 2021-11-01 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/week7_withClara || SP16 with Clara Balaguer ||  || Week_7, SP16 || 2021-11-02 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/TBD_VLTK || TBD VLTK, by Clara Balaguer || A high-low mix tape on the vernacular || Week_7, SP16 || 2021-11-02 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/Meeting_SP16_Nov_04 || Group Meeting || Remarks on the Rejection Glossary, Vernacular, SI16 Brainstorming, Organising our work || Week_7, SP16, Meeting, Rejection || 2021-11-04 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/Meeting_Template || TEMPLATE for Group Meetings || Please copy from this template and paste to the actual meeting pad! || SP16, Meeting, Templates || 2021-11-04 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/si16-protoyping-week-8 || Prototyping XP15, Publishing Pipeline || XP15 check in + Etherpad API with Python || Week_8, Prototyping || 2021-11-08 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SP16_0911 || SP16 with Cristina (Danny is sick) || RUMINATION, DIGESTION, REFLECTION a.k.a. \"The long day with Cristina\" || SP16, Week_8 || 2021-11-09 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/si16-protoyping-week-9 || Prototyping || Sharing out prototypes, Creating a webpage w/ Python + html & css, What is \"documentation\" || Prototyping, Week_9 || 2021-11-15 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/Meeting_16112021 || Group meeting || morning: SP16 structure proposals; afternoon: editorial w/ Cristina || Week_9, SP16 || 2021-11-16 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/si16-protoyping-week-10 || Prototyping || Exploring ways to create the API [examples] || Week_10, Prototyping || 2021-11-22 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/si16-26112021 || Guest Danny Tirthdas van der Kleij || Vernacular in the Software || Week_10, SP16 || 2021-11-26 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/si16-protoyping-week-11 || Prototyping || Check-in + Tutorial + ... || Week_11, SP16, Prototyping || 2021-11-29 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/si16-protoyping-week-12 || Prototyping || ... || Week_12, SP16, Prototyping || 2021-12-06 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/si16-week-12 || SP16 with Cristina || Radical efficiency day || Week_12, SP16 || 2021-12-07 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/18012022 || SP17 with Lidia & Co. || Ideology, gamification || Week_02, SP17 || 2022-01-18 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/19012022 || RW&RM with Steve || Marx and Engels; Gramsci; Hebdidge; Chad McCail || Week_02, SP17, RWRM || 2022-01-19 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/19012022 || SP17 with Lidia & Co. || Games as reproductive technologies, Predatory monetization || Week_03, SP17 || 2022-01-25 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/si16_debrief || SP16 Debrief || Reflections, debrief with XPUB1, Aymeric, Michael, Cristina, Manetta and Steve || Debrief, SP16, Week_03 || 2022-01-26 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/01022022 || SP17 with Lidia & Co. || Digesting, reflecting, more reads + Tutorials || SP17, Week_04 || 2022-02-01 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/02022022 || RW&RM with Steve || NO NEW STUFF & Creating our Productive Play Glossary || SP17, RWRM, Week_04 || 2022-02-02 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SI17-prototyping-07022022 || Prototyping || Building little games, playful things, make mazes with python || Prototyping, Week_05 || 2022-02-07 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/08022022 || SP17 with Lidia & Co. || What is modding and how it is connected to culture and labour || SP17, Week_05 || 2022-02-07 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/role-playing-structure || Experimental Kitchen || Kim and Chae designed an experimental role-play session for the whole group || SP17, Week_05 || 2022-02-08 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/paolopedercini || Paolo Pedercini session || tba || SP17, Week_05, Talks || 2022-02-09 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SI17-prototyping-14022022 || Prototyping || Play time for puzzles, mini-games collaboration tools || Prototyping, Week_06 || 2022-02-14 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/16022022-ste%3C3 || RW&RM with Steve || Loot box ideas and prototypes || RWRM, Week_06 || 2022-02-16 \n",
      "|-\n",
      "| https://hub.xpub.nl/soupboat/pad/p/group_meeting_18022022 || Group meeting || set pre-launch date and group awareness, the loot box, our public and intentions towards our public || SP17, Meeting || 2022-02-18 \n",
      "|-\n",
      "| https://hub.xpub.nl/soupboat/pad/p/group_meeting_21022022 || Group meeting || Loot box proposals, PNF & confirm format - the Box || SP17, Meeting, Week_06 || 2022-02-21 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/talks-chess-23022022 || dr. Shira Chess session || Public lecture & private Q&A with \"Play Like A Feminist\" author || SP17, Talks || 2022-02-23 \n",
      "|-\n",
      "| https://hub.xpub.nl/soupboat/pad/p/group_meeting_28022022 || Group meeting || Prototypes presentations, getting stuck and dividing into small groups to move on || SP17, Meeting || 2022-02-28 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SI17-prototyping-07-03-2022 || Prototyping || Bots, IRC [hello, again, mIRC-a :D] & chat bots with python || Prototyping, Week_09 || 2022-03-07 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/08032022 || SP17 with Lidia & Co. || Progress updates from Teams #1, #2 and #3 || SP17, Week_09 || 2022-03-08 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/xpub1-si17-editorial-groups-outlines || Editorial meeting || Team representatives meeting with the editors to align the overall concept || SP17, Week_09, Meeting || 2022-03-09 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SI17-prototyping-14-03-2022 || Prototyping || Catching up, git tutorial, deadlines for the week || Prototyping, Week_10 || 2022-03-14 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/15032022 || SP17 with Lidia & Steve || Updates from editors and teams 1,2 3; to-dos for the week || SP17, Week_10 || 2022-03-14 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SI17-prototyping-21-03-2022 || Prototyping || Assessments, documentation & updates from teams 1 & 3; Hello, Spring! || SP17, Week_10 || 2022-03-21 \n",
      "|-\n",
      "| https://pad.xpub.nl/p/SIX-diffractive-cookbook || Diffractive Cookbook || Plan for the release of SI18.6 || SI18, Week_6 || 2022-06-02 \n",
      "|-\n",
      "|-\n",
      "|}\n"
     ]
    }
   ],
   "source": [
    "pads = get_pads()\n",
    "\n",
    "table = '{| class = \"wikitable sortable padliography\"\\n|-\\n!link !! title !! overview !! categories !! date\\n|-\\n'\n",
    "for pad in pads:\n",
    "    table += add_pad(pad['link'], pad['title'], pad['overview'], pad['categories'], pad['date'])\n",
    "table += '|-\\n|}'\n",
    "print(table)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "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,
  "vscode": {
   "interpreter": {
    "hash": "cc811c39cebdedb5a11cacaf3b223f5b956494f89d9226d14870082e2ebdafc1"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
