-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmotorcycleUpdates.py
More file actions
91 lines (82 loc) · 2.43 KB
/
motorcycleUpdates.py
File metadata and controls
91 lines (82 loc) · 2.43 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
"""Summary
"""
import pytz
from datetime import datetime
from datetime import timedelta
import random
import lxml
from bs4 import BeautifulSoup
import urllib
import urllib2, urllib
import collections
import os
import re
import sys
def AddChatId(myId):
try:
file = 'motorcycle.txt'
EnsureFileExists(file)
with open(file) as f:
lines = f.read().splitlines()
if str(myId) in lines:
return "This chat is already receiving new motorcycle notifcations"
else:
lines.append(str(myId))
f = open(file, 'w')
for line in lines:
f.write("%s\n" % line)
f.close
return "Chat will now get notified of new motorcycle updates"
except:
print "error", sys.exc_info()[0]
return "something terrible may have just happened"
def RemoveChatId(myId):
try:
file = 'motorcycle.txt'
EnsureFileExists(file)
with open(file) as f:
lines = f.read().splitlines()
if str(myId) in lines:
lines.remove(str(myId))
f = open(file, 'w')
for line in lines:
f.write("%s\n" % line)
f.close
return "Chat will no longer be notified of new motorcycle updates"
else:
return "This chat isn't currently getting notified of new motorcycle"
except:
print "error", sys.exc_info()[0]
return "something terrible may have just happened"
def GetChatIds():
file = 'motorcycle.txt'
EnsureFileExists(file)
with open(file) as f:
lines = f.read().splitlines()
return lines
def EnsureFileExists(filename):
if not os.path.exists(filename):
file(filename, 'w').close()
def getCount():
"""Summary
Returns:
TYPE: Description
"""
url = 'https://axiom.lcc.edu/wconnect/ace1/ShowSchedule.awp1?&Criteria=UPPER%28cocrsenm%29%20LIKE%20%27BASIC%20RIDER%20COURSE%25%27&TITLE=Title%20begins%20with%20%22basic%20rider%20course%22'
#content = urllib2.urlopen(url).readlines()
#print content
r = urllib.urlopen(url).read()
#print r
soup = BeautifulSoup(r, "lxml")
table = soup.findChildren("table", {"class" : "awTable"})
table = table[0]
rows = table.findChildren("tr")
#print rows
return len(rows)
def main():
"""Summary
"""
print getCount()
if __name__ == '__main__':
main()