doors/contrib/ookean_export.py

42 lines
1.4 KiB
Python
Raw Normal View History

2020-09-22 20:35:30 +00:00
from collections import defaultdict
import json
from MySQLdb import _mysql
db = _mysql.connect(host="localhost", db="ookean",
user="root", passwd="salakala")
db.query("""
select persons.name, t2.uid, t2.name from persons join tagowners t on persons.id = t.person_id join tags t2 on t.tag_id = t2.id
where persons.archived is null and t.revoked_date is null and t2.archived is null;
""")
r=db.store_result()
nicknames = {
"Adi": "Aaditya Parashar",
"Artur Kerge": "Artur Vincent Kerge",
"Alexander Sysoev": "Aleksander Sysoev",
"Pavel Kirienko": "Pavel Kirilenko",
"Erwin Orye": "Erwin Rudi J. Orye",
"Martti Rand (Protoskoop OÜ)": "Martti Rand",
"Arttu Valkonen": "Arttu Mikael Valkonen",
"Anima (Aleksandrs Naidjonovs)": "Aleksandrs Naidjonovs"
}
cards = defaultdict(list)
for x in range(r.num_rows()):
name, uid, descr = r.fetch_row()[0]
name, uid, descr = name.decode(), uid.decode(), descr.decode() if descr else descr
name = name.replace("(deactivated)", "")\
.replace("(Deactivated)","").replace("(Paused)", "").replace("(disactive)", "")\
.replace("(Disabled)", "").replace("(Protoskoop)", "")\
.strip()
if name in nicknames:
name = nicknames[name]
cards[name].append({"uid": uid, "descr": descr})
print(f"{name:30} {uid:20} {descr}")
with open("ookean_cards.json", "w") as fp:
json.dump(cards, fp, indent=2)