Friday, June 24, 2011

Python twitter search api

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......








Enhanced by Zemanta

Wednesday, June 22, 2011

Python Video Tutorials

Here is a list of python video tutorials that introduces Python language and shows how to use PyDev editor along with Eclipse:

1. Introduction




2. Lists and Tuples





3. Dictionaries and Strings



4. If and Else





5. While and for loop



6. Functions



7. Object Oriented Programming Part-I



8. Object Oriented Programming Part-II

Sunday, June 19, 2011

Greedy for Cakes


Who doesn't love cakes. They are just yummy! But if you put some maths in it........, results may not be that much yummy. That's the case for the following puzzles taken from a book entitled , "Puzzles for Programmers"


Puzzle 1: Two children, perhaps similar to ones you know, love cake and mathematics. For this reason, Jeremy convinces Marie to play the following game on two identical rectangular cakes chef Martine has prepared for them.

Jeremy will cut the first cake into two pieces, perhaps evenly, perhaps not. After seeing the cut, Marie will decide whether she will choose first or allow Jeremy to do so. If she goes first, she will take the larger piece. If she goes second, she can assume that Jeremy will take the larger piece.

Next, Jeremy will cut the second cake into two pieces (remember that one of the pieces can be vanishingly small if he so chooses). If Marie had chosen first for the first cake, then Jeremy gets to take the larger piece of the second cake. If Marie had chosen second for the first cake, then she gets to take the larger piece of the second cake.

Assuming each child will strive to get the most total cake possible, what is an optimal strategy for Jeremy?

Answers??? ----Wait for the next post.

Enhanced by Zemanta

Saturday, June 18, 2011

Walking in "The Cloud"



"I just have a month's subscription left. So I need to recharge my Cloud Service. I just have to switch on my terminal and log into my account for extending my subscription. It will take just few seconds and that's all, and it comes at a very nominal rate, with most of its services free of cost and a plethora of apps to choose from. It's really awesome. I have recently turned into a developer and I need to host my apps. So I will require few more services than the normal users. Sometimes I even get money for those cool apps that I make. I feel really great when millions of users use my app and its so easy to host them these days. I just need to register and sign in. I don't even need to worry about maintaining it. I am no computer geek, but I do have a cool website and make plenty of cool apps just by drag and drop. Ah! its such a beautiful world. I love walking in the cloud. These days I don't have to manage so many accounts in Facebook, Orkut, MySpace. I just have a single account registered with my Cloud Service provider and it allows me to manage all from there. Each one of us have a public profile in the cloud as if everyone of us is a separate entity with a key to distinguish ourselves from one another. So whenever I need to mention any of my friend or someone in the cloud while writing my status updates , or my blog , or while making my presentations and docs, the cloud just detects it and provides a link to his/her public profile. It also gives me recommendations of his/her works available in the cloud. The cloud is so intelligent. I call it the Genie.What's more......its not just people , everything right from places to cars and the laptop that I use are separate entities these days. It has an amazing visualization capability. I just click , and it visualizes my entire network with all the familiar profile pics. I see them everyday on my big LED display. Whenever I become curious to know about anyone's current status i just keep my finger on his/her node and it shows me the status summary. I can do the same from my mobile, from my laptop and also from my ipad. They just act like windows, and whenever I open these windows, the Genie is waiting outside to serve me. I just provide my wish list to him and he grants every one of them. So that's how it is in 2020."




That's not just me, it's going to be any commoner talking like that in 2020.It seems to be a dream today, but fortunately it's going to be "the reality" in the future. It's the dawn of Web 3.0, Semantic Web, The Cloud, The Genie or whatever fancy term we use for it, and it has arrived with all its potential to unleash itself and spread itself among the common masses. It was the computers that got linked to one another in early days of the internet. Then the web had pages which got linked to one another. Now, these pages have immense amount of data. With the dawn of the Web 3.0 , its time for these data to get linked. What’s more interesting is that these data are about the users of the web and the things about which they write and discuss on the web. The amount of information available from these data will help in disambiguating these people and the things which they talk about making each one of them a separate entity. With this huge amount of linked data available, the future is going to see a new platform which will be more intelligent than what we can imagine today, taking the virtual society of the web more towards the realistic society and making the modern society fully dependent on it.Living in the cloud would be like living in the bits. We talked about the atoms and molecules as the constituents of the living society. Now its going to be the bits, the new constituents of the virtual living society. We are going to be wired up by the bits. It will be a society of data, and the world is going to be a huge cloud of linked data.



It will be available to everyone as a service, just like we have our mobile phone service with prepaid and post paid schemes. The devices, TV, Laptops, ipads, phones ........all of them will just be windows to it. Soon the web will encompass the whole population of the world , as Kevin Kelly , the founding executive editor of the Wired magazine puts it in his famous TED talk [10] - “There is only one machine. The web is its OS. All screens look into the One. No bits will live outside the web. To share is to gain. Let the One read it. The One is us”










Enhanced by Zemanta