Skip to content

Instantly share code, notes, and snippets.

View salgo60's full-sized avatar
😴

Magnus Sälgö salgo60

😴
View GitHub Profile
from mwclient import Site
from mwtemplates import TemplateEditor
site = Site('sv.wikipedia.org')
site.login('xusername', 'pwd')
# https://sv.wikipedia.org/wiki/Vincent_Lundberg
# https://sv.wikipedia.org/w/api.php?action=query&titles=Vincent_Lundberg&prop=revisions&rvprop=content&format=json
page = site.pages['Vincent Lundberg']
te = TemplateEditor(page.text())
for t in te.templates.items():
#!/bin/bash
for i in `cat ~/scripts/working/purgescript-test.tsv`;
do
echo "$i to be purged"
python3 ~/pywikibot/pwb.py touch -page:$i -purge
done
#https://kulturpersoner.uppsalakyrkogardar.se/galleri/
import requests
import urllib.request
import time
from bs4 import BeautifulSoup
def cleanupstring(s):
out_s = s
while ' ' in out_s:
out_s = out_s.strip().replace(' ', ' ')
return out_s, len(s)-len(out_s)
@salgo60
salgo60 / CheckEuropeanaSameAs.py
Last active May 4, 2020 06:33
A test checking what is in Wikidata with what we have in SameAs Wikidata
import json
import traceback
import requests
import sys
from SPARQLWrapper import SPARQLWrapper, JSON
endpoint_url = "https://query.wikidata.org/sparql"
# SPARQL finding objects with Property P7704 Europeana https://w.wiki/PrV
query = """SELECT * WHERE {
#Test extract första "ExtractNumberChar" tecknen Wikipedia artikeln
#fundering https://sv.wikipedia.org/wiki/Wikipedia:Projekt_naturreservat#Enhetlighet_i_beskrivningar_i_Wikidataobjektet
# pip install sparqlwrapper
# https://rdflib.github.io/sparqlwrapper/
import sys
import urllib
from SPARQLWrapper import SPARQLWrapper, JSON
import requests
@salgo60
salgo60 / SödertäljeKommunNaturreservat.json
Last active May 8, 2020 09:48
Added fields for Wikidata Wikipedia Naturvårdsverket WDPA would be interesting to add identifiers for inaturalist places ....
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@salgo60
salgo60 / Distrikt Bygdeband Wikidata Wikipediapageid.py
Last active May 10, 2020 14:15
Extraherar från Wikidata Bygdebandid och artikelnamn sedan används API att hämta pageid
""" Code that generate for all districts the
BygdebandID
Wikidata Qid
Page id or curid
Name of Wikipedia article
URL Bygdeband
URL Wikidata
See video https://youtu.be/Zno9C5xR2UQ
SPARQL https://w.wiki/QHP
<?xml version="1.0" encoding="UTF-8"?>
<metadata xml:lang="sv">
<Esri>
<CreaDate>20150410</CreaDate>
<CreaTime>08095700</CreaTime>
<ArcGISFormat>1.0</ArcGISFormat>
<SyncOnce>FALSE</SyncOnce>
<DataProperties>
<itemProps>
<itemName Sync="TRUE">Varldsarv</itemName>
@salgo60
salgo60 / WDProperty8133.py
Last active May 21, 2020 13:36
Webscrape bolin.su.se toi set Property 8133
# https://phabricator.wikimedia.org/T236131
import urllib3
from bs4 import BeautifulSoup
from dataclasses import dataclass
@dataclass
class glacier:
id: int
name: str
drainagebasin: str
@salgo60
salgo60 / CheckQualityofWikidataPropertyP3188.py
Last active May 23, 2020 00:10
Check Wikidata property P3188 quality comoared wuth the new P8024
# Check the quality of the Wikidata Property P3188
# See discussion if we should delete it or not
# https://www.wikidata.org/wiki/Wikidata:Properties_for_deletion#Nobelpris-ID_(P3188)
#
import sys, urllib3
from SPARQLWrapper import SPARQLWrapper, JSON
version = "0.0.2"
endpoint_url = "https://query.wikidata.org/sparql"
# SPARQL https://w.wiki/Rbb