Skip to content

Commit

Permalink
workaround for broken stocks command
Browse files Browse the repository at this point in the history
Google pulled the plug on the old API finally.  This is a workaround for now, I'm not sure how accurate it is, but I do know the opening + change != current for some reason.
  • Loading branch information
dasu committed Sep 14, 2017
1 parent 9fa8f55 commit beee6df
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,26 @@ def stocks(bot,trigger):
futurespercent = str(float("{0:.2f}".format(futures['basicQuote']['percentChange1Day'])))
return bot.say("Dow Jones Index futures: {} ({}/{}) from {}".format(futures['basicQuote']['price'], "\x0304"+futurespoints+"\x0F" if float(futurespoints) < 0 else "\x0303+"+futurespoints+"\x0F", "\x0304"+futurespercent+"%\x0F" if float(futurespercent) < 0 else "\x0303+"+futurespercent+"%\x0F", futures['basicQuote']['previousClosingPriceOneTradingDayAgo']))
else:
x = requests.get("http://finance.google.com/finance/info?client=ig&q=.DJI")
x = requests.get("https://finance.google.com/finance?q=.dji&output=json")
else:
x = requests.get("http://finance.google.com/finance/info?client=ig&q={0}".format(trigger.group(2)))
x = requests.get("https://finance.google.com/finance?q={0}&output=json".format(trigger.group(2)))
try:
data = json.loads(x.text[6:-3])
data = json.loads(x.content[6:-2].decode('unicode_escape'))
except:
return bot.say("Doesn't exist.")
if trigger.group(2):
name = data['t']
name = data['name']
else:
name = "Dow Jones Index"
if not data['lt']:
return bot.say("Doesn't exist.")
start = data['pcls_fix']
current = data['l_fix']
change = data['c_fix']
percent = data['cp_fix']
if not data.get('ec_fix'):
return bot.say("{0}: {1} ({2}/{3}) from {4}".format(name,current,"\x0304"+change+"\x0F" if float(change) < 0 else "\x0303+"+change+"\x0F","\x0304"+percent+"%\x0F" if float(percent) < 0 else "\x0303+"+percent+"%\x0F",start))
afterhourschange = data['ec_fix']
afterhourspercent = data['ecp_fix']
afterhourscurrent = data['el_fix']
bot.say("{0} after hours: {1} ({2}/{3}) from {4} ".format(name, afterhourscurrent, "\x0304"+afterhourschange+"\x0F" if float(afterhourschange) < 0 else "\x0303+"+afterhourschange+"\x0F","\x0304"+afterhourspercent+"%\x0F" if float(afterhourspercent) < 0 else "\x0303+"+afterhourspercent+"%\x0F",current))
start = data['op']
current = data['l']
change = data['c']
percent = data['cp']
return bot.say("{0}: {1} ({2}/{3}) from {4}".format(name,current,"\x0304"+change+"\x0F" if float(change) < 0 else "\x0303"+change+"\x0F","\x0304"+percent+"%\x0F" if float(percent) < 0 else "\x0303+"+percent+"%\x0F",start))
#afterhourschange = data['ec_fix']
#afterhourspercent = data['ecp_fix']
#afterhourscurrent = data['el_fix']
#bot.say("{0} after hours: {1} ({2}/{3}) from {4} ".format(name, afterhourscurrent, "\x0304"+afterhourschange+"\x0F" if float(afterhourschange) < 0 else "\x0303+"+afterhourschange+"\x0F","\x0304"+afterhourspercent+"%\x0F" if float(afterhourspercent) < 0 else "\x0303+"+afterhourspercent+"%\x0F",current))

@sopel.module.commands('futures')
def futures(bot,trigger):
Expand Down

0 comments on commit beee6df

Please sign in to comment.