Was getting bored at night due to a loss in connection while directing a Windows Phone 7 app development to my would be room mate Venky. We were trying to build a Bing maps and Twitter mashup. So thought of writing these quick codes and sharing them. The code segments below are python codes which uses the Twitter API to fetch some useful information. Sorry I don;t know .NET. The code segment also uses the Google Maps API to fetch the Geo-co-ordinates of a particular location. The code was written in a hurry. So the exceptions aren't handled. Would like to add some interesting functions to it and would like to build a Twitter API wrapper in the future, which is quiet different from some of the python wrappers already available. Sorry for the rudimentary nature of the code. Will keep all of you updated.
twitter_search.py:
This particular module contains all the codes doing the action. It can be downloaded from the following link:
http://code.google.com/p/twipy/downloads/detail?name=twitter_search.py&can=2&q=#makechanges
The code refers to, two very useful python libraries:
1. feedparser library : http://pypi.python.org/pypi/feedparser/5.0.1
2. googlemaps library : http://pypi.python.org/pypi/googlemaps/1.0.2
The results:
1. Tweets containing the word python:
import twitter_search twitter_search.get_tweets_containing_word("python")
Output:
The tweet is: Wrote a blog entry about the #python web frameworks #django and #aspen: http://t.co/Z0ylcsF
The author's name is: falstaff_ch (Stefan)
The tweet is: RT @mjabali: Track your home's live electricity usage with Python http://bit.ly/mUCNRL < That's really geeky
The author's name is: scaganoff (Saul Caganoff)
The tweet is: Hey girl let a python slide on. Stay sick, infect me, Lysol
The author's name is: willcook7 (will cook)
The tweet is: @robertcarroll I'd say "2 Guys, 1 Gun" but I'm not sure if that joke is still valid. "2 Guys, 1 Gun, and Mega Python" meh, kinda gay. #doit
The author's name is: mailorderhero (David Johnson)
The tweet is: Monty Python - Climbing the North Face of the Uxbridge Road http://fb.me/17bTgyjNB
The author's name is: boholwebmaster (Bohol Web Design)
The tweet is: RT @dozba: From the CentOS forums: "Why do you *need* a version of Python > 2.4?" What a complete joke of an operating system.
The author's name is: bluu (John Kurkowski)
The tweet is: @MsshayButta Natural style http://t.co/xuwzd6M Pumps ONLY 161 bucks:
The author's name is: Cavazos1985 (Ramiro)
2. Tweets from MATI_KI_MAMATA - unofficial
twitter_search.get_tweets_from_user("MATI_KI_MAMATA")
Output:
Tweet time is: 2011-06-22T18:04:07Z
The tweet is: Kolkata will be London, Darjeeling another Switzerland and Sundarbans African safari..MA MAT MANUSH
Tweet time is: 2011-06-21T11:16:36Z
The tweet is: RT @BUDDHADEBDEY: @MATI_KI_MAMATA JUST SUPERB.
Tweet time is: 2011-06-21T11:16:32Z
The tweet is: RT @BUDDHADEBDEY: @MATI_KI_MAMATA DIDI YOU ARE TOO GOOD & YOUR STEP IS TOO TOO GOOD.
Tweet time is: 2011-06-21T11:15:44Z
The tweet is: RT @dastapan80: @MATI_KI_MAMATA
Didi many many congrats to you for Singur land bill pass in West Bengal assembly.
Tweet time is: 2011-06-21T11:15:01Z
3. Tweets to MATI_KI_MAMATA
twitter_search.get_tweets_to_user("MATI_KI_MAMATA")
Output:
Tweet time is: 2011-06-24T05:43:39Z
The tweet is: @MATI_KI_MAMATA very very nice dream & i think it should be urgently then our west bengal will be most tourism spot from others state.
The author is: BUDDHADEBDEY (BUDDHADEBDEY)
Tweet time is: 2011-06-23T16:16:36Z
The tweet is: @MATI_KI_MAMATA: Kolkata will be London, Darjeeling another Switzerland and Sundarbans African safari..MA MAT MANUSH. Yes it can be done.
The author is: mrinalsahoo1 (mrinal sahoo)
4. Tweets referring Techcrunch:
twitter_search.get_tweets_refer_user("techcrunch")
Output:
Tweet time is: 2011-06-24T22:03:48Z
The tweet is: RT @bufferapp: In-Stream Ads Are Coming To Twitter, Will A User Revolt Follow? http://j.mp/jIe0Hs (Wow, my tweet made it to TechCrunch :)
The author is: KathyWingard (Kathy Wingard)
Tweet time is: 2011-06-24T22:02:03Z
The tweet is: In-Stream Ads Are Coming To Twitter, Will A User Revolt Follow? http://j.mp/jIe0Hs (Wow, my tweet made it to TechCrunch :)
The author is: bufferapp (Buffer)
Tweet time is: 2011-06-24T19:21:37Z
The tweet is: Spent the morning opening a small trade account - funny how much more attention you pay to TechCrunch once you have a position...
The author is: exswoo (WooJin Lee)
Tweet time is: 2011-06-24T19:20:46Z
The tweet is: TechCrunch Giveaway: Free Tickets To @techcrunch 6th Annual Summer Party At August Capital #tcaugustcapital http://t.co/x64SRBl
The author is: beautyfoodie (Gina)
Tweet time is: 2011-06-24T19:15:25Z
The tweet is: Can someone donate 30 minutes of coding to @TechCrunch to make their website usable? I'm drowning in mismanaged widgets (~_~;)
The author is: andruflockhart (Andrew Flockhart)
Tweet time is: 2011-06-24T18:29:14Z
The tweet is: Win tickets to @TechCrunch's 6th Annual Summer Party at August Capital! #tcaugustcapital http://t.co/KXelqd3
The author is: kim617 (Kim Pham)
Tweet time is: 2011-06-24T18:23:13Z
The tweet is: RT @mirandagale: So, 2.5 USAs? Whoah. RT @davefleet Facebook now has 750 million users according to TechCrunch http://t.co/MOjNfFQ (via @jangles)
The author is: alexpriest (Alex Priest)
Tweet time is: 2011-06-24T18:20:24Z
The tweet is: RT @jangles: Facebook now has 750 million users according to TechCrunch http://tcrn.ch/kRllyD
The author is: BenjaminRupert (Ben West)
Tweet time is: 2011-06-24T18:11:35Z
The tweet is: RT @davefleet: Facebook now has 750 million users according to TechCrunch http://tcrn.ch/kRllyD (via @jangles)
The author is: mic911 (Paul McAllister)
Tweet time is: 2011-06-24T17:42:13Z
The tweet is: Who remembers which services he/she is subscribed to? @TechCrunch: Now You Can Unsubscribe.com From Social Apps Too http://tcrn.ch/ktBxpn
The author is: petermaleh (Peter Maleh)
Tweet time is: 2011-06-24T17:19:54Z
The tweet is: Facebook now has 750 million users according to TechCrunch
The author is: blablablapr (Abdul Aleem)
Tweet time is: 2011-06-24T17:19:28Z
The tweet is: #FF to @TechCrunch @thetecheye and @Wired because...well, you know why you need to follow them :)
The author is: elpady (Javier Padilla)
Tweet time is: 2011-06-24T17:18:02Z
The tweet is: RT @jangles: Facebook now has 750 million users according to TechCrunch http://tcrn.ch/kRllyD
The author is: chigorodo (Kathy Osorio)
Tweet time is: 2011-06-24T17:14:29Z
The tweet is: So, 2.5 USAs? Whoah. RT @davefleet Facebook now has 750 million users according to TechCrunch http://t.co/MOjNfFQ (via @jangles)
The author is: mirandagale (Miranda Gale)
Tweet time is: 2011-06-24T17:13:33Z
The tweet is: RT @davefleet: Facebook now has 750 million users according to TechCrunch http://tcrn.ch/kRllyD (via @jangles)
The author is: elliottchun (Elliott Chun)
5. Tweets containing the hashtag: #python
twitter_search.get_tweets_contain_hashtag("python")
Output:
Tweet time is: 2011-06-24T22:39:08Z
The tweet is: Glad I never spent too long getting my Python script to work (or not, as is the case) http://bit.ly/mlpOTk
The author is: kylegordon (Kyle Gordon)
Tweet time is: 2011-06-24T22:38:42Z
The tweet is: 2 miles down 4 to go. Python is on the path for success! http://t.co/vXZD3Wh
The author is: jsmooth788 (Justin Susanjar)
Tweet time is: 2011-06-24T22:37:59Z
The tweet is: RT @AmazonVideo: Nudge, nudge: instant streaming of "Monty Python's Flying Circus" is now included with Amazon Prime. http://amzn.to/l56ifH
The author is: Mechachrome (Jason Hennigan)
Tweet time is: 2011-06-24T22:32:07Z
The tweet is: How to make Python 2.x Unicode strings not print as u'string'? http://bit.ly/jKmlfx
The author is: pythonatso (PythonAtSO)
Tweet time is: 2011-06-24T22:31:13Z
The tweet is: We're giving away a pair of Season Tickets to the 2011 - 2012 Broadway Series featuring Monty Python's SPAMALOT and more: http://ow.ly/5pYnj
The author is: BwayInSaginaw (Broadway In Saginaw)
Tweet time is: 2011-06-24T22:22:16Z
The tweet is: I'm tired about people who doesn't know how to draw a cube and keep saying that Python is slow.
The author is: ChicOrtiz (Francisco Ortiz)
Tweet time is: 2011-06-24T22:22:12Z
The tweet is: RT @AmazonVideo: Nudge, nudge: instant streaming of "Monty Python's Flying Circus" is now included with Amazon Prime. http://amzn.to/l56ifH
The author is: nethead (Nethead)
6. What are the people tweeting at M.I.T , USA-------this one is ineteresting. u can try even with ur home address :) or may be your college address to find out the guys tweeting about your Girl Friend ;)
twitter_search.get_tweets_from_location("M.I.T,U.S.A")
Output:
Tweet time is: 2011-06-24T22:42:26Z
The tweet is: http://t.co/PVsEthj participem
The author is: Alisson_105 (AL1S5ON 105)
Tweet time is: 2011-06-24T22:41:43Z
The tweet is: Out of curiosity - how many people would be interested to know more about native API access on Dell Venue Pro? #wp7 #wp7dev #wpdev
The author is: DennisCode (Den Delimarsky)
Tweet time is: 2011-06-24T22:29:04Z
The tweet is: #tropicalsno
The author is: jwalt10 (Jamie Walton)
Tweet time is: 2011-06-24T22:28:51Z
The tweet is: Meteor Man!
The author is: JSteveATC (James M. Stephens II)
Tweet time is: 2011-06-24T22:06:47Z
The tweet is: Fair and 96 F at Coffeyville Municipal Airport, KS Winds are South at 15.0 MPH (13 KT). The pressure is 1006.6 mb and t http://s2z.us/ns.htm
The author is: Coffeyville_WX (Coffeyville Weather)
Tweet time is: 2011-06-24T22:05:02Z
The tweet is: @JessRMyers j-e-t-s, jets,jets, jets!!
The author is: davidcole69 (david cole)
Tweet time is: 2011-06-24T22:02:48Z
The tweet is: Me to cool operations manager at work: "Does your wife make you drive the mini-van so it will be impossible for you to cheat on her?"
The author is: Brain_Of_Brian (Brian Eubanks)
Tweet time is: 2011-06-24T22:00:15Z
The tweet is: Sit back & watch while I do my thang!
#letmeshowyou
The author is: SexylegsSheek (Spryng Wilson)
Tweet time is: 2011-06-24T21:54:43Z
The tweet is: @allexsmainchick. Damn rite its hot Lol dats a song!
The author is: SexylegsSheek (Spryng Wilson)
Tweet time is: 2011-06-24T21:47:46Z
The tweet is: Upper New York Annual Conference: One year following its creation, the Upper New York annual conference held its... http://bit.ly/jbg4Tj
The author is: Liam_OHanrahan (Liam O'Hanrahan)
Tweet time is: 2011-06-24T21:29:22Z
The tweet is: ECUACIÓN MATEMÁTICA CONCLUYE QUE EL 24 DE JUNIO ES EL DÍA MÁS FELIZ DEL 2011: http://bit.ly/j13ofm
The author is: denissecarrion1 (Denisse Carrión)
Tweet time is: 2011-06-24T21:29:22Z
The tweet is: ECUACIÓN MATEMÁTICA CONCLUYE QUE EL 24 DE JUNIO ES EL DÍA MÁS FELIZ DEL 2011: http://bit.ly/j13ofm
The author is: Coatzadigital (Coatza Digital)
Tweet time is: 2011-06-24T21:11:38Z
The tweet is: The Real Reason Why Steve Carrel Left The Office http://t.co/r8AVaOU
The author is: Brain_Of_Brian (Brian Eubanks)
Tweet time is: 2011-06-24T21:06:02Z
The tweet is: Fair and 95 F at Coffeyville Municipal Airport, KS Winds are from the South at 12.7 gusting to 19.6 MPH (11 gusting to http://s2z.us/ns.htm
The author is: Coffeyville_WX (Coffeyville Weather)
Tweet time is: 2011-06-24T21:02:56Z
The tweet is: Kks
The author is: death_ridder90 (tom waddle)
Looking forward to come up with a lot of things......
No comments:
Post a Comment