-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrapewat.py
44 lines (40 loc) · 1.41 KB
/
scrapewat.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
import requests
from bs4 import BeautifulSoup
import pandas as pd
import datetime
import sendmail
import texter
now = datetime.datetime.now()
def generateURL(usr):
usr.coursestring = usr.code + " " + usr.num
usr.url = "http://www.adm.uwaterloo.ca/cgi-bin/cgiwrap/infocour/salook.pl?level=under&sess=" + usr.term + "&subject=" + usr.code + "&cournum=" + usr.num
return(usr)
def scrapeTable(url):
#load and scrape
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html, 'lxml')
table = soup.table
subtable = table.table
dfs = pd.read_html(subtable.prettify(),header=0,flavor='bs4')
df = dfs[0]
return df
def spacecheck(usr):
df = scrapeTable(usr.url)
selectedRow = df[df['Comp Sec'].str.contains(usr.sec)]
cap = selectedRow['Enrl Cap'].astype(int)
tot = selectedRow['Enrl Tot'].astype(int)
diff = cap.iloc[0] - tot.iloc[0]
print()
if diff != 0 and usr.space != False:
message = "There are " + str(diff) + " spots open in " + usr.coursestring
print(message)
#sendmail.emailNotification(emailAddr,courseString)
#texter.sendtext(usr.phone,message)
usr.space = True
elif diff == 0:
print("No spots currently open in " + usr.coursestring +", will try again later")
usr.space = False
#setSpaceAvail(id,spaceAvail)
else:
print("Already notified for " + usr.coursestring)