-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
136 lines (95 loc) · 3.18 KB
/
setup.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
'''
setup script for Dartmouth_Timetable_Scanner
author: Jai Smith
date: December 2018
'''
# imports
import pickle
import pip
import importlib.util
pip_version = int(pip.__version__.split('.')[0])
if pip_version >= 10:
from pip._internal import main as pip_main
else:
from pip import main as pip_main
# variables
number_of_courses = None
course_crns = list()
course_depts = list()
SMS_RECIPIENT = None
TWILIO_SID = None
TWILIO_AUTH_TOKEN = None
TWILIO_NUMBER = None
queries = [
'Number of courses you would like to track: ',
'CRN of course #{0}: ',
'Department of course #{0}: ',
'Target term (numeric): ',
'Interval between scans (in seconds): ',
'Enable text notifications? (y/n): ',
'Twilio SID: ',
'Twilio Auth Token: ',
'Twilio Number (include +1, no spaces): ',
'SMS Recipient (include +1, no spaces): ',
]
# functions
def get_int(message):
token = input(message)
while True:
try:
token = int(token)
return token
except ValueError:
print('Error. Please enter an integer value.')
token = input(message)
def get_yes_no(message):
token = input(message)
while token != 'y' and token != 'n':
print("Error. Please enter either 'y' or 'n'.")
token = input(message)
return token
# main code
print('Running setup...')
for query_index in range(len(queries)):
if query_index == 0:
number_of_courses = get_int(queries[0])
elif query_index == 1:
for i in range(number_of_courses):
course_crns.append(str(get_int(queries[1].format(i))))
elif query_index == 2:
for i in range(number_of_courses):
course_depts.append(str(input(queries[2].format(i))))
elif query_index == 3:
TERM = get_int(queries[3])
elif query_index == 4:
INTERVAL = get_int(queries[4])
elif query_index == 5:
SMS_ACTIVE = get_yes_no(queries[5]) == 'y'
elif query_index == 6 and SMS_ACTIVE:
TWILIO_SID = input(queries[6])
elif query_index == 7 and SMS_ACTIVE:
TWILIO_AUTH_TOKEN = input(queries[7])
elif query_index == 8 and SMS_ACTIVE:
TWILIO_NUMBER = input(queries[8])
elif query_index == 9 and SMS_ACTIVE:
SMS_RECIPIENT = input(queries[9])
COURSES = list()
for i in range(number_of_courses):
COURSES.append((course_depts[i], course_crns[i]))
with open('preferences', 'wb') as f:
pickle.dump([TERM, COURSES, INTERVAL, SMS_ACTIVE, SMS_RECIPIENT,
TWILIO_SID, TWILIO_AUTH_TOKEN, TWILIO_NUMBER], f)
# install packages
# check for installed packages
twilio_installed = importlib.util.find_spec('twilio')
requests_installed = importlib.util.find_spec('requests')
if SMS_ACTIVE and not twilio_installed:
print('Twilio package not found. Installing twilio package with pip...')
# pip
pip_main(['install', 'twilio'])
print('')
if not requests_installed:
print('Requests package not found. ' +
'Installing requests package with pip...')
# pip
pip_main(['install', 'requests'])