Scripts live in their own dir
This commit is contained in:
parent
253096bf59
commit
295e833621
2 changed files with 56 additions and 2 deletions
55
scripts/add_conference_urls.py
Executable file
55
scripts/add_conference_urls.py
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import json
|
||||
from confarchive import database, model
|
||||
from confarchive.view import app
|
||||
|
||||
app.config.from_object("config.default")
|
||||
database.init_app(app)
|
||||
|
||||
|
||||
def url_from_giggty_menu() -> None:
|
||||
for conf in model.Conference.query.order_by(model.Conference.short_name):
|
||||
if conf.url:
|
||||
continue
|
||||
|
||||
giggity_menu = "giggity/menu/"
|
||||
|
||||
menu_filename = os.path.join(giggity_menu, conf.short_name + ".json")
|
||||
|
||||
if not os.path.exists(menu_filename):
|
||||
continue
|
||||
|
||||
menu = json.load(open(menu_filename))
|
||||
links = {link["title"]: link["url"] for link in menu["metadata"]["links"]}
|
||||
|
||||
if "Website" not in links:
|
||||
continue
|
||||
print(json.dumps(links, indent=2))
|
||||
|
||||
url = links["Website"]
|
||||
|
||||
print(conf.short_name, menu_filename, url)
|
||||
|
||||
conf.url = url
|
||||
|
||||
database.session.commit()
|
||||
|
||||
|
||||
def add_more_urls() -> None:
|
||||
for conf in model.Conference.query.order_by(model.Conference.short_name):
|
||||
if conf.url:
|
||||
continue
|
||||
if conf.short_name.startswith("debconf"):
|
||||
conf.url = f"https://{conf.short_name}.debconf.org/"
|
||||
print(conf.short_name, conf.url)
|
||||
if conf.short_name.startswith("fosdem"):
|
||||
year = conf.short_name[-4:]
|
||||
conf.url = f"https://fosdem.org/{year}/"
|
||||
print(conf.short_name, conf.url)
|
||||
|
||||
database.session.commit()
|
||||
|
||||
|
||||
add_more_urls()
|
||||
130
scripts/add_place.py
Executable file
130
scripts/add_place.py
Executable file
|
|
@ -0,0 +1,130 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
from confarchive import database, model, wikidata
|
||||
from confarchive.view import app
|
||||
|
||||
app.config.from_object("config.default")
|
||||
database.init_app(app)
|
||||
|
||||
|
||||
def add_country(name: str) -> None:
|
||||
"""Add a country to the database."""
|
||||
print(name)
|
||||
|
||||
hits = wikidata.search(name + " haswbstatement:P297")
|
||||
|
||||
found = []
|
||||
|
||||
for hit in hits:
|
||||
qid = hit["title"]
|
||||
item = wikidata.get_item(qid)
|
||||
if "en" in item["labels"]:
|
||||
label = item["labels"]["en"]["value"]
|
||||
else:
|
||||
label = "[no english label]"
|
||||
|
||||
if "en" in item["descriptions"]:
|
||||
description = item["descriptions"]["en"]["value"]
|
||||
else:
|
||||
description = "[no english description]"
|
||||
|
||||
if name.lower() not in label.lower():
|
||||
print("not picking", label)
|
||||
continue
|
||||
|
||||
alpha2 = item["claims"]["P297"][0]["mainsnak"]["datavalue"]["value"]
|
||||
|
||||
wd_hit = {
|
||||
"qid": qid,
|
||||
"label": label,
|
||||
"description": description,
|
||||
"alpha2": alpha2,
|
||||
}
|
||||
print(wd_hit)
|
||||
|
||||
found.append(wd_hit)
|
||||
|
||||
assert len(found) == 1
|
||||
hit = found[0]
|
||||
|
||||
item = model.Country(
|
||||
alpha2=hit["alpha2"], name=hit["label"], wikidata_qid=hit["qid"]
|
||||
)
|
||||
database.session.add(item)
|
||||
database.session.commit()
|
||||
|
||||
print(hit["alpha2"], hit["label"], hit["qid"], "added to database")
|
||||
|
||||
|
||||
def add_city(country_code: str, name: str) -> None:
|
||||
"""Add a city to the database."""
|
||||
print(name)
|
||||
|
||||
country = model.Country.query.filter_by(alpha2=country_code).one()
|
||||
country_qid = country.wikidata_qid
|
||||
|
||||
# hits = wikidata_search(name + " haswbstatement:P17=" + country_qid)
|
||||
hits = wikidata.search(name)
|
||||
|
||||
found = []
|
||||
|
||||
for hit in hits:
|
||||
qid = hit["title"]
|
||||
item = wikidata.get_item(qid)
|
||||
claims = item["claims"]
|
||||
if "en" in item["labels"]:
|
||||
label = item["labels"]["en"]["value"]
|
||||
else:
|
||||
label = "[no english label]"
|
||||
|
||||
if "en" in item["descriptions"]:
|
||||
description = item["descriptions"]["en"]["value"]
|
||||
else:
|
||||
description = "[no english description]"
|
||||
|
||||
try:
|
||||
hit_country_qid = claims["P17"][0]["mainsnak"]["datavalue"]["value"]["id"]
|
||||
except KeyError:
|
||||
hit_country_qid = None
|
||||
if hit_country_qid != country_qid:
|
||||
print("skipping:", label, description)
|
||||
print(" ", hit_country_qid, "!=", country_qid)
|
||||
continue
|
||||
|
||||
wd_hit = {
|
||||
"qid": qid,
|
||||
"label": label,
|
||||
"description": description,
|
||||
"country": country,
|
||||
}
|
||||
print(wd_hit)
|
||||
assert len(label) < 30
|
||||
|
||||
found.append(wd_hit)
|
||||
break
|
||||
|
||||
assert len(found) == 1
|
||||
hit = found[0]
|
||||
|
||||
slug = hit["label"].lower().replace(" ", "_")
|
||||
|
||||
item = model.City(
|
||||
slug=slug, name=hit["label"], country=country, wikidata_qid=hit["qid"]
|
||||
)
|
||||
database.session.add(item)
|
||||
database.session.commit()
|
||||
|
||||
print(hit["label"], hit["qid"], "added to database")
|
||||
|
||||
|
||||
obj_type = sys.argv[1]
|
||||
|
||||
assert obj_type in ("country", "city", "venue")
|
||||
|
||||
if obj_type == "country":
|
||||
add_country(sys.argv[2])
|
||||
if obj_type == "city":
|
||||
add_city(sys.argv[2], sys.argv[3])
|
||||
# if obj_type == "venue":
|
||||
# add_venue(sys.argv[2], sys.argv[3])
|
||||
Loading…
Add table
Add a link
Reference in a new issue