-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-json.py
62 lines (53 loc) · 2.15 KB
/
generate-json.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
import json
import sys
if len(sys.argv) != 2:
print("Incorrect number of arguments.")
sys.exit(0)
file = sys.argv[1]
name = raw_input(
"What name would you like the email to come from? ex: Aneesh Ashutosh\n")
username = raw_input(
"What is the email you are sending from? ex: [email protected]\n")
password = raw_input(
"What is the password to that email account? ex: password\n")
subject = raw_input(
"What is the subject of the email? ex: \"Hello, {{NAME}}!\"\n")
message = raw_input(
"What is the message? ex: \"Welcome to Tech@NYU, {{NAME}}! We want your company, {{COMPANY}}, to give us cash money.\"\n")
raw_emails = raw_input(
"Please enter all emails the message should be sent to in a comma-separated list. ex: [email protected],[email protected],[email protected]\n")
variables = raw_input(
"Please enter all variable names as a comma-separated list. ex: NAME,COMPANY\n").split(",")
emails = raw_emails.split(",")
# strip all trailing whitespace from lists
map(str.strip, emails)
map(str.strip, variables)
json_dictionary = {}
json_dictionary["name"] = name
json_dictionary["username"] = username
json_dictionary["password"] = password
json_dictionary["to"] = "{{EMAIL}}"
json_dictionary["subject"] = subject
json_dictionary["message"] = message
json_variables = []
formatted_emails = []
for email in emails:
formatted_emails.append({'val': email})
json_variables.append({'var': '{{EMAIL}}', 'vals': formatted_emails})
for var in variables:
raw_variable_values = raw_input(
"Please enter all values of variable " + var + "\n")
variable_values = raw_variable_values.split(",")
map(str.strip, variable_values)
list_variables = []
for val in variable_values:
list_variables.append({'val': val})
variable_entry = {'var': '{{' + var + '}}', 'vals': list_variables}
json_variables.append(variable_entry)
json_dictionary["variables"] = json_variables
print("Saving to " + file + "...")
with open(file, 'w') as f:
json.dump(json_dictionary, f, sort_keys=True, indent=4,
separators=(',', ': '), ensure_ascii=False)
# json.dump(json_dictionary, f, ensure_ascii=False)
print("Done!")