Created
September 22, 2012 18:08
-
-
Save matchdav/3767257 to your computer and use it in GitHub Desktop.
Uvic - CSC 326 Algorithms - check for posted assignments and send them by email.
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
import commands | |
import re | |
#I wrote this script to check whether our Uvic CSC 326 assignments are posted. | |
#That's because our instructor can't be bothered to let us know when he posts them. | |
#I suggest using cron to schedule it every 15 mins on your server | |
email = "[email protected]" | |
def do_mailout(email, filename, url): | |
cmd = "cat "+ filename + " | mail -s '"+url+"' " + email | |
print commands.getstatusoutput(cmd) | |
# urls are of the form 'http://csc.uvic.ca/courses/csc326/assign/hw[x]_F2012.html" | |
root = "http://csc.uvic.ca/courses/csc326/assign/hw" | |
# and if he hasn't posted it we get a 302 return code | |
notthere = re.compile("302 Found") | |
for i in range(1,7): | |
path = root + str(i) + "_F2012.html" | |
filename = "assignment" +str(i) + ".html" | |
# we first check to see whether we already have this assignment by reading the file, | |
# checking for a 302 error code. | |
# if we don't find one, we have the assignment, so move on to the next one. | |
findit = "cat " + filename | |
haveit = commands.getstatusoutput(findit) | |
is302 = notthere.search(haveit[1]) | |
if ((haveit[0] ==0) & (not is302)): | |
continue | |
else: | |
query = "curl " + path | |
response = commands.getstatusoutput(query) | |
is302 = notthere.search(response[1]) | |
if (not is302): | |
print "Curling " + filename | |
curlit = query + " > " + filename | |
gotit = commands.getstatusoutput(curlit) | |
if ((gotit[0]==0)): | |
#then email it! | |
do_mailout(email, filename, path) | |
else: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment