Permalink
Browse files

tweet to histogram

  • Loading branch information...
satojkovic committed Apr 22, 2012
1 parent dc4cc0c commit 0be6a2be5b5be14010c5793973b58713b6a8e38b
Showing with 34 additions and 0 deletions.
  1. +34 −0 tweet2hist.py
View
@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+import matplotlib.pyplot as plt
+import twitter
+from pit import Pit
+import re
+import numpy as np
+
+config = Pit.get('twitter.com', {'require':
+ {'ConsumerKey':",'ConsumerSecret':",
+ 'AccessToken':",'AccessTokenSecret':"}})
+
+api = twitter.Api(config['ConsumerKey'], config['ConsumerSecret'],
+ config['AccessToken'], config['AccessTokenSecret'])
+
+statuses = api.GetSearch(term='withings', per_page=100, page=25)
+
+data = []
+p = re.compile('(My weight|u"体重"): ([0-9\.]+) (lb|kg)')
+for status in statuses:
+ m = p.match(status.text)
+ if m:
+ if m.group(3) == 'lb':
+ data.append(float(m.group(2))*0.4536)
+ else:
+ data.append(float(m.group(2)))
+
+ary = np.asarray(data)
+fig = plt.figure(1)
+plt.subplot(111)
+plt.axis([40,160,0,5])
+plt.grid(True)
+plt.hist(ary, 100)
+plt.show()
+

0 comments on commit 0be6a2b

Please sign in to comment.