Acquired from >>
http://nbviewer.ipython.org/urls/raw.github.com/sanand0/ipython-notebooks/master/Office.ipynb
I have to try this:
Live tweeting
Just for kicks, let’s use PowerPoint as a dashboard to show live tweets.
I picked TwitterAPI to get streaming results, but twython and Python Twitter Tools look fine too.
In [13]:from TwitterAPI import TwitterAPI # I'm keeping my keys and secrets in a secret file. from secret_twitter import consumer_key, consumer_secret, access_token_key, access_token_secret api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)This function will draw a tweet in a reasonably nice way on a slide. There’s a block each for the profile picture, the text of the tweet, and the name of the user.
In [16]:def draw_tweet(Base, item, pos): y = 40 + (pos % 4) * 120 image = Base.Shapes.AddPicture( # To get the larger resolution image, just remove _normal from the URL item['user']['profile_image_url'].replace('_normal', ''), LinkToFile=True, SaveWithDocument=False, Left=20, Top=y, Width=100, Height=100) try: status = item['text'].encode('cp1252') except UnicodeEncodeError: status = item['text'] text = Base.Shapes.AddShape(msoShapeRectangle, 130, y, 460, 100) text.Fill.ForeColor.ObjectThemeColor = msoThemeColorText1 text.Fill.ForeColor.Brightness = +0.95 text.Line.Visible = msoFalse text.TextFrame.TextRange.Text = status text.TextFrame.TextRange.Font.Color.ObjectThemeColor = msoThemeColorText1 text.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignLeft user = Base.Shapes.AddShape(msoShapeRectangle, 600, y, 100, 100) user.Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent6 user.Line.Visible = False user.TextFrame.TextRange.Text = '@' + item['user']['screen_name']Let’s track requests for specific words, and see what we get.
In [17]:Base = Presentation.Slides.Add(1, ppLayoutBlank) api.request('statuses/filter', {'track': 'beer'}) for pos, item in enumerate(api.get_iterator()): draw_tweet(Base, item, pos) if pos > 10: break