Advertisement
rfmonk

sapper1.py

Oct 15th, 2014
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. a twitter mining app
  5. note this requires twitter api
  6. """
  7.  
  8. import twitter
  9. import json
  10.  
  11. # these four cannot be empty
  12. CONSUMER_KEY = ''
  13. CONSUMER_SECRET = ''
  14. OAUTH_TOKEN = ''
  15. OAUTH_TOKEN_SECRET = ''
  16.  
  17. auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,
  18.         CONSUMER_KEY, CONSUMER_SECRET)
  19.  
  20. twitter_api = twitter.Twitter(auth=auth)
  21.  
  22. print twitter_api
  23.  
  24. # this is found via a yahoo api
  25. WORLD_WOE_ID = 1
  26. PH_WOE_ID = 23424934
  27.  
  28. world_trends = twitter_api.trends.place(_id=WORLD_WOE_ID)
  29. ph_trends = twitter_api.trends.place(_id=PH_WOE_ID)
  30.  
  31. world_trends_set = set ([trend['name']
  32.     for trend in world_trends[0]['trends']])
  33.  
  34. ph_trends_set = set([trend['name']
  35.     for trend in ph_trends[0]['trends']])
  36.  
  37. common_trends = world_trends_set.intersection(ph_trends_set)
  38.  
  39. print json.dumps(world_trends, indent=1)
  40. print
  41. print json.dumps(ph_trends, indent=1)
  42. print common_trends
  43.  
  44. # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement