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
2 changes: 2 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def eval(cmd, input=None):
return wordOfTheDay.eval()
elif cmd['service'] == 'MBTA':
return MBTA.eval(cmd['args'])
elif cmd['service'] == 'H': ##Crimson headlines
return headlines.eval()
else:
return "ERROR 42: service not recognized"

Expand Down
1 change: 1 addition & 0 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
{'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': 'D', 'args':{}, 'tags':['WORDOFTHEDAY']},
{'service': 'H', 'args':{}, 'tags':['HEADLINES']},
{'service': 'MBTA', 'args': {'pg': ['green/lake']}, 'tags': ['MBTA', 'SUBWAY', 'T', 'SCHEDULE', 'LINE', 'GREEN', 'COLLEGE', 'BOSTON']},
{'service': 'MBTA', 'args': {'pg': ['green/sougr']}, 'tags': ['MBTA', 'SUBWAY', 'T', 'SCHEDULE', 'LINE', 'ST', 'STREET', 'SOUTH', 'GREEN']},
{'service': 'MBTA', 'args': {'pg': ['green/chill']}, 'tags': ['MBTA', 'SUBWAY', 'T', 'SCHEDULE', 'LINE', 'HILL', 'AVE', 'GREEN', 'CHESTNUT']},
Expand Down
1 change: 1 addition & 0 deletions services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from weather import weather
from wordOfTheDay import wordOfTheDay
from MBTA import MBTA
from headlines import headlines
Empty file added services/headlines/__init__.py
Empty file.
42 changes: 42 additions & 0 deletions services/headlines/headlines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import urllib2, urllib
import re
from bs4 import BeautifulSoup

#####################################
## Crimson Headlines Function ##
#####################################

def getHeadlines():
url = 'https://www.thecrimson.com/'
hdr = {'User-Agent': 'Chrome'}
req = urllib2.Request(url,headers=hdr)
website = urllib2.urlopen(req)
soup = BeautifulSoup(website.read(), 'html.parser')
msg = "The 5 most read Crimson articles:\n"

try:
headlines = soup.find("div", {"id": "most-read-box"})
for li in headlines.find_all('li'):
link = li.find('a')
msg += link.get_text()+ " " + "https://www.thecrimson.com" + link['href']+ " "


except Exception, e:
print str(e)
return "Could not find headline data."

return msg

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

def makeSpecial():
s = 'This will get the top Crimson headlines.'
return s

## return proper format
special = makeSpecial()

def eval():
return getHeadlines()