In [3]:
import requests
import smtplib
from time import sleep
from numpy import random
import pandas as pd

In [7]:
courses = [
    ('matthew.annam.ho@gmail.com','ECE','340','56895'),
    ('maho3@illinois.edu','CS','498','65685')
]
courses = pd.read_csv('courses.csv', dtype={'Course': str,'CRN': str})
courses.to_csv('courses.csv',index=False)
courses


Out[7]:
Name Email Dept Course CRN Open
0 MAH matthew.annam.ho@gmail.com ECE 340 56895 0
1 MAH maho3@illinois.edu CS 498 65685 0

In [3]:
def alert(row):
    ADDR = "dummymattho@gmail.com"
    passw = "dummyaccount"

    content = (row['Dept']+ ' ' + row['Course'] + ', CRN: ' 
               + row['CRN'] + ', is available \n\nIt may not be immediately apparent on Course Explorer, as that site only refreshes every 20 min.')
    
    mail = smtplib.SMTP('smtp.gmail.com',587)
    mail.ehlo()
    mail.starttls()
    mail.login(ADDR,passw)
    mail.sendmail(ADDR, row['Email'],content) 
    mail.close()
    print("Sent update to:")
    print row

In [8]:
while True:
    courses = pd.read_csv('courses.csv', dtype={'Course': str,'CRN': str})
    
    for index, row in courses.iterrows():

        a = requests.get('http://courses.illinois.edu/cisapp/explorer/schedule/2017/spring/'
                         + row['Dept'] +'/' + row['Course'] + '/' + row['CRN']+'.xml', 
                         auth=()).text

        if u'Closed' in a:
            print(row['Dept'] +' ' + row['Course'] + ': closed')
            courses.loc[row.name,'Open'] = 0
        elif (u'null' in a) or (u'Error' in a):
            print(row['Dept'] +' ' + row['Course'] + ': XML RETRIEVAL ERROR')
        else:
            print(row['Dept'] +' ' + row['Course'] + ': OPEN')
            
            if row['Open'] == 0:
                alert(row)
            courses.loc[row.name,'Open'] = 1
            
    sleep(15*random.poisson(20))


Name                             MAH
Email     matthew.annam.ho@gmail.com
Dept                             ECE
Course                           340
CRN                            56895
Name: 0, dtype: object
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-bab0cda4dee0> in <module>()
      5 
      6         a = requests.get('http://courses.illinois.edu/cisapp/explorer/schedule/2017/spring/'
----> 7                          + row['Dept'] +'/' + row['Course'] + '/' + row['CRN']+'56895.xml',
      8                          auth=()).text
      9 

TypeError: cannot concatenate 'str' and 'int' objects

In [ ]:


In [20]:
for index, row in courses.iterrows():

    a = requests.get('http://courses.illinois.edu/cisapp/explorer/schedule/2017/spring/'
                     + row['Dept'] +'/' + row['Course'] + '/' + row['CRN']+'.xml', 
                     auth=()).text

    if u'Closed' in a:
        print(row['Dept'] +' ' + row['Course'] + ': closed')
        courses.loc[row.name,'Open'] = 3
    elif (u'null' in a) or (u'Error' in a):
        print(row['Dept'] +' ' + row['Course'] + ': XML RETRIEVAL ERROR')
    else:
        print(row['Dept'] +' ' + row['Course'] + ': OPEN')
        alert(row)


ECE 340: closed
CS 498: closed

In [18]:
courses.loc[row.name,'Open'] = 3

In [21]:
courses


Out[21]:
Name Email Dept Course CRN Open
0 MAH matthew.annam.ho@gmail.com ECE 340 56895 3
1 MAH maho3@illinois.edu CS 498 65685 3

In [ ]:


In [ ]:


In [23]:
m = re.search(r'(?<= \<script type="text/javascript"\>) \w+',str(r.text))
m.group(0)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-23-5de34db3d407> in <module>()
      1 m = re.search(r'(?<= \<script type="text/javascript"\>) \w+',str(r.text))
----> 2 m.group(0)

AttributeError: 'NoneType' object has no attribute 'group'

In [25]:
x = page.find('script',type='text/javascript')

In [38]:
import requests
import smtplib
from time import sleep
def alert():
    ADDR = 'DANK@NUGS.COM'
    content = ("340 (CRN 56895) is open")
    mail = smtplib.SMTP('smtp.gmail.com',587)
    mail.ehlo()
    mail.starttls()
    mail.login(ADDR,'EMAIL PASSWORD HERE')
    mail.sendmail(ADDR,ADDR,content) 
    mail.close()
    print("Sent")
    sleep(60*10)

while True:
    a = requests.get('http://courses.illinois.edu/cisapp/explorer/schedule/2017/spring/ECE/340/56895.xml', auth=()).text
    if u'Closed' in a:
        print('closed')
    else:
        print('OPEN: 56895')
        alert()
    sleep(60*5)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-38-904040f3f26f> in <module>()
----> 1 json.loads(x.text)

/usr/lib64/python2.7/json/__init__.pyc in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    336             parse_int is None and parse_float is None and
    337             parse_constant is None and object_pairs_hook is None and not kw):
--> 338         return _default_decoder.decode(s)
    339     if cls is None:
    340         cls = JSONDecoder

/usr/lib64/python2.7/json/decoder.pyc in decode(self, s, _w)
    364 
    365         """
--> 366         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    367         end = _w(s, end).end()
    368         if end != len(s):

/usr/lib64/python2.7/json/decoder.pyc in raw_decode(self, s, idx)
    382             obj, end = self.scan_once(s, idx)
    383         except StopIteration:
--> 384             raise ValueError("No JSON object could be decoded")
    385         return obj, end

ValueError: No JSON object could be decoded

In [8]:
import smtplib

In [4]:
a = requests.get('http://courses.illinois.edu/cisapp/explorer/schedule/2017/spring/ECE/340/56895.xml', auth=()).text

In [10]:
ADDR = 'matthew.annam.ho@gmail.com'
content = ("340 (CRN 56895) is open")
mail = smtplib.SMTP('smtp.gmail.com',587)
mail.ehlo()
mail.starttls()
mail.login(ADDR,'pass11Word!')
mail.sendmail(ADDR,ADDR,content) 
mail.close()