Monday, May 11, 2009

Ice Cream Hair Dye Without Oxidizing

# chingasatumadre

The whole story, the voice of The Leader Movement, here. If

were permitted marriage between men and twitter accounts, I would marry the Lilian.

Finally, we needed to know who tweeted the hashtag (so called to be preceded by a # Words do ... is like a "marker" of the item in your twit) # chingasatumadre.

Well, you can search in the search hashtag twitter:



And then review each outcome, by hand, over a million years.

NOT!

This is a job for Python!

(From here, the post gets technical. Plenty. Flee while you can).

Step 1, look for the Twitter API: An API is ... as a series of instructions that the manufacturer or supplier of "something" gives you so you can control the "something" automatically from a program. Twitter is a (In those days, what "network" does not?): http://apiwiki.twitter.com

Step 2, look for the Python library to interact with the API: Using twitter API is half a mess. You need to visit certain Internet addresses, with the appropriate parameters for the "page" they will give you the results you want to be seen. Done from Python (my preferred programming language) is half a mess. Sure, I could write a small library of functions who abstracted this functionality, but ... Surely someone had already done. And yes, I found this gem: http://mike.verdone.ca/twitter/ .

Step 3, the program itself: The task is simple: Find all tweets that mention "# chingasatumadre" and make a list, without repetitions, of the users responsible. Easily solved with the following:

  # coding: utf-8  

# The library to use the Twitter API from
import twitter Twitter

# indicates that only use the functionality of Search
# (To avoid loguearnos).
t_s = Twitter ( domain = 'search.twitter.com' )

# Create a "set" to store users. A set
# does not support reps.
users = September ( )

# Small "cheat" to "compensate" the absence of do ... while in
# Python
results = 100
p = 1

# As long as one hundred results page
results while = = 100 :
p # Takes page of results (with a maximum of 100 per
# page) Search chingas # chingasatumadre
= t_s . Search (q = '# chingasatumadre' , rpg = 100 , page + p = 1)
# Get a list of user names of those twits.
= users [ Chin [ 'from_user' ] for chin in chingas [ 'results' ] ]
# Add them to all users (eliminating repetitions).
users. Update ( users)
# How many results were on this page?
results len = ( users)
# Advance the page number.
+ p = 1

# Finally, print the user names, each on one line,
# ignoring case.
print '\\ n' . join (sorted ( users , key = unicode . lower ) )


UPDATE: Error! p must be zero before the cycle. Sorry to those left out by my uselessness.

Step 4, the list Lilián Passing: Very easy, go to a pastebin service (as http://pastebin.com/ ) where we can paste any text and make it publicly available for some time. Very useful when you need help to fix a program, and I want to teach someone else on the Internet.

Voila! Kids, try it at home. Become addicted, and never do anything by hand again.

0 comments:

Post a Comment