-
-
Save valpackett/548282 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # If you've just missed your 12345th tweet.. | |
| # Getting it, the Python one-line way ^^ | |
| # By myfreeweb <[email protected]>. | |
| # Follow me on Twitter: @myfreeweb in English, @myfreeweb_ru in Russian. | |
| import json | |
| import urllib2 | |
| # Imports don't count! | |
| # We get 12344th tweet because Python counts from 0 and Twitter - from 1. Twitter loves humans :D | |
| print json.loads(urllib2.urlopen('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=myfreeweb&count=200').read())[json.loads(urllib2.urlopen('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=myfreeweb&count=2').read())[0]['user']['statuses_count']-12344] | |
| # Note the "count=2" in the second request. Twitter returns nothing when you pass it "count=1". | |
| # Stupid Ruby? Stupid Rails? Or stupid Twitter developers?? No, maybe they just love humans way too much... | |
| # We need to do 2 requests only because I wanted to do it in one line. Smth like this is possible: | |
| spam = json.loads(urllib2.urlopen('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=myfreeweb&count=200').read()) | |
| print spam[spam[0]['user']['statuses_count']-12344] | |
| # But that's a tweet dict. We want just text, right? | |
| print json.loads(urllib2.urlopen('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=myfreeweb&count=200').read())[json.loads(urllib2.urlopen('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=myfreeweb&count=2').read())[0]['user']['statuses_count']-12344]['text'] | |
| # Now let's use the force... | |
| print (lambda a: a[a[0]['user']['statuses_count']-12344]['text'])(json.loads(urllib2.urlopen('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=myfreeweb&count=200').read())) | |
| # It can do a better thing: open it in your browser. | |
| # So copy this (don't forget the imports), paste to the interactive python shell, replace the username and enjoy... | |
| import webbrowser | |
| webbrowser.open('http://twitter.com/myfreeweb/status/' + (lambda a: a[a[0]['user']['statuses_count']-12344]['id'])(json.loads(urllib2.urlopen('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=myfreeweb&count=200').read()))) | |
| # Yeah, Python can do it with a single line. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment