-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfor_special_cases.py
62 lines (54 loc) · 1.91 KB
/
for_special_cases.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import csv
import re
import yaml
import logging
from github import Github
from pathlib import Path
logging.basicConfig(
filename="special_pechas.log",
format="%(levelname)s: %(message)s",
level=logging.INFO,
)
def notifier(msg):
logging.info(msg)
def check_for_base_file(meta_data, pecha_id):
source_meta = meta_data['source_metadata']
key = 'volumes'
if key in source_meta.keys():
if meta_data["source_metadata"]["volumes"] != (None or {} or ''):
volumes = meta_data["source_metadata"]["volumes"]
key = 'base_file'
for vol_id, vol_info in volumes.items():
if key in vol_info.keys():
print(f"{pecha_id} updated")
break
else:
notifier(f"{pecha_id} no base file")
print(f"{pecha_id} not updated")
break
else:
notifier(f"{pecha_id} volumes empty")
print(f"{pecha_id} is empty")
else:
notifier(f"{pecha_id} not updated at all")
print(f"{pecha_id} not updated")
def get_meta_from_opf(g, pecha_id):
try:
repo = g.get_repo(f"Openpecha/{pecha_id}")
contents = repo.get_contents(f"./{pecha_id}.opf/meta.yml")
return contents.decoded_content.decode()
except:
print(f'Repo Not Found {pecha_id}')
return None
if __name__=='__main__':
token = ""
g = Github(token)
with open("catalog.csv", newline="") as csvfile:
pechas = list(csv.reader(csvfile, delimiter=","))
for pecha in pechas[3626:]:
pecha_id = re.search("\[.+\]", pecha[0])[0][1:-1]
file_path = f"./{pecha_id}.opf/meta.yml"
old_meta_data = get_meta_from_opf(g, pecha_id)
old_meta_data = yaml.safe_load(old_meta_data)
if old_meta_data != None:
check_for_base_file(old_meta_data, pecha_id)