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['stock'] == 'M':
return stock.eval(input)
else:
return "ERROR 42: service not recognized"

Expand All @@ -33,6 +35,8 @@ def special(incoming):
body = laundry.special
elif incoming.upper() == "WEATHER":
body = weather.special
elif incoming.upper() == "STOCK":
body = stock.special
elif incoming.upper() == "DEMO":
## welcome/instructions
body = 'Thanks for using Harvard Now!\n'
Expand All @@ -45,6 +49,7 @@ def special(incoming):
body += 'Sending part of a name gives all information associated with that name.\n'
body += 'For example sending Quad will give information about the shuttle stop Quad and the shuttle'
body += 'route Quad Yard Express and sending Quincy laundry will give all the laundry rooms in Quincy.\n'
body += 'If you want to snag it, type in a stock symbol. Thanks!\n'
return body

## main function
Expand Down
1 change: 1 addition & 0 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,5 @@
{'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']}
{'serivce': 'M', 'args':{}, 'tags':['STOCK']}
]
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 stock import stock
Empty file added services/stock/__init__.py
Empty file.
42 changes: 42 additions & 0 deletions services/stock/stock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import urllib2, urllib
import re
from bs4 import BeautifulSoup

#############################
## Stock Function ##
#############################

def getStockData(input):
url = 'https://finance.google.com/finance?q='
url += input
hdr = {'User-Agent': 'Chrome'}
req = urllib2.Request(url,headers=hdr)
website = urllib2.urlopen(req)
soup = BeautifulSoup(website.read(), 'html.parser')

try:
card = soup.find("div", {"id":"price-panel"}).find("span").find("span").string

card = '$' + card

return card

except Exception, e:
print str(e)
return "Could not find stock data. Are you sure you gave a proper stock symbol?"

#return body

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

def makeSpecial():
s = 'To get the stock, type in the stock symbol.'
return s

## return proper format to use for getting weather
special = makeSpecial()

def eval(input):
return getStockData(input)
Binary file added services/stock/stock.pyc
Binary file not shown.