-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_sheets.py
executable file
·72 lines (59 loc) · 1.98 KB
/
update_sheets.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
#!/usr/bin/env python3
import argparse
from args import (
get_area_code_epilog,
add_srpo_config,
add_sheets_config,
get_area_string,
)
from sheet import Sheet
from srpo import SRPO
def get_args():
parser = argparse.ArgumentParser(
description="Update online spreadsheets with latest SRPO data",
epilog=get_area_code_epilog(),
)
add_srpo_config(parser)
add_sheets_config(parser)
parser.add_argument(
"--type",
required=True,
type=str,
choices=["latestcycles", "allcycles", "individuals"],
help="What type of data to import from the SRPO into the spreadsheet",
)
return parser.parse_args()
if __name__ == "__main__":
args = get_args()
sheet = Sheet(args.sheet_id, args.tab_name, args.key_path)
srpo = SRPO(args.secret, None)
print("Logging into SRPO...", end="", flush=True)
srpo.login(args.username, args.password)
srpo.set_area(get_area_string(args.area))
print(" Done", flush=True)
print("Retrieving data from SRPO...", end="", flush=True)
if args.type == "latestcycles":
data = srpo.get_latest_cycles()
cell_range = "A4:BS"
if not sheet.has_cgp_data():
print("Spreadsheet tab is not correctly formatted with CGP data.")
exit(1)
elif args.type == "allcycles":
data = srpo.get_all_cycles()
cell_range = "A4:BS"
if not sheet.has_cgp_data():
print("Spreadsheet tab is not correctly formatted with CGP data.")
exit(1)
elif args.type == "individuals":
data = srpo.get_individuals_data()
cell_range = "A3:BZ"
if not sheet.has_individual_data():
print(
"Spreadsheet tab is not correctly formatted with individual record data."
)
exit(1)
srpo.cleanup()
print(" Done", flush=True)
print("Updating sheet...", end="", flush=True)
sheet.update(data, cell_range)
print(" Done", flush=True)