Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib
- import urllib2
- from cookielib import CookieJar
- import re
- #
- # stock script
- #
- cookies = {}
- def login(username, password):
- cj = CookieJar()
- opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
- opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1')]
- urllib2.install_opener(opener)
- urllib2.urlopen(urllib2.Request(
- "http://tptapi.com/login_proc.php?login",
- urllib.urlencode({"Username":username, "Password":password})))
- for i in list(cj):
- cookies[i.name] = i.value
- def getPage(url):
- return urllib2.urlopen(urllib2.Request(url, urllib.urlencode(cookies))).read()
- results = {}
- def getStockInfo(page):
- stocks = []
- for i in page.splitlines():
- stocks.extend(re.findall("<td width='\d+%'>([^<>]*)</td>", i))
- for i in range(0, len(stocks), 4):
- results[stocks[i]] = {'name':stocks[i], 'value':stocks[i+1], 'shares':stocks[i+2], 'ceo':stocks[i+3]}
- def printStockInfo(text, user, server, channel):
- output = ""
- for i in results:
- output = output + i + " - $" + results[i]["value"] + " 08"
- #print i + " - $" + results[i]["value"] + " " + results[i]["shares"] + " shares. CEO: " + results[i]["ceo"]
- send(["msg " + channel + " " + output, server, channel])
- def stockInfo(text, user, server, channel):
- getStockInfo(getPage("http://tptapi.com/getstock.php"))
- if text[1] in results:
- send(["msg " + channel + " " + results[text[1]]["value"], server, channel])
- #
- #insert random hexchat related stuff here
- #somewhere in main:
- #
- if command == "!!login":
- login("jacob2", "<insert password here>") #cookies are saved to a pref file in my script
- elif command == "!!stock":
- stockInfo(text, user, server, channel) #get info on just one stock
- elif command == "!!print":
- printStockInfo(text, user, server, channel) #print all info. doesn't get the info first though ...
Advertisement
Add Comment
Please, Sign In to add comment