From c9342c56d39bf5831bf26452e371538535e3e7db Mon Sep 17 00:00:00 2001 From: jules Date: Fri, 6 Nov 2020 20:01:33 +0100 Subject: [PATCH] fetching mediawikipage content --- daapinterface.py | 32 ++++++++++++++- templates/about-wiki.html | 6 +++ templates/layout-later.html | 78 ------------------------------------- 3 files changed, 36 insertions(+), 80 deletions(-) create mode 100644 templates/about-wiki.html delete mode 100644 templates/layout-later.html diff --git a/daapinterface.py b/daapinterface.py index 26d1538..dce6be7 100644 --- a/daapinterface.py +++ b/daapinterface.py @@ -8,6 +8,11 @@ import requests from SPARQLWrapper import SPARQLWrapper, JSON import json # import pandas as pd +# ##### IMPORTS FOR TEST WIKIPAGE +from lxml import html +from bs4 import BeautifulSoup + + # # # # # # # # # # # # # # # # # # # # # # # # # GETTING STARTED @@ -350,7 +355,16 @@ def searchtools(): ######################### ABOUT @app.route("/about") def about(): - return render_template('about.html') + url="https://daap.bannerrepeater.org/w/index.php?title=Project:About&action=render" + # Make a GET request to fetch the raw HTML content + html_content = requests.get(url).text + # Parse the html content + soup = BeautifulSoup(html_content, "lxml") + print(soup.prettify()) # print the parsed data of html + + text=soup.find("p") + + return render_template('about-wiki.html', text=text) ######################### TUTORIAL @app.route("/tutorials") @@ -367,7 +381,21 @@ def upload(): ######################### LOGIN #Goes to wikibase page - +# ################### +# TEST + +response = requests.get( + 'https://daap.bannerrepeater.org/w/api.php', + params={ + 'action': 'parse', + 'page': 'Test', + 'format': 'json', + }).json() +raw_html = response['parse']['text']['*'] +document = html.document_fromstring(raw_html) +first_p = document.xpath('//p')[0] +intro_text = first_p.text_content() +print(intro_text) # ALL NAME diff --git a/templates/about-wiki.html b/templates/about-wiki.html new file mode 100644 index 0000000..2ab998e --- /dev/null +++ b/templates/about-wiki.html @@ -0,0 +1,6 @@ +{% extends "layout.html" %} +{% block content %} + +{{ text }} + +{% endblock content %} \ No newline at end of file diff --git a/templates/layout-later.html b/templates/layout-later.html deleted file mode 100644 index b58c47b..0000000 --- a/templates/layout-later.html +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - D.A.A.P - - - - - - - - - - - {% block content %} - {% endblock content %} - - - - - - - - - \ No newline at end of file