Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import simplejson, httplib2, BeautifulSoup, urllib
- h = httplib2.Http()
- h.add_credentials('randomdev8d','felpo4242')
- search = httplib2.Http()
- from time import sleep
- import pickle, os
- if os.path.exists('people'):
- p = open('people', 'rb')
- people = pickle.load(p)
- p.close()
- else:
- people = {}
- """ e.g. "text":"#dev8D @dev8d survey: Win7\/Laptop","to_user_id":null,"from_user":"alexwade","id":1202175487,"from_user_id":4737001,"iso_language_code":"fr","profile_image_url":"http:\/\/static.twitter.com\/images\/default_profile_normal.png","created_at":"Thu, 12 Feb 2009 10:04:25 +0000"}
- """
- def get_results(text):
- if text and isinstance(text, basestring):
- tokens = text.split(' ')
- results = []
- for token in tokens:
- token = token.lower()
- spl = token.split('/')
- if len(spl) == 2:
- if spl[1].startswith('laptop'):
- results.append((spl[0], 'laptop'))
- elif spl[1].startswith('netbook'):
- results.append((spl[0], 'netbook'))
- elif spl[1].startswith('ec2') or spl[1].startswith('amazon'):
- results.append((spl[0], 'amazonEC2'))
- elif spl[1].startswith('iphone'):
- results.append((spl[0], 'iphone'))
- elif spl[1].startswith('mac'):
- results.append((spl[0], spl[1]))
- return results
- def stats():
- os = {}
- hw = {}
- for person in people:
- for item in people[person]:
- if os.has_key(item[0]):
- os[item[0]] = os[item[0]] + 1
- else:
- os[item[0]] = 1
- if hw.has_key(item[1]):
- hw[item[1]] = hw[item[1]] + 1
- else:
- hw[item[1]] = 1
- return (os, hw)
- while True:
- print "Checking surveys"
- (resp, content) = search.request('http://search.twitter.com/search.json?rpp=99&q=dev8D+OR+dev8dsurvey')
- doc = simplejson.loads(content.decode('utf-8'))
- for item in doc['results']:
- user = item['from_user']
- if not (user == 'randomdev8d'):
- text = item['text']
- results = get_results(text)
- if people.has_key(user):
- for res in results:
- people[user].add(res)
- else:
- people[user] = set(results)
- packet = stats()
- p = open('people', 'wb')
- pickle.dump(people, p)
- p.close()
- st = ["#dev8d tallys: OSs"]
- for k in packet[0]:
- st.append("%s:%s" % (k,packet[0][k]))
- hwst = ["#dev8d tallys: HW"]
- for k in packet[1]:
- hwst.append("%s:%s" % (k,packet[1][k]))
- body = urllib.urlencode({'status':", ".join(st)})
- (rs,cont) = h.request('http://www.twitter.com/statuses/update.json', "POST", body=body)
- sleep(20)
- body = urllib.urlencode({'status':", ".join(hwst)})
- (rs,cont) = h.request('http://www.twitter.com/statuses/update.json', "POST", body=body)
- sleep(1440)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement