forked from marviro/siterevuestylo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakecaches.py
More file actions
84 lines (70 loc) · 3.41 KB
/
makecaches.py
File metadata and controls
84 lines (70 loc) · 3.41 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import requests
import json
import config
import yaml
import pypandoc
import re
import config
from tools import yamltojs, getartinfofromyaml, setkeywords, setdossiers, setauthors
headers = {"Authorization": f"Bearer {config.accessToken}"}
endpoint = "https://stylo.huma-num.fr/graphql"
def retrievejsoncache():
query = """
{
articles{_id title contributors{user{displayName}} workingVersion{md yaml bib}versions{_id} tags{name}}
}
"""
r = requests.post(endpoint, json={"query": query}, headers=headers)
if r.status_code == 200:
articlesdata = r.json()['data']['articles']
tagName = config.tagName
articles=[]
for article in articlesdata:
try:
for tag in article['tags']:
if tag['name'] == tagName:
titledoc=article['title']
idart= article['_id']
yaml = yamltojs(article['workingVersion']['yaml'])[0]
myid=re.split('_', getartinfofromyaml(article,'id'))[0]
try:
title = pypandoc.convert_text(yaml['title_f'], 'html', format='md')
except:
title = article['title']
versions = article['versions']
contributors = article['contributors']
workingVersion = article['workingVersion']
dictart = {"titledoc":titledoc, "id":idart, "yaml":yaml, 'myid':myid, 'title':title, 'versions': versions, 'contributors':contributors, 'workingVersion':workingVersion }
if dictart not in articles:
articles.append(dictart)
elif tag['name'] == config.appelTag:
titledoc=article['title']
idart= article['_id']
yaml = yamltojs(article['workingVersion']['yaml'])[0]
myid=re.split('_', getartinfofromyaml(article,'id'))[0]
try:
title = pypandoc.convert_text(yaml['title_f'], 'html', format='md')
except:
title = article['title']
versions = article['versions']
contributors = article['contributors']
workingVersion = article['workingVersion']
dictart = {"titledoc":titledoc, "id":idart, "yaml":yaml, 'myid':myid, 'title':title, 'versions': versions, 'contributors':contributors, 'workingVersion':workingVersion }
if dictart not in articles:
articles.append(dictart)
except:
print('no tags')
return articles
else:
raise Exception(f"Query failed to run with a {r.status_code}.")
def makecaches():
with open('caches/articles.json', 'w') as file:
json.dump(retrievejsoncache(), file)
with open('caches/appels.json', 'w') as file:
json.dump(retrievejsoncache(), file)
with open('caches/keywords.json', 'w') as file:
json.dump(setkeywords(), file)
with open('caches/dossiers.json', 'w') as file:
json.dump(setdossiers(), file)
with open('caches/authors.json', 'w') as file:
json.dump(setauthors(), file)