Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def eval(cmd, input=None):
return shuttle.eval(cmd['args'])
elif cmd['service'] == 'W': ## Weather
return weather.eval(input)
elif cmd['service'] == 'C': ## Crimson
return crimson.eval()
else:
return "ERROR 42: service not recognized"

Expand All @@ -33,12 +35,15 @@ def special(incoming):
body = laundry.special
elif incoming.upper() == "WEATHER":
body = weather.special
elif incoming.upper() == "CRIMSON":
body = crimson.special
elif incoming.upper() == "DEMO":
## welcome/instructions
body = 'Thanks for using Harvard Now!\n'
body += 'Laundry Information is accessed by sending the name of your laundry room\n'
body += 'e.g. Lowell D\n'
body += 'For a list of all laundry rooms send laundry\n\n'
body += 'For a list of current Crimson headlines and links to them, send \"Crimson\"\n'
body += 'To access shuttle information send the name of the stop or name of the route\n'
body += 'e.g. Widener Gate; Quad Yard Express\n'
body += 'For a list of all shuttle stops and routes send shuttle\n\n'
Expand Down
3 changes: 2 additions & 1 deletion data.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,6 @@
{'service': 'S', 'args':{'endpoint': 'route', 'routeid': '4007272' , 'label': 'Barry\'s Corner Shuttle Route'}, 'tags':["BARRY'S",'BARRY', 'CORNER', 'SHUTTLE', 'ROUTE']},
{'service': 'S', 'args':{'endpoint': 'route', 'routeid': '4007610' , 'label': 'Quad Stadium Express Shuttle Route'}, 'tags':['QUAD', 'STADIUM', 'EXPRESS', 'SHUTTLE', 'ROUTE']},
{'service': 'S', 'args':{'endpoint': 'route', 'routeid': '4007650' , 'label': 'Allston Campus Express Shuttle Route'}, 'tags':['ALLSTON', 'CAMPUS', 'EXPRESS', 'SHUTTLE', 'ROUTE']},
{'service': 'W', 'args':{}, 'tags':['WEATHER']}
{'service': 'W', 'args':{}, 'tags':['WEATHER']},
{'service': 'C', 'args':{}, 'tags':['CRIMSON']}
]
1 change: 1 addition & 0 deletions services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from laundry import laundry
from shuttle import shuttle
from weather import weather
from crimson import crimson
Empty file added services/crimson/__init__.py
Empty file.
41 changes: 41 additions & 0 deletions services/crimson/crimson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import urllib2, urllib
from bs4 import BeautifulSoup
import data

#############################
## Crimson Function ##
#############################

def getHeadlines():
headlines = []
website = urllib2.urlopen('http://www.thecrimson.com')
soup = BeautifulSoup(website.read(), 'html.parser')
headline_divs = soup.find_all("div", {"class" : "article-content"})

# return at most 7 headlines/articles
while len(headline_divs) > 7:
del headline_divs[-1]
for headline_div in headline_divs:
headline_words = headline_div.a.string
headline_link = "http://www.thecrimson.com" + headline_div.a['href']
s = headline_words + ": " + headline_link
headlines.append(s)

return headlines


############################
## Top-Level ##
############################

def makeSpecial():
s = "Crimson headlines today:\n"
headlines = getHeadlines()
s += '\n'.join([headline for headline in headlines])
return s

## return headlines
special = makeSpecial()

def eval():
return makeSpecial();