Skip to content

Instantly share code, notes, and snippets.

@bwesterb
Created July 3, 2013 21:49
Show Gist options
  • Save bwesterb/5923156 to your computer and use it in GitHub Desktop.
Save bwesterb/5923156 to your computer and use it in GitHub Desktop.
import os
import urllib2
import socket
from bs4 import BeautifulSoup
def teespring_amount_ordered(what):
html = urllib2.urlopen('http://teespring.com/'+what).read()
soup = BeautifulSoup(html)
return int(soup.find(attrs={'class': 'amount-ordered'}).text)
def irc_message(host, port, nick, realname, chan, msg):
s = socket.socket()
s.connect((host, port))
s.send('USER %s 0 * : %s\r\n' % (nick, realname))
s.send('NICK %s\r\n' % nick)
f = s.makefile()
for line in f:
line = line[:-1]
if line.startswith('PING'):
s.send(line.replace('PING', 'PONG') + '\r\n')
if not line.startswith(':'):
continue
bits = line.split(' ')
if len(bits) >= 2 and bits[1] == '001':
s.send('MODE %s +B\r\n' % nick)
s.send('JOIN %s\r\n' % chan)
s.send('PRIVMSG %s :%s\r\n' % (chan, msg))
break
def read_status(status_file):
if not os.path.exists(status_file):
return -1
with open(status_file, 'r') as f:
return int(f.read())
def write_status(status_file, status):
with open(status_file, 'w') as f:
f.write(str(status))
if __name__ == '__main__':
status_file = 'status'
campaign = 'forscience'
old = read_status(status_file)
new = teespring_amount_ordered(campaign)
if old != new:
write_status(status_file, new)
irc_message('irc.kassala.de', 6667, 'TeeSpringBot', 'bwesterb',
'#test', 'ZOMG: %s tee\'s' % new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment