User:Mirjam Dissel/JSON twitter API in Python: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "Friday 21 Jan 2011 ---- Chmod it by removing extension and in terminal:<br> chmod +x filename execute by typing in terminal:<br> filename searchquery <source lang="python">...")
 
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 3: Line 3:
----
----


<source lang="python">
#!/usr/bin/python
import sys, json, urllib2, os
f = urllib2.urlopen("http://search.twitter.com/search.json?q="+sys.argv[1])
data = json.load(f)
for r in data ["results"]:
print r["text"]
</source>


Chmod it by removing extension and in terminal:<br>
Chmod it by removing extension and in terminal:<br>
chmod +x filename
chmod +x filename


execute by typing in terminal:<br>
execute by typing in terminal:<br>
filename searchquery
filename searchquery


Exact same story as above, now espeak read tweets out aloud:
<source lang="python">
<source lang="python">
#!/usr/bin/python
#!/usr/bin/python
Line 20: Line 36:
data = json.load(f)
data = json.load(f)


os.system("espeak cool")
for r in data ["results"]:
for r in data ["results"]:
print r["text"]
print r["text"]
 
os.system('espeak "'+r["text"].encode("utf-8") + '"')
</source>
</source>

Latest revision as of 15:05, 21 January 2011

Friday 21 Jan 2011


#!/usr/bin/python

import sys, json, urllib2, os
 

f = urllib2.urlopen("http://search.twitter.com/search.json?q="+sys.argv[1])
data = json.load(f)

for r in data ["results"]:
	print r["text"]

Chmod it by removing extension and in terminal:
chmod +x filename

execute by typing in terminal:
filename searchquery



Exact same story as above, now espeak read tweets out aloud:

#!/usr/bin/python

import sys, json, urllib2, os
 

f = urllib2.urlopen("http://search.twitter.com/search.json?q="+sys.argv[1])
data = json.load(f)

os.system("espeak cool")
for r in data ["results"]:
	print r["text"]
	os.system('espeak "'+r["text"].encode("utf-8") + '"')