from external.wikipedia import WikipediaDV, WikipediaAPI
from IPython.display import HTML, display, clear_output
from utils.notebooks import get_notebook_by_number
from external.xtools import XtoolsAPI, XtoolsDV
xtools_api = XtoolsAPI(project = 'en.wikipedia.org')
xtools_dv = XtoolsDV(xtools_api)
try:
created_pages = xtools_dv.get_created_pages_per_editor(the_editor['name'])
except:
clear_output()
display(md(f'**There are no created pages by this editor.**'))
display(HTML(f'<a href="{get_notebook_by_number(1)}" target="_blank">Go to next workbook</a>'))
from visualization.conflicts_listener import ConflictsListener
def select_page(page):
global the_page
page_inputname=page
wikipedia_dv = WikipediaDV(WikipediaAPI(domain='en.wikipedia.org'))
try:
the_page = wikipedia_dv.get_page(int(page_inputname))
except:
the_page = wikipedia_dv.get_page(page_inputname)
with out:
%store the_page
clear_output()
display(md("### Current Selection:"))
if 'invalid' in the_page:
display(f"The page {page_inputname} was not found, try a different page")
else:
# display the data that will be passed to the next notebook
display(the_page.to_frame('values'))
display(HTML(f'<a href="{get_notebook_by_number(1)}" target="_blank">Go to next workbook</a>'))
def on_selection_change(change):
try:
select_page(qg_obj.get_selected_df().iloc[0].page_title)
except:
print('Problem parsing the name. Execute the cell again and try a different page.')
display(HTML(f'<a href="{get_notebook_by_number(1)}" target="_blank">Go to next workbook</a>'))
if 'created_pages' in locals():
import qgrid
qg_obj = qgrid.show_grid(created_pages[['page_title', 'page_len', 'rev_id', 'rev_len', 'rev_timestamp']])
qg_obj.observe(on_selection_change, names=['_selected_rows'])
if 'qg_obj' in locals():
from ipywidgets import Output
from IPython.display import display, clear_output, Markdown as md
display(md("### Select one page row for the next notebook:"))
display(qg_obj)
out = Output()
display(out)