-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
201 lines (169 loc) · 6.17 KB
/
app.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
from flask import Flask, render_template, redirect, send_file
import tools
import config
import pypandoc
import re
import makecaches
import json
from slugify import slugify
app = Flask(__name__, template_folder='./templates/')
if config.dynamic:
print('dynamic version')
else:
print('version with caches')
makecaches.makecaches()
@app.route('/') # route où seront servies ces données
def homepage(): # la fonction qui sert les données pour la route /
if config.dynamic:
data = tools.retrievetags("article")
else:
data = json.load(open('caches/articles.json','r'))
return render_template('index.html', title=config.title, data=data)
@app.route('/a-propos') # route où seront servies ces données
def aboutpage(): # la fonction qui sert les données pour la route /
return render_template('a-propos.html', title="à propos - revue lampadaire")
@app.route('/appels') # route où seront servies ces données
def appels(): # la fonction qui sert les données pour la route /
if config.dynamic:
data = tools.retrievetags("appel")
else:
data = json.load(open('caches/appels.json','r'))
return render_template('appels.html', title="appels de textes - revue lampadaire", data=data)
@app.route('/contact') # route où seront servies ces données
def contact(): # la fonction qui sert les données pour la route /
return render_template('contact.html', title="contact - revue lampadaire")
@app.route('/articles/<myid>.html')
def article(myid):
alldata=tools.idfrommyid(myid) # fonction pour récuperer les données d'un article à partir de son id yaml
data=alldata[0]
myid=alldata[1]
yaml=alldata[2]
try:
keywords= yaml['keywords']
kw_sl=[]
for kw in keywords:
keywords_slugs = [(k, slugify(k)) for k in kw['list_f']]
kw.update({'list_f':keywords_slugs})
kw_sl.append(kw)
except:
kw_sl=[]
try:
authors= yaml['authors']
au_sl=[]
for au in authors:
authorslug = slugify(au['surname'])+'-'+slugify(au['forname'])
au.update({'authorslug':authorslug})
au_sl.append(au)
except:
au_sl=[]
yaml.update({'authors':au_sl})
title = pypandoc.convert_text(yaml['title_f'], 'html', format='md')
try:
myarticle = pypandoc.convert_text(data['data']['article']['workingVersion']['md'], 'html', format='md')
except:
myarticle = data['data']['article']['workingVersion']['md']
abstract_fr=''
abstract_en=''
try:
for abstract in yaml['abstract']:
if abstract['lang'] == 'fr':
abstract_fr = abstract['text_f']
except:
abstract_fr=''
try:
for abstract in yaml['abstract']:
if abstract['lang'] == 'en':
abstract_en = abstract['text_f']
except:
abstract_en=''
try:
authors = yaml['authors']
except:
authors = [{'forname':'','name':'','orcid':''}]
try:
for d in yaml['dossier']:
mydossier = d['title_f']
except:
mydossier = ''
return render_template('article.html', myarticle=myarticle, data=data, yaml=yaml,title=title, abstract_fr=abstract_fr, abstract_en=abstract_en, authors=authors, myid=myid, mydossier=mydossier)
@app.route('/downloads/<myid>')
def articlepdf(myid):
alldata=tools.idfrommyid(myid)
data=alldata[0]
myid=alldata[1]
id = alldata[3]
version=alldata[4]
# print(myid,id,version)
tools.getpdf(id,myid,version)
#For windows you need to use drive name [ex: F:/Example.pdf]
path = "downloads/"+myid+"-"+id+"/"+myid+".pdf"
return send_file(path, as_attachment=True)
@app.route('/xml/<myid>')
def articlexml(myid):
alldata=tools.idfrommyid(myid)
data=alldata[0]
myid=alldata[1]
id = alldata[3]
version=alldata[4]
# print(myid,id,version)
tools.getpdf(id,myid,version)
#For windows you need to use drive name [ex: F:/Example.pdf]
path = "downloads/"+myid+"-"+id+"/"+myid+"-metopes.tei.xml"
return send_file(path, as_attachment=True)
@app.route('/motscles/index.html') # route où seront servies ces données
def keywords(): # la fonction qui sert les données pour la route /
if config.dynamic:
data = tools.setkeywords()
else:
data = json.load(open('caches/keywords.json','r'))
data = sorted(data, key=lambda k: k['name'])
return render_template('motscles.html', data=data)
@app.route('/motscles/<name>.html')
def keyword(name):
if config.dynamic:
data = tools.setkeywords()
else:
data = json.load(open('caches/keywords.json','r'))
mykeyword={}
for k in data:
if k['nameslug'] == name:
mykeyword = k
return render_template('motcle.html', mykeyword=mykeyword)
@app.route('/authors/index.html') # route où seront servies ces données
def authors(): # la fonction qui sert les données pour la route /
if config.dynamic:
data = tools.setauthors()
else:
data = json.load(open('caches/authors.json','r'))
return render_template('authors.html', data=data)
@app.route('/authors/<name>.html')
def author(name):
if config.dynamic:
data = tools.setauthors()
else:
data = json.load(open('caches/authors.json','r'))
author={}
for a in data:
if a['authorslug'] == name:
myauthor = a
return render_template('author.html', author=myauthor)
@app.route('/dossiers/index.html') # route où seront servies ces données
def dossiers(): # la fonction qui sert les données pour la route /
if config.dynamic:
data = tools.setdossiers()
else:
data = json.load(open('caches/dossiers.json','r'))
return render_template('dossiers.html', data=data)
@app.route('/dossiers/<idd>.html')
def dossier(idd):
if config.dynamic:
data = tools.setdossiers()
else:
data = json.load(open('caches/dossiers.json','r'))
mydossier={}
for d in data:
if d['dossier']['id'] == idd:
mydossier = d
return render_template('dossier.html', mydossier=mydossier)
if __name__ == '__main__':
app.run(debug=True)