Skip to content

Instantly share code, notes, and snippets.

@salgo60
Created March 31, 2021 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salgo60/e7b4c0c71e33e00b9082c5f23aabfe0e to your computer and use it in GitHub Desktop.
Save salgo60/e7b4c0c71e33e00b9082c5f23aabfe0e to your computer and use it in GitHub Desktop.
Kollar verk uppladdade på WD med URL Levandemusikarv om dom finns
# Check linkroot
# pip install sparqlwrapper
# https://rdflib.github.io/sparqlwrapper/
# see task https://github.com/salgo60/Litteraturbanken_wd_runes/issues/14
# gist https://gist.github.com/salgo60/51d56cc60dd382301cce33bd462f6363
from datetime import datetime
import urllib3
import sys
from SPARQLWrapper import SPARQLWrapper, JSON
endpoint_url = "https://query.wikidata.org/sparql"
#endpoint_url = "https://wcqs-beta.wmflabs.org/sparql"
http = urllib3.PoolManager()
# SPARQL
query = """SELECT ?item ?itemLabel ?LevandeMusik WHERE {
?item wdt:P31 wd:Q2188189.
?item wdt:P4607 ?id
BIND(URI(CONCAT("http://www.swedishmusicalheritage.com/composers/",?id)) AS ?LevandeMusik)
SERVICE wikibase:label { bd:serviceParam wikibase:language "sv,en". }
}"""
def get_results(endpoint_url, query):
user_agent = "user:salgo60/%s.%s" % (sys.version_info[0], sys.version_info[1])
sparql = SPARQLWrapper(endpoint_url, agent=user_agent)
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
return sparql.query().convert()
''' Check if URLS is ok'''
def check(url):
#print("\t" + url)
r = http.request('GET', url)
#print("\t" + url + "\t" + str(r.status))
if r.status != 200:
#print("Status: ",r.status, " \t", url)
return False
return True
start_time = datetime.now()
print("Last run: ", start_time)
results = get_results(endpoint_url, query)
ok = 0
notok = 0
print("SPARQL result = ", str(len(results["results"]["bindings"])))
for result in results["results"]["bindings"]:
#print(result)
levURL = result["LevandeMusik"]["value"]
#file = result["file"]["value"]
if check(levURL):
ok += 1
else:
print("Status not ok: ", levURL, " \t")
notok += 1
print("OK: ",ok,"\t not ok",notok)
end = datetime.now()
print("Ended: ", end)
print('Time elapsed (hh:mm:ss.ms) {}'.format(datetime.now() - start_time))
@salgo60
Copy link
Author

salgo60 commented Mar 31, 2021

/usr/local/bin/python3.8 /Users/magnus/Library/Preferences/PyCharmCE2019.2/scratches/scratch_127.py
Last run: 2021-03-31 12:00:48.089130
SPARQL result = 5317
Status not ok: http://www.swedishmusicalheritage.com/composers/heintze-gustaf-hjalmar/SMH-W5653-Konsert_for_tva_pianon_och_orkester_a-moll
Status not ok: http://www.swedishmusicalheritage.com/composers/heintze-gustaf-hjalmar/SMH-W5654-Konsertstycke_for_piano_och_liten_orkester_fiss-moll
Status not ok: http://www.swedishmusicalheritage.com/composers/heintze-gustaf-hjalmar/SMH-W5656-Pianoconcert_f-moll
Status not ok: http://www.swedishmusicalheritage.com/composers/heintze-john-wilhelm/SMH-W5657-Conserto_nr_1_ess-moll_for_Piano_med_orkester
Status not ok: http://www.swedishmusicalheritage.com/composers/heintze-john-wilhelm/SMH-W5658-Consert_no_2_e-moll_for_Piano_med_Orkester
Status not ok: http://www.swedishmusicalheritage.com/composers/soderman-august/SMH-W4526-Hymn_till_natten
Status not ok: http://www.swedishmusicalheritage.com/composers/rendahl-edwin/SMH-W6043-Marcia_funebre_vid_C_W_Rendahls_bar
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6108-Tvenne_romanser
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6109-Fyra_sanger
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6110-Vackra_sky_som_ensam_tagar
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6111-Fyra_sanger_med_svensk_och_tysk_text
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6112-Flyttfoglarne
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6114-Varhelsning
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6116-Tre_romancer_Text_af_BjOrnstjerne_BjOrnsons_Arne
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6119-En_bon
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6120-Langt_fjarran
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6121-God_morgen
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6123-Midsommarsminnen_fran_Sverige_Trenne_genrestycken_for_piano
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6124-Chansons_dhiver
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6126-Ar_han_an_mig_trogen
Status not ok: http://www.swedishmusicalheritage.com/composers/andersson-richard/SMH-W1951-Vanitas_vanitatum_Vanitas
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6118-Larkroster_i_Maj
Status not ok: http://www.swedishmusicalheritage.com/composers/safstrom-august/SMH-W6128-Sanger_ur_operetten_Fiskar-Stugan
Status not ok: http://www.swedishmusicalheritage.com/composers/geijer-gosta/SMH-W6133-Harpolekarens_sang_ur_Vapensmeden_af_Viktor_Rydberg
Status not ok: http://www.swedishmusicalheritage.com/composers/geijer-gosta/SMH-W6134-Dulgt_KjArlighed
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6139-Till_ditt_hjerta_saligt_sluten
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6140-Till_en_ofver_sina_synder_bedrofvad_sjal
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6141-Gjordt_och_ogjordt
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6142-Jullof
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6144-Vi_aro_nu_Guds_fria_barn
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6145-Framat
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6146-Jesus_ar_hvad_jag_behofver
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6147-Ave_Verum
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6148-Serenad_qvartett_for_mansroster
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6149-Barnens_anlag
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6150-Fattiga_Barn_i_Finland
Status not ok: http://www.swedishmusicalheritage.com/composers/wickman-fredrika/SMH-W6155-Varminnen_fran_Italien_Fyra_genrestycken
Status not ok: http://www.swedishmusicalheritage.com/composers/rudolf-gagge/SMH-W2173-
Status not ok: http://www.swedishmusicalheritage.com/composers/roman-johan-helmich/SMH-W754-Assaggi_a_violino_solo_25_tjugofem_etyder

OK: 5278 not ok 39
Ended: 2021-03-31 12:03:57.438712
Time elapsed (hh:mm:ss.ms) 0:03:09.349603

Process finished with exit code 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment