Grote push
This commit is contained in:
parent
59a757c72a
commit
63dd187fb4
6 changed files with 112 additions and 75 deletions
|
@ -23,6 +23,9 @@ def converteer(tekst, gebruiker=True):
|
|||
|
||||
from urllib import parse
|
||||
|
||||
if tekst is None:
|
||||
return None
|
||||
|
||||
if gebruiker:
|
||||
return parse.unquote(tekst).replace('_', ' ').split('#')[0]
|
||||
else:
|
||||
|
@ -131,8 +134,6 @@ def run(taal, start, stop):
|
|||
Paden kunnen gecontroleerd worden met https://www.xefer.com/wikipedia, al doet dit niets met 'speciale' Wikipedia-
|
||||
links.
|
||||
|
||||
>>> run('fr', 'Langue', 'Philosophie')
|
||||
|
||||
Gewone controles
|
||||
>>> run('en', "Belgium", "Philosophy")
|
||||
{'pad': ['Belgium', 'Northwestern Europe', 'Subregion', 'Region', 'Geography', 'Science', 'Scientific method', 'Empirical evidence', 'Proposition', 'Logic', 'Reason', 'Consciousness', 'Sentience', 'Emotion', 'Mental state', 'Mind', 'Phenomenon', 'Immanuel Kant', 'Philosophy']}
|
||||
|
@ -140,6 +141,8 @@ def run(taal, start, stop):
|
|||
{'pad': ['Department of Standards Malaysia', 'Ministry of International Trade and Industry (Malaysia)', 'Ministry (government department)', 'Executive (government)', 'Government', 'State (polity)', 'Germans', 'Germany', 'Central Europe', 'Europe', 'Continent', 'Landmass', 'Region', 'Geography', 'Science', 'Scientific method', 'Empirical evidence', 'Proposition', 'Logic', 'Reason', 'Consciousness', 'Sentience', 'Emotion', 'Mental state', 'Mind', 'Phenomenon', 'Immanuel Kant', 'Philosophy']}
|
||||
>>> run('en', 'Malkajgiri mandal', 'Philosophy')
|
||||
{'pad': ['Malkajgiri mandal', 'Medchal–Malkajgiri district', 'District', 'Administrative division', 'Sovereign state', 'Polity', 'Politics', 'Decision-making', 'Psychology', 'Science', 'Scientific method', 'Empirical evidence', 'Proposition', 'Logic', 'Reason', 'Consciousness', 'Sentience', 'Emotion', 'Mental state', 'Mind', 'Phenomenon', 'Immanuel Kant', 'Philosophy']}
|
||||
>>> run('fr', 'Langue', 'Philosophie')
|
||||
{'pad': ['Langue', 'Système', 'Ensemble', 'Mathématiques', 'Connaissance', 'Notion', 'Connaissance (philosophie)', 'Philosophie']}
|
||||
|
||||
Loops
|
||||
>>> run('nl', 'België', 'Philosophy')
|
||||
|
@ -148,7 +151,8 @@ def run(taal, start, stop):
|
|||
{'pad': ['Tom Inglesby', 'Johns Hopkins Center for Health Security', 'Nonprofit organization', 'Contract failure']}
|
||||
|
||||
Doodlopende eindes
|
||||
TODO Voorbeelden zoeken
|
||||
>>> run('en', 'Gaumee Film Awards', 'Philosophy')
|
||||
{'error': "Er konden geen nieuwe links meer gevonden worden op 'Gaumee Film Awards'"}
|
||||
|
||||
Foute linkjes
|
||||
>>> run('en', 'Deze pagina bestaat niet', 'Philosophy')
|
||||
|
@ -166,7 +170,7 @@ def run(taal, start, stop):
|
|||
|
||||
# Stoppen indien het inladen van de pagina niet lukte.
|
||||
if pagina.status_code != 200:
|
||||
return {'error': f"Er ging iets fout bij het inladen van '{lijst[-1]}'. Bestaat de website?"}
|
||||
return {'error': f"Er ging iets fout bij het inladen van '{lijst[-1]}', vertrekkende vanaf '{lijst[0]}'. Bestaat de website?"}
|
||||
|
||||
# Verwerken.
|
||||
soep = BeautifulSoup(pagina.content, 'html.parser')
|
||||
|
|
|
@ -5,37 +5,15 @@ Dit script is enkel en alleen bedoeld om heel veel willekeurige pagina's te kunn
|
|||
enkel degene eruit te halen die falen (en dus niet correct afgehandeld worden).
|
||||
"""
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
|
||||
from scraper import converteer, zoek_link
|
||||
|
||||
|
||||
def run(taal, start, stop):
|
||||
lijst = [converteer(start, True)] if start != 'Special:Random' else []
|
||||
base = f"https://{taal}.wikipedia.org/wiki/"
|
||||
|
||||
while start != stop:
|
||||
|
||||
# Dit is het enigste dat we aanpassen.
|
||||
print(lijst[-1] if len(lijst) != 0 else [])
|
||||
|
||||
pagina = requests.get(base + converteer(start, False))
|
||||
if pagina.status_code != 200:
|
||||
return {'error': f"Er ging iets fout bij het inladen van '{lijst[-1]}'. Bestaat de website?"}
|
||||
soep = BeautifulSoup(pagina.content, 'html.parser')
|
||||
start = converteer(zoek_link(soep))
|
||||
if start is None:
|
||||
return {'error': f"Er konden geen nieuwe links meer gevonden worden op '{lijst[-1]}'"}
|
||||
if start in lijst:
|
||||
return {'error':
|
||||
f"Cyclus gedetecteerd op '{start}', startende vanaf '{lijst[0]}'. Het onafgewerkte pad zal niet worden toegevoegd aan het overzicht. "
|
||||
}
|
||||
lijst.append(start)
|
||||
return {'pad': lijst}
|
||||
|
||||
from scraper import run
|
||||
|
||||
antwoord = run('en', 'Special:Random', 'Philosophy')
|
||||
langste = antwoord
|
||||
|
||||
while 'pad' in antwoord or antwoord['error'].startswith('Cyclus'):
|
||||
if 'error' not in antwoord and len(langste['pad']) < len(antwoord['pad']):
|
||||
langste = antwoord
|
||||
print(f"Langste pad (lengte {len(langste['pad'])}), van {langste['pad'][0]} naar {langste['pad'][-1]}")
|
||||
antwoord = run('en', 'Special:Random', 'Philosophy')
|
||||
print(antwoord['error'])
|
||||
|
||||
print('Er ging iets mis:', antwoord['error'])
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 65 KiB |
22
index.html
22
index.html
|
@ -7,21 +7,19 @@
|
|||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="top-bar">
|
||||
<label for="taal">Taal: </label><input type="text" id="taal" placeholder="en"/>
|
||||
<label for="start">Startpagina: </label><input type="text" id="start" placeholder="Special:Random"/>
|
||||
<label for="einde">Eindpunt: </label><input type="text" id="einde" placeholder="Philosophy"/>
|
||||
<button type="button" id="toevoegKnop">Voeg toe</button>
|
||||
<p id="waarschuwing" hidden="hidden">
|
||||
De huidige boom zal overschreven worden bij een nieuwe toevoeging.
|
||||
</p>
|
||||
|
||||
<hr/>
|
||||
</div>
|
||||
<div class="header">
|
||||
<img src="images/wikipedia_edit.png" alt="The Wikipedia Logo but rotated" id="logo">
|
||||
<h1>Phikipathia</h1>
|
||||
<p>Philosophy Wikipedia Path visualiser</p>
|
||||
<p>From Philosophy Wikipedia Path visualiser</p>
|
||||
</div>
|
||||
<div id="bar">
|
||||
<label for="taal">Taal: </label><input type="text" id="taal" placeholder="en"/>
|
||||
<label for="start">Startpagina: </label><input type="text" id="start" placeholder="Special:Random"/>
|
||||
<label for="einde">Eindpunt: </label><input type="text" id="einde" placeholder="Philosophy"/>
|
||||
<button type="button" id="toevoegKnop">voeg toe</button>
|
||||
<label id="waarschuwing" hidden="hidden">
|
||||
<b>Waarschuwing:</b> De huidige boom zal overschreven worden bij een nieuwe toevoeging.
|
||||
</label>
|
||||
</div>
|
||||
<div id="visualisatie">
|
||||
</div>
|
||||
|
|
25
index.js
25
index.js
|
@ -8,6 +8,10 @@ const einde = document.getElementById('einde');
|
|||
const toevoegKnop = document.getElementById('toevoegKnop');
|
||||
const visualisatie = document.getElementById('visualisatie');
|
||||
|
||||
let timer;
|
||||
let rotatie;
|
||||
const logo = document.getElementById('logo');
|
||||
|
||||
let huidigeTaal;
|
||||
let huidigeDoel;
|
||||
|
||||
|
@ -23,7 +27,7 @@ function zoek() {
|
|||
|
||||
// Schakel de knop 'toevoegen' uit zolang het zoekproces bezig is, zodat er geen meerdere
|
||||
// paden tegelijk toegevoegd kunnen worden.
|
||||
toevoegKnop.disabled = true;
|
||||
toggleZoeken(false);
|
||||
|
||||
refreshTree();
|
||||
|
||||
|
@ -37,7 +41,7 @@ function zoek() {
|
|||
.then(antwoord => antwoord.json())
|
||||
.then(data => voegToe(data))
|
||||
.catch(reason => alert('‼ ' + reason))
|
||||
.finally(() => toevoegKnop.disabled = false); // Herstel de knop. Ook als er ondertussen iets mis ging.
|
||||
.finally(() => toggleZoeken()); // Herstel de knop. Ook als er ondertussen iets mis ging.
|
||||
|
||||
}
|
||||
|
||||
|
@ -113,3 +117,20 @@ function inputWaarschuwing() {
|
|||
function getOrDefault(element) {
|
||||
return element.value === '' ? element.getAttribute('placeholder') : element.value;
|
||||
}
|
||||
|
||||
function toggleZoeken(stop = true) {
|
||||
toevoegKnop.disabled = !stop;
|
||||
|
||||
rotatie = 0;
|
||||
if (stop) {
|
||||
clearInterval(timer);
|
||||
logo.style.transform = 'rotate(0)';
|
||||
} else {
|
||||
timer = setInterval(draai, 24);
|
||||
}
|
||||
}
|
||||
|
||||
function draai() {
|
||||
rotatie += 5;
|
||||
logo.style.transform = `rotate(${rotatie % 360}deg`;
|
||||
}
|
||||
|
|
90
style.css
90
style.css
|
@ -1,5 +1,19 @@
|
|||
body {
|
||||
font-family: 'Linux Libertine','Georgia','Times',serif;
|
||||
padding: 0 1.5em 1.5em 1.5em;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 0.25em;
|
||||
padding: 0;
|
||||
line-height: 1.3;
|
||||
font-size: 1.8em;
|
||||
font-weight: normal;
|
||||
border-bottom: 1px solid #a2a9b1;
|
||||
}
|
||||
|
||||
li ul {
|
||||
/* Zorg ervoor dat de kinderelementen met hun bolletje onder de eerste letter van het vorige element staan. */
|
||||
margin: 0.2vh 1ch;
|
||||
padding: 0.2vh 1vw;
|
||||
}
|
||||
|
@ -14,38 +28,60 @@ ul#wortel {
|
|||
list-style-type: none;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
text-align: center;
|
||||
margin: 0 auto;
|
||||
|
||||
font-min-size: 2vw;
|
||||
font-size: 3vw;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.header img {
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
|
||||
width: 10%;
|
||||
height: 10%;
|
||||
|
||||
min-width: 2%;
|
||||
min-height: 2%;
|
||||
max-width: 20%;
|
||||
max-height: 20%;
|
||||
height: 1.8em;
|
||||
margin-top: 0.3em;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
font-size: 92%;
|
||||
display: block;
|
||||
color: #202122;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
.top-bar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
#bar {
|
||||
font-family: sans-serif;
|
||||
font-size: 95%;
|
||||
|
||||
padding: 7px;
|
||||
border: 1px solid #a2a9b1;
|
||||
background-color: #f8f9fa;
|
||||
color: #202122;
|
||||
|
||||
position: sticky;
|
||||
top: 7px;
|
||||
}
|
||||
|
||||
#waarschuwing {
|
||||
color: darkorange;
|
||||
#visualisatie {
|
||||
margin: 0.5em 0;
|
||||
font-size: calc(1em * 0.875);
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
background: none;
|
||||
color: #3366bb;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
color: #ba0000;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
button:before {
|
||||
color: #54595d;
|
||||
margin-right: 0.25em;
|
||||
content: "[";
|
||||
}
|
||||
|
||||
button:after {
|
||||
color: #54595d;
|
||||
margin-left: 0.25em;
|
||||
content: "]";
|
||||
}
|
||||
|
|
Reference in a new issue