-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_research_canvases.py
88 lines (70 loc) · 3.75 KB
/
create_research_canvases.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
"""
This script is used to create Slide-based Research Canvases for each project in DTR, given a Canvas template, output directory, and
studio database with student and project information.
"""
import sys
import helpers.imports as helpers
import studio_db_to_json as studio_db
from copy_gdrive_file import copy_file
def generate_research_canvases(studio_db_dict, gdrive_service, template_url, folder_url, qtr):
"""
Generates a Canvas for each project.
:param studio_db_dict: dict of each SIG with all student and project information.
:param gdrive_service: Google Drive v3 authentication object.
:param template_url: string url of original file to copy.
:param folder_url: string url of folder to copy file to.
:param qtr: string name of quarter to generate Canvases for.
:return: None
"""
# iterate over each SIG, and generate file names
for sig_name, sig_info in studio_db_dict.items():
# hold SIG abbreviation for file names
curr_sig_abb = sig_info["abbreviation"]
# iterate over projects
for proj in sig_info["projects"]:
# generate filename
curr_proj_name = proj["project_name"]
curr_filename = "[{abb}] {proj} Practical/Conceptual Research Canvas".format(abb=curr_sig_abb, proj=curr_proj_name, qtr=qtr)
# copy original file for each project using curr_filename
curr_copied_file = copy_file(gdrive_service, template_url, folder_url, curr_filename)
# generate a file URL for copied file, and print out
curr_file_id = curr_copied_file["id"]
print("{filename}: https://docs.google.com/spreadsheets/d/{id}/edit".format(filename=curr_filename,
id=curr_file_id))
def main(template_file_url, folder_url, qtr_str, studio_db_url, sig_info_sheet_name, proj_info_sheet_name):
"""
Fetches Studio Database information and uses it to generate Canvases.
:param template_file_url: string url of original file to copy.
:param folder_url: string url of folder to copy file to.
:param studio_db_url: string url of Studio Database Google Spreadsheet
:param qtr_str: string name of quarter to generate Canvases for.
:param sig_info_sheet_name: string name of sheet where SIG information is stored.
:param proj_info_sheet_name: string name of sheet where Project information is stored.
:return:
"""
# authenticate for Google Drive v3 and Google Spreadsheets APIs
gdrive_service = helpers.auth_gdrive()
gspreadsheets_service = helpers.auth_gsheets()
# generate studio database
studio_db_dict = studio_db.main(studio_db_url, sig_info_sheet_name, proj_info_sheet_name)
# generate Canvases for each project
generate_research_canvases(studio_db_dict, gdrive_service, template_file_url, folder_url, qtr_str)
if __name__ == '__main__':
# get command line args
arg_count = len(sys.argv) - 1
# check for correct number of arguments
if arg_count != 6:
raise Exception("Invalid number of arguments. Expected 5 "
"(Canvas template URL, Canvas folder URL, Quarter Name, "
"Studio Database URL, SIG Info sheet name, Proj Info sheet name) got {}."
.format(arg_count))
# inputs for creating Canvases
input_template_file_url = sys.argv[1]
input_folder_url = sys.argv[2]
input_qtr_str = sys.argv[3]
# inputs for generating studio database
input_studio_db_url = sys.argv[4]
input_sig_info_sheet_name = sys.argv[5]
input_proj_info_sheet_name = sys.argv[6]
main(input_template_file_url, input_folder_url, input_qtr_str,
input_studio_db_url, input_sig_info_sheet_name, input_proj_info_sheet_name)