/
sync-sheet.py
704 lines (612 loc) · 24.5 KB
/
sync-sheet.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
# coding: utf-8
"""
Shows basic usage of the Sheets API. Prints values from a Google Spreadsheet.
"""
import re
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from pprint import pprint
from pathlib import Path
import click
import logging
LOGGER = logging.getLogger("PWS")
logging.basicConfig(level=logging.INFO)
### ---------------------------------------- CONFIGURATION
SPREADSHEET_ID = '17XzKw0Gf3vKWzqRTrC-hV4bhi09sfGJO5oGFHQSq1iU'
RELAZIONI = 'RELAZIONI'
RELATORI = 'RELATORI'
ORGANIZZATORI = ['calamari', 'giorio', 'somma']
EPRIVACY_N = 'XXIX'
URL = 'e-privacy-'
PATH = 'content/2021/summer/'
PROG_FNAME = 'programma.md'
GIORNO1 = 'Giorno1'
GIORNO2 = 'Giorno2'
SESSIONI = '1M,1P,2M'.split(',')
F_ORG = 'org'
## ---------------------------------------- FINE CONFIGURAZIONE
def program_line(*cols):
return " | ".join(cols)
def section_open(label, kind, srange, service, _id, info, rdb):
lines = []
for label, record in info.items():
try:
people = record['pers'].strip()
if ',' in people:
people = re.split(r', *', people)
else:
people = [people, ]
names = make_persons(people, rdb)
durata = re.sub(r'^0(|(0:))', '', record['Durata'])
lines.append(program_line(record['Ora'],
durata,
names + "<br/>" + record['Titolo']))
except:
print("ERRORE: sulla linea {}".format(label))
raise
return lines, rdb
def section_saluti(label, kind, srange, service, _id, info, rdb):
return section_open(label, kind, srange, service, _id, info, rdb)
def section_talks(label, kind, srange, service, _id, info, rdb):
lines = []
for label, record in sorted(info.items()):
try:
people = [record['pers'], ]
if 'altri' in record and len(record['altri'].strip())>0:
altri = re.split(r', *', record['altri'])
people.extend(altri)
for person in people:
if person in rdb:
rdb[person]['talk'].append( record )
else:
LOGGER.error('TALK: '+person+" non nel DB")
names = make_persons(people, rdb)
durata = re.sub(r'^0(|(0:))', '', record['Durata'])
titolo = rdb[record['pers']]['Titolo']
titolo = mk_intervento(titolo, record['pers'])
lines.append(program_line(record['Ora'],
durata,
names + "<br/>" + titolo ))
except:
print("ERRORE: sulla linea {}".format(label))
raise
return lines, rdb
def section_roundtable(label, kind, srange, service, _id, info, rdb):
lines = []
for label, record in sorted(info.items()):
try:
tavola = [record['pers'], ]
people = []
modera = 'tba'
if 'altri' in record:
people = re.split(r', *', record['altri'])
modera = people.pop(0)
if modera in rdb:
record['role'] = 'moderatore'
rdb[modera]['roundtable'].append( record )
for person in people:
if person in rdb:
rdb[person]['roundtable'].append( record )
else:
LOGGER.error('TALK: '+person+" non nel DB")
modera = make_persons([modera, ], rdb)
names = make_persons(people, rdb)
names = "Modera: "+modera+"<br/>Partecipano: "+names
durata = re.sub(r'^0(|(0:))', '', record['Durata'])
titolo = rdb[record['pers']]['Titolo']
titolo = "Tavola Rotonda: " + mk_intervento(titolo, record['pers'])
lines.append(program_line(record['Ora'],
durata,
titolo + "<br/>" + names))
except:
print("ERRORE: sulla linea {}".format(label))
raise
return lines, rdb
def section_pausa(label, kind, srange, service, _id, info, rdb):
lines = []
for label, record in info.items():
try:
durata = re.sub(r'^0(|(0:))', '', record['Durata'])
lines.append(program_line(record['Ora'],
durata,
record['Titolo']))
except:
print("ERRORE: sulla linea {}".format(label))
raise
return lines, rdb
def mk_md_link(nome, label, sezione, num=EPRIVACY_N):
return "[_{nome}_](e-privacy-{num}-{sezione}.html#{label})".format(
nome=nome, num=num, label=label, sezione=sezione
)
def mk_relatore(nome, label, num=EPRIVACY_N):
return "<span class='speaker'>"+mk_md_link(nome, label, 'relatori', num)+"</span>"
def mk_intervento(nome, label, num=EPRIVACY_N):
return "<span class='talk'>"+mk_md_link(nome, label, 'interventi', num)+"</span>"
def format_relatori(relatori):
md_relatori = []
for relatore in re.split(';', relatori):
md_relatori.append(mk_relatore(relatore))
return ','.join(md_relatori)
FORMATS = (
lambda label, x: x,
lambda label, x: re.sub(r'^00:', '', x),
)
def make_authors_roundtable(info, rdb):
if 'altri' in info and len(info['altri'])>0:
altri = list(map(lambda x: x.strip(), re.split(',', info['altri'])))
pres = altri.pop(0)
if pres in rdb:
record = rdb[pres]
else:
return ""
org = ""
if F_ORG in record and len(record[F_ORG]) > 0:
org = ("({"+F_ORG+"})").format(**record)
di = "Modera: <a href=\"/e-privacy-{num}-relatori.html#{label}\">{Nome} {Cognome} {org}</a>".format(
num=EPRIVACY_N,
org=org,
**record)
di += "<br/>Partecipano: " + ", ".join(map(lambda x: "<a href=\"/e-privacy-{num}-relatori.html#{label}\">{Nome} {Cognome} {org}</a>".format(
num=EPRIVACY_N,
**rdb[x],
org=("("+rdb[x][F_ORG]+")") if F_ORG in rdb[x] and len(rdb[x][F_ORG]) > 0 else '',),
altri))
di = re.sub(r'(.*), ([^.]+)$', '\\1 e \\2', di)
return di
def db_get_attrs(attr,service, _id, _range, HEADERS):
""" get an attribute from a dict of dict """
ret = []
lines = read_db(service, _id, _range, HEADERS)
for values in lines.values():
if attr in values:
val = values[attr]
if val:
ret.append(val)
return ret
def write_out(path, fname, **kw):
templ_f = Path(path) / (fname+'.template')
out_f = Path(path) / fname
templ = templ_f.read_text(encoding='utf-8')
output = templ.format(**kw)
out_f.write_text(output)
print("scrittura "+str(out_f)+" from template "+str(templ_f))
def lay_talk(talk, item, db):
pres = talk['pers']
item = db[pres]
titolo = item['Titolo']
con = ""
if titolo in db:
titolo = db[titolo]['Titolo']
if 'altri' in talk and len(talk['altri'])>0:
label = item['label']
altri = list(map(lambda x: x.strip(),
re.split(',', talk['altri'])))
altri.append(talk['pers'])
if label in altri:
altri.remove(label)
if len(altri)>0:
con = ", ".join(map(
lambda x: "<a href=\"/e-privacy-{num}-relatori.html#{label}\">{Nome} {Cognome}</a>".format(
num=EPRIVACY_N, **db[x.strip()]), altri))
con = " con " + re.sub(r'(.*), ([^.]*)', '\\1 e \\2', con)
return talk, titolo, con
def lay_roundtable(talk, item, db):
label = talk['pers']
con = ""
titolo = db[label]['Titolo']
ruolo = "Partecipa al"
if 'altri' in talk:
label = item['label']
altri = list(map(lambda x: x.strip(),
re.split(',', talk['altri'])))
moderatore = altri.pop(0)
if moderatore == label:
ruolo = "Modera "
con = ", ".join(map(
lambda x: "<a href=\"/e-privacy-{num}-relatori.html#{label}\">{Nome} {Cognome}</a>".format(
num=EPRIVACY_N, **db[x.strip()]), altri))
con = " con " + re.sub(r'(.*), ([^.]*)', '\\1 e \\2', con)
if ruolo == 'Partecipa al':
con += " moderata da <a href=\"/e-privacy-{num}-relatori.html#{label}\">{Nome} {Cognome}</a>".format(num=EPRIVACY_N, **db[moderatore.strip()])
return talk, ruolo, titolo, con
def make_roundtable(item, db):
pers = item['author']
aList = re.split(r' *, *', item['altri'])
modera = aList.pop(0)
modera = "Modera: " + make_persons(modera, db)
partecipa = "Partecipa: " + make_persons(aList, db)
return "Tavola Rotonda: " + mk_intervento(item['title'], pers) + "<br/>" + modera + "<br/>" + partecipa
def make_authors(info, rdb):
if 'pers' not in info:
return ""
pres = info['pers']
if pres in rdb:
record = rdb[pres]
else:
return ""
org = ""
if F_ORG in record and len(record[F_ORG]) > 0:
org = ("({"+F_ORG+"})").format(**record)
di = "<a href=\"/e-privacy-{num}-relatori.html#{label}\">{Nome} {Cognome} {org}</a>".format(
num=EPRIVACY_N,
org=org,
**record)
if 'altri' in info and len(info['altri'])>0:
altri = list(map(lambda x: x.strip(), re.split(',', info['altri'])))
di += ", " + ", ".join(map(lambda x: "<a href=\"/e-privacy-{num}-relatori.html#{label}\">{Nome} {Cognome} {org}</a>".format(
num=EPRIVACY_N,
**rdb[x],
org=("("+rdb[x][F_ORG]+")") if F_ORG in rdb[x] and len(rdb[x][F_ORG]) > 0 else '',),
altri))
di = re.sub(r'(.*), ([^.]*)', '\\1 e \\2', di)
return di
def make_person(label, db):
return make_authors(
{'pers': label,
'label': label},
db)
def compose_people(talk, db, all=False):
aList = [ talk['author'], ]
if 'altri' in talk and all:
altri = talk['altri']
if ',' in altri:
aList.extend(altri.split(','))
else:
aList.append(altri)
return compose_person(db['relatori'], *aList)
### ---------------------------------------- ELEMENT COMPOSITIONS
def compose_person(rdb, *people, org=True):
output = []
for person in people:
person = re.sub("\d","",person)
if person not in rdb:
LOGGER.error('COMPOSE_PERSON:NO RECORD FOR:'+person)
continue
record = rdb[person]
o_org = ""
if org and F_ORG in record and len(record[F_ORG])>0:
o_org = ("({"+F_ORG+"})").format(**record)
o_name = "<a href=\"/e-privacy-{num}-relatori.html#{label}\">{Nome} {Cognome} {Xorg}</a>".format(
num=EPRIVACY_N,
Xorg=o_org,
**record)
output.append(o_name)
if output:
answer = ', '.join(output)
answer = re.sub(r'(.*), ([^.]*)', '\\1 e \\2', answer)
return answer
# compose_title
def compose_title(relazioni, talk):
relazione = talk['author']
output = None
if relazione not in relazioni:
LOGGER.error(f'COMPOSE_TITLE:NO RECORD FOR: {relazione}')
return None
record = relazioni[relazione]
index = talk['label']
title = record['title']
prefix = ''
if re.match(r'tavola rotonda',title,re.I):
prefix = "Tavola Rotonda: "
title = re.sub(r'^Tavola Rotonda: *','',title, re.I)
label = record['label']
output = f"<a name='{index}'></a>{prefix}<a href=\"/e-privacy-{EPRIVACY_N}-interventi.html#{label}\">{title}</a>"
return output
# compose_time
# cimpose_duration
def compose_email(all_relatori, all_relazioni, db, dictionary):
write_out(PATH,'email.md',
RELATORI = _compose_speakers(all_relatori, db),
INTERVENTI = _compose_interventi(all_relazioni, db),
**dictionary)
def _compose_speakers(all_relatori, db):
relatori = {}
for cognome, item in sorted(all_relatori):
rkey = item['Cognome'].capitalize()
LOGGER.info("SPEAKERS:"+cognome+"/"+rkey)
if rkey.lower() in ORGANIZZATORI or len(rkey)==0:
LOGGER.info("SPEAKERS:exclude:"+rkey)
continue
relatori[rkey] = compose_speaker_bio(item,db)
str_out = ""
for label,relatore in sorted(relatori.items()):
LOGGER.info('SPEAKERS:writeout:'+label)
str_out += relatore + "\n"
return str_out
def compose_speakers(all_relatori, db):
write_out(PATH, 'speakers.md',
RELATORI=_compose_speakers(all_relatori, db))
def compose_speaker_bio(item,db):
label = item['label']
if 'bio' in item:
org = ""
if F_ORG in item and len(item[F_ORG]) > 0:
org = "(" + item[F_ORG] + ")"
bio = '#### <a name="{label}"></a> {Nome} {Cognome} {Xorg}\n\n{bio}\n'.format(
num=EPRIVACY_N,
Xorg=org,
**item )
# talks = []
# if 'talk' in item:
# for talk in item['talk']:
# talks.append(lay_talk(talk, item, db))
# if len(talks)>0:
# bio += "\nAd e-privacy " + EPRIVACY_N + " presenta <br/>\n"
# for talk, titolo, con in talks:
# bio += "<b><a href=\"e-privacy-{num}-interventi.html#{label}\">".format(num=EPRIVACY_N, label=talk['pers']) + titolo + "</a></b> alle <a href=\"/e-privacy-{num}-programma.html#{label}\">".format( num=EPRIVACY_N, label=talk['label']) + talk['Ora'] + " di " + talk['Giorno'] + "</a>" + con + ".<br/>"
# bio += "<br/>\n"
# roundtables = []
# if 'roundtable' in item:
# for roundtable in item['roundtable']:
# roundtables.append(lay_roundtable(roundtable, item, db))
# if len(roundtables)>0:
# # bio += "\nPartecipa alla " + ( "Tavola Rotonda" if len(roundtables) == 1 else "Tavole rotonde" ) + " <br/>\n"
# for talk, ruolo, titolo, con in roundtables:
# bio += "<br/>{ruolo}la Tavola Rotonda <b><a href=\"e-privacy-{num}-interventi.html#{label}\">".format(ruolo=ruolo,num=EPRIVACY_N, label=talk['pers']) + titolo + "</a></b> alle <a href=\"/e-privacy-{num}-programma.html#{label}\">".format( num=EPRIVACY_N, label=talk['label']) + talk['Ora'] + " di " + talk['Giorno'] + "</a>" + con + ".<br/>\n\n"
bio += '\n\n'
return bio
def _compose_interventi(all_relazioni, db):
# service, id, db, pr):
str_out = ""
relazioni = dict()
for label, talk in all_relazioni:
LOGGER.info('TALKS:writeout:'+label)
relazioni[label] = compose_talk_info(talk, db)
for label,relazione in sorted(relazioni.items()):
str_out += relazione + "\n"
return str_out
def compose_interventi(all_relazioni, db):
write_out(PATH, 'interventi.md',
INTERVENTI=_compose_interventi(all_relazioni, db))
def compose_talk_info(talk, db):
label = talk['author']
link = talk['label']
title = talk['title']
_title = f'#### <a name="{label}"></a> {title}'
_up = f'<a href="/e-privacy-{EPRIVACY_N}-programma.html#{link}">⇧</a>'
auth = [ talk['author'], ]
_authors = "*"+compose_people(talk, db, all=True)+"*"
desc = db['relazioni'][label]['description']
return f'{_title}{_up}\n{_authors}\n\n{desc}\n\n'
#### ---------------------------------------- SETUP PROGRAM
def setup_title(talk, relazioni, relatori):
return compose_title(relazioni, talk)
def setup_Durata(talk, relazioni, relatori):
if len((talk['Durata'])):
ore, minuti = map(int, talk['Durata'].split(':'))
return str(ore*60+minuti)
return ""
def setup_opening_author(talk, relazioni, relatori):
return ''
def setup_opening_title(talk, relazioni, relatori):
return talk['title']
def setup_closing_author(talk, relazioni, relatori):
return ''
def setup_closing_title(talk, relazioni, relatori):
return talk['title']
def setup_welcome_author(talk, relazioni, relatori):
auth = talk['author']
if auth == 'tba':
return ''
if auth in relatori:
return compose_person(relatori, auth)
return '?!?'
def setup_welcome_title(talk, relazioni, relatori):
return talk['title']
def setup_talk_author(talk, relazioni, relatori):
auth = [ talk['author'], ]
if 'altri' in talk:
for altro in talk['altri'].split(','):
auth.append( altro)
return compose_person(relatori, *auth)
def setup_roundtable_author(talk, relazioni, relatori):
if 'altri' in talk:
names = talk['altri'].split(',')
if len(names)>0:
moderator = names.pop(0)
partecipa = compose_person(relatori, *names)
return "Modera: " + compose_person(relatori, moderator) + "<br/>Partecipano: " + partecipa
return ""
def setup_program_session(info, relazioni, relatori):
program = info['program']
session = []
D_relazioni = list()
D_relatori = list()
for label,talk in program:
kind = talk['kind']
line = []
for num, field in enumerate(('Ora','Durata','author', 'title')):
method = None
name = f'setup_{kind}_{field}'
if name in globals():
method = globals()[name]
else:
name = f'setup_{field}'
if name in globals():
method = globals()[name]
if method:
value = method(talk, relazioni, relatori)
else:
value = talk[field]
talk[f'OUT_{num:02d}_{field}'] = value
line.append(value)
title = line.pop()
author = line.pop()
line.append('')
line[-1] = "<span class='talk'>"
if len(author) > 0:
line[-1] += author + "<br/>"
line[-1] += "<em>" + title +"</em>"
line[-1] += "</span>"
session.append('|'.join(line))
if kind == 'roundtable':
relatoreX = re.sub("\d","",relatore)
D_relatori.append((relatore, relatori[relatoreX] ))
if 'altri' in talk:
for altro in talk['altri'].split(','):
if altro in relatori:
D_relatori.append((altro,relatori[altro]))
elif kind == 'talk':
relatore = talk['author']
intervento = relazioni[relatore]
D_relazioni.append((relatore, talk))
relatoreX = re.sub("\d","",relatore)
D_relatori.append((relatore, relatori[relatoreX] ))
if 'altri' in talk:
for altro in talk['altri'].split(','):
if altro in relatori:
D_relatori.append((altro,relatori[altro]))
return session, D_relazioni, D_relatori
#### ---------------------------------------- READ FUNCTIONS
def read_db(service, id, range, tweak_item=None, tweak_collection=None):
result = service.spreadsheets().values().get(spreadsheetId=id,
range=range).execute()
values = result.get('values', [])
infos = {}
if not values:
print('No data found.')
else:
for jj,row in enumerate(values):
if jj == 0:
HEADERS = row
continue
if len(row[0]):
info = dict(zip(HEADERS, row))
info['label'] = info['label'].lower()
if 'pers' in info:
info['pers'] = info['pers'].lower()
if 'altri' in info:
info['altri'] = info['altri'].lower()
if tweak_item:
info = tweak_item(info)
infos[info['label'].lower()] = info
if tweak_collection:
infos = tweak_collection(infos)
return infos
def tweak_relazioni(info):
info['talk']=[]
info['roundtable']=[]
return info
def tweak_sessioni(info):
LOGGER.info("LABEL:"+info['label'])
if info['label'][-2:].lower() == 'aa':
info['label'] = 'apertura'
info['kind'] = 'opening'
info['order'] = -1
elif info['label'][-2:].lower() == 'ss':
info['label'] = 'saluti'
info['kind'] = 'welcome'
info['order'] = 0
elif info['label'][-2:].lower() == 'zz':
info['label'] = 'chiusura'
info['kind'] = 'closing'
info['order'] = 100
else:
order = int(info['label'][-2:])
info['order'] = order
info['kind'] = 'talk'
if info['author'][:6] == 'tavola':
info['kind'] = 'roundtable'
return info
def tweak_sessioni_collection(info):
program = []
for key, value in sorted( info.items(),
key=lambda x : x[1]['order']):
program.append((key, value))
info['program'] = program
# pprint(info)
if 'apertura' in info:
info['chairman'] = info['apertura']['author']
return info
def read_programma_db(service, _id, rdb, SESSIONI):
variables = {}
db = {}
J = 0
K = 0
for variable, J, K, sessione, chair in SESSIONI:
program = []
db["{}.{}".format(J,K)] = {}
chairman = db_get_attrs('pers',service, _id, chair, PROGRAMMA_HEADERS)
if chairman:
chairman = re.split(r'\s*,\*',chairman[0])
chairman = compose_person(rdb, *chairman)
LOGGER.info('SESSIONE '+variable)
LOGGER.info('CHAIRMAN '+chairman)
for label, kind, srange in sessione:
LOGGER.info(' PARTE '+label)
prog = read_db(service,
_id,
srange,
PROGRAMMA_HEADERS)
db["{}.{}".format(J,K)].update(prog)
func = "section_" + kind
if func not in globals():
raise SyntaxError('function {} '
'not in globals()'.format(func))
else:
func = globals()[func]
prglines, rdb = func(label, kind, srange,
service, _id, prog,
rdb)
program.extend(prglines)
variables[variable] = '\n'.join(program)
variables["CHAIRMAN_" + variable]=compose_person(rdb,chairman)
return variables, rdb, db
#### ---------------------------------------- END READ FUNCTIONS
#### ---------------------------------------- SETUP SYNC SHEET
def setup_sheet_work(SPREADSHEET_ID):
SCOPES = 'https://www.googleapis.com/auth/spreadsheets.readonly'
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('sheets', 'v4', http=creds.authorize(Http()))
return service
@click.command()
@click.option('--debug/--no-debug', default=False)
@click.option('--debug-section', type=click.Choice(['db', 'program',
'relazioni','relatori']))
def main(debug,debug_section):
LOGGER.info('service beginning')
service = setup_sheet_work(SPREADSHEET_ID)
LOGGER.info('service loaded')
relatori = read_db(service, SPREADSHEET_ID, RELATORI )
relazioni = read_db(service, SPREADSHEET_ID, RELAZIONI, tweak_item = tweak_relazioni )
db = {'relatori': relatori, 'relazioni': relazioni , 'sessioni': SESSIONI }
dictionary = {}
all_relazioni = list()
all_relatori = list()
for session in SESSIONI:
label = 'G' + session
LOGGER.info(f'session: {label} {",".join(dict(all_relatori).keys())}')
sess_db = read_db(service, SPREADSHEET_ID, label ,
tweak_item = tweak_sessioni,
tweak_collection = tweak_sessioni_collection)
db[label] = sess_db
session, D_relazioni, D_relatori = setup_program_session(db[label],
relazioni,
relatori)
all_relazioni.extend(D_relazioni)
all_relatori.extend(D_relatori)
dictionary[label] = '\n'.join(session)
dictionary[f'{label}_CHAIRMAN'] = compose_person(relatori,sess_db['chairman'])
db['_relazioni'] = dict(all_relazioni)
db['_relatori'] = dict(all_relatori)
if debug and debug_section=='db':
pprint(db)
return
LOGGER.info('db loaded')
if debug and debug_section=='relatori':
pprint(all_relatori)
return
if debug and debug_section=='relazioni':
pprint(all_relazioni)
return
write_out(PATH, PROG_FNAME , **dictionary)
compose_speakers(all_relatori, db)
compose_interventi(all_relazioni, db)
compose_email(all_relatori, all_relazioni, db, dictionary)
if __name__ == '__main__':
main()