{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "%store -r the_editor\n", "\n", "if 'the_editor' not in locals():\n", " import pickle\n", " print(\"Loading default data...\")\n", " the_editor = pickle.load(open(\"data/the_editor.p\",'rb'))\n", " \n", "from IPython.display import display, Markdown as md\n", "display(md(\"---\"))\n", "display(md(f\"# A. Basic editor information (from Wikipedia)\"))\n", "display(md(f\"***Editor: {the_editor['name']}***\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "the_editor.to_frame('value')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import display, Markdown as md\n", "display(md(\"---\"))\n", "display(md(f\"# B. Modified pages of an editor (from Xtools)\"))\n", "display(md(f\"***Editor: {the_editor['name']}***\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from external.xtools import XtoolsAPI, XtoolsDV\n", "from IPython.display import display, clear_output\n", "\n", "xtools_api = XtoolsAPI(project = 'en.wikipedia.org')\n", "xtools_dv = XtoolsDV(xtools_api)\n", "\n", "try:\n", " editor_info = xtools_dv.get_modified_pages_counts_per_editor(the_editor['name'])\n", " display(editor_info.to_frame('value'))\n", "except:\n", " clear_output()\n", " display(md(f'**There are no modified pages by this editor.**'))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import display, Markdown as md\n", "display(md(\"---\"))\n", "display(md(f\"# C. Select one page created by an editor (XTools)\"))\n", "display(md(f\"***Editor: {the_editor['name']}***\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from external.wikipedia import WikipediaDV, WikipediaAPI\n", "from IPython.display import HTML, display, clear_output\n", "from utils.notebooks import get_notebook_by_number\n", "from external.xtools import XtoolsAPI, XtoolsDV\n", "\n", "xtools_api = XtoolsAPI(project = 'en.wikipedia.org')\n", "xtools_dv = XtoolsDV(xtools_api)\n", "\n", "try:\n", " created_pages = xtools_dv.get_created_pages_per_editor(the_editor['name'])\n", "except:\n", " clear_output()\n", " display(md(f'**There are no created pages by this editor.**'))\n", " display(HTML(f'Go to next workbook'))\n", " \n", "\n", "from visualization.conflicts_listener import ConflictsListener\n", "def select_page(page):\n", " global the_page\n", " page_inputname=page\n", " \n", " wikipedia_dv = WikipediaDV(WikipediaAPI(domain='en.wikipedia.org'))\n", " try:\n", " the_page = wikipedia_dv.get_page(int(page_inputname))\n", " except:\n", " the_page = wikipedia_dv.get_page(page_inputname)\n", "\n", " with out:\n", " %store the_page\n", " clear_output()\n", " display(md(\"### Current Selection:\"))\n", " \n", " if 'invalid' in the_page:\n", " display(f\"The page {page_inputname} was not found, try a different page\")\n", " else:\n", " # display the data that will be passed to the next notebook\n", " display(the_page.to_frame('values'))\n", " display(HTML(f'Go to next workbook'))\n", " \n", "\n", "def on_selection_change(change):\n", " try:\n", " select_page(qg_obj.get_selected_df().iloc[0].page_title)\n", " except:\n", " print('Problem parsing the name. Execute the cell again and try a different page.')\n", " display(HTML(f'Go to next workbook'))\n", "\n", "if 'created_pages' in locals():\n", " import qgrid\n", " qg_obj = qgrid.show_grid(created_pages[['page_title', 'page_len', 'rev_id', 'rev_len', 'rev_timestamp']])\n", " qg_obj.observe(on_selection_change, names=['_selected_rows'])\n", "\n", "if 'qg_obj' in locals():\n", " from ipywidgets import Output\n", " from IPython.display import display, clear_output, Markdown as md\n", " display(md(\"### Select one page row for the next notebook:\"))\n", " display(qg_obj)\n", " out = Output()\n", " display(out)\n", "\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.7" } }, "nbformat": 4, "nbformat_minor": 2 }