Last active
July 26, 2020 02:00
-
-
Save hoefler02/73d807ed5968ab8b0507dc2d1666cfed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
This is a script to query the WVU course listing, checking for seat openings. | |
CRN refers to "course reference number", which is found by visiting | |
courses.wvu.edu. Term is passed as a string (eg. "Fall 2020"), and is converted | |
to a numeric code which is used to query for the desired course. Enjoy! | |
""" | |
from config import account_sid, auth_token, send_number, recieve_number, crn, term | |
from twilio.rest import Client | |
from datetime import datetime | |
import requests | |
import time | |
import json | |
class WVUClient: | |
def __init__(self, crn, term): | |
self.bot = requests.Session() | |
self.crn = crn | |
search = {'offset':'1','max':'10','query':term} | |
options = self.bot.get('https://starss.wvu.edu/StudentRegistrationSsb/ssb/classSearch/getTerms', params=search) | |
self.term = json.loads(options.text)[0]['code'] | |
self.newcookie() | |
def newcookie(self): | |
self.bot.cookies.clear() | |
self.bot.post('https://starss.wvu.edu/StudentRegistrationSsb/ssb/term/search', params={'mode':'search'}, data={'term':self.term}) | |
def getseats(self): | |
search = { | |
'txt_keywordexact': self.crn, | |
'txt_term': self.term | |
} | |
course = self.bot.get('https://starss.wvu.edu/StudentRegistrationSsb/ssb/searchResults/searchResults', params=search) | |
info = json.loads(course.text) | |
if not int(info['totalCount']): | |
raise Exception('Error: No course returned...') | |
seats = int(info['data'][0]['seatsAvailable']) | |
return seats | |
""" | |
Check for openings in Multivariable Calculus and use Twilio to send | |
SMS notifications. Checks every 5 minutes, and sends status updates | |
every 4 hours, or whenever an opening is detected. | |
""" | |
if __name__ == '__main__': | |
messenger = Client(account_sid, auth_token) | |
def msg(body): | |
message = messenger.messages.create(body=body, from_=send_number, to=recieve_number) | |
return message.sid | |
checker = WVUClient(crn, term) | |
checked = 0 | |
while True: | |
print(datetime.now()) | |
seats = checker.getseats() | |
if seats: | |
print('%d seats are available!' %d) | |
m = msg('There are %d seats available!' % seats) | |
if checked % 48 == 0 and not seats: | |
print('No seats available') | |
m = msg('No seats available.') | |
print('Message sent with SID = %s' % m) | |
checked += 1 | |
time.sleep(60 * 5) | |
checker.newcookie() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Configuration file for WVU Course Listing Client Script | |
# Twilio Credentials | |
account_sid = 'XXXXXXXXXXXXXXXXXXXX' | |
auth_token = 'XXXXXXXXXXXXXXXXXXXX' | |
# Send Number -> Twilio SMS Number | |
# Recieve Number -> Number for SMS Notifications | |
send_number = 'XXX-XXX-XXXX' | |
recieve_number = 'XXX-XXX-XXXX' | |
# Course Information (eg. crn = '83187'; term = 'Fall 2020') | |
crn = 'XXXXX' | |
term = 'XXXXXXXXX' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment