def insertBoardData(conn, boardAbbr, pageNum, filename): currTime = unixTime() cur = conn.cursor() req = 'INSERT INTO codechan (board, pagenum, threadnum, lastupdate, filename) VALUES (%s, %s, %s, %s, %s)' arg = (boardAbbr, pageNum, -1, currTime, filename) cur.execute(req, arg) conn.commit() cur.close()
def updateBoardData(conn, boardAbbr, pageNum, filename): currTime = unixTime() cur = conn.cursor() req = 'UPDATE codechan SET lastupdate = %s, filename = %s WHERE board = %s AND pagenum = %s' arg = (currTime, filename, boardAbbr, pageNum) cur.execute(req, arg) conn.commit() cur.close
def updateThreadData(conn, boardAbbr, threadNum, filename): currTime = unixTime() cur = conn.cursor() req = 'UPDATE codechan SET lastupdate = %s, filename = %s WHERE board = %s AND threadnum = %s' arg = (currTime, filename, boardAbbr, threadNum) #print "updateThreadData:", cur.mogrify(req, arg) cur.execute(req, arg) conn.commit() cur.close()
def saveCourseDict(): startTime = time.clock() cfg = loadConfig() season = cfg['oneStop']['season'] year = cfg['oneStop']['year'] courseDataDir = cfg['dataLoc']['courseDataDir'] dataExt = cfg['dataLoc']['courseDataExt'] # **** is the abbreviation for 'all subjects' oneStopLookupUrl = oneStopUtils.getOneStopSearchUrl(season, year, '****') timeScraped = unixTime() # retrieve html from OneStop htmlObj = urllib2.urlopen(oneStopLookupUrl) rawHtml = htmlObj.read() courseDict = bsParseHtml(rawHtml) with open(courseDataDir + '/' + str(timeScraped) + '.' + dataExt, 'w') as dataOut: cPickle.dump(courseDict, dataOut) totalTime = time.clock() - startTime return totalTime
def getSecsSinceLastThreadUpdate(conn, boardAbbr, threadNum): return unixTime() - getLastUpdateOfThreadData(conn, boardAbbr, threadNum)
def getSecsSinceLastBoardUpdate(conn, boardAbbr, pageNum): return unixTime() - getLastUpdateOfBoardData(conn, boardAbbr, pageNum)
#!/usr/bin/python2 import sys import getpass import csv from unixTime import unixTime csvFile = 'cardLog.csv' cardLog = {} print 'Swipe your U card now.' while True: raw = getpass.getpass('') swipeTime = unixTime() if raw == "": break #print '\t' + raw # track 1 begins with % and ends with ? # track 2 begins with ? and ends with ? start1 = raw.find('%') end1 = raw.find('?') track1 = raw[start1+1:end1] raw2 = raw[end1+1:] start2 = raw2.find(';') end2 = raw2.find('?') track2 = raw2[start2+1:end2] data1 = track1.split('^')