Merge branch 'develop' into refresh
This commit is contained in:
commit
a41eb47551
2 changed files with 22 additions and 34 deletions
|
@ -53,8 +53,7 @@
|
||||||
"wunderground": "",
|
"wunderground": "",
|
||||||
"googletranslate": "",
|
"googletranslate": "",
|
||||||
"rdio_key": "",
|
"rdio_key": "",
|
||||||
"rdio_secret": "",
|
"rdio_secret": ""
|
||||||
"steam_key": ""
|
|
||||||
},
|
},
|
||||||
"disabled_plugins": []
|
"disabled_plugins": []
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +1,37 @@
|
||||||
|
import random
|
||||||
|
|
||||||
from util import hook, http
|
from util import hook, http
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
url = 'http://www.google.com/ig/api'
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command
|
@hook.command
|
||||||
def stock(inp):
|
def stock(inp):
|
||||||
"""stock <symbol> -- Gets information about stock symbol <symbol>."""
|
""".stock <symbol> -- gets stock information"""
|
||||||
|
|
||||||
parsed = http.get_xml(url, stock=inp)
|
url = ('http://query.yahooapis.com/v1/public/yql?format=json&'
|
||||||
|
'env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys')
|
||||||
|
|
||||||
if len(parsed) != 1:
|
parsed = http.get_json(url, q='select * from yahoo.finance.quote '
|
||||||
return "error getting stock info"
|
'where symbol in ("%s")' % inp) # heh, SQLI
|
||||||
|
|
||||||
# Stuff the results in a dict for easy string formatting
|
quote = parsed['query']['results']['quote']
|
||||||
results = dict((el.tag, el.attrib['data'])
|
|
||||||
for el in parsed.xpath('//finance/*'))
|
|
||||||
|
|
||||||
# if we dont get a company name back, the symbol doesn't match a company
|
# if we dont get a company name back, the symbol doesn't match a company
|
||||||
if not "company" in results:
|
if quote['Change'] is None:
|
||||||
guess_data = json.loads(http.get("http://d.yimg.com/autoc.finance.yahoo.com/autoc", query=inp,
|
return "unknown ticker symbol %s" % inp
|
||||||
callback="YAHOO.Finance.SymbolSuggest.ssCallback")[39:-1])
|
|
||||||
guess = guess_data['ResultSet']['Result']
|
|
||||||
if len(guess) > 0:
|
|
||||||
guess = guess[0]["symbol"]
|
|
||||||
return stock(guess)
|
|
||||||
else:
|
|
||||||
return "error: unable to get stock info for '{}'".format(inp)
|
|
||||||
|
|
||||||
if results['last'] == '0.00':
|
change = float(quote['Change'])
|
||||||
return "%(company)s - last known stock value was 0.00 %(currency)s" \
|
price = float(quote['LastTradePriceOnly'])
|
||||||
" as of %(trade_timestamp)s" % results
|
|
||||||
|
|
||||||
if results['change'][0] == '-':
|
if change < 0:
|
||||||
results['color'] = "5"
|
quote['color'] = "5"
|
||||||
else:
|
else:
|
||||||
results['color'] = "3"
|
quote['color'] = "3"
|
||||||
|
|
||||||
ret = "%(company)s - %(last)s %(currency)s " \
|
quote['PercentChange'] = 100 * change / (price - change)
|
||||||
"\x03%(color)s%(change)s (%(perc_change)s%%)\x03 " \
|
|
||||||
"as of %(trade_timestamp)s" % results
|
|
||||||
|
|
||||||
if results['delay'] != '0':
|
ret = "%(Name)s - %(LastTradePriceOnly)s " \
|
||||||
ret += " (delayed %s minutes)" % results['delay']
|
"\x03%(color)s%(Change)s (%(PercentChange).2f%%)\x03 " \
|
||||||
|
"Day Range: %(DaysRange)s " \
|
||||||
|
"MCAP: %(MarketCapitalization)s" % quote
|
||||||
|
|
||||||
return ret
|
return ret
|
Reference in a new issue