-
Notifications
You must be signed in to change notification settings - Fork 3
/
getTwitterFeed.py
executable file
·32 lines (22 loc) · 1006 Bytes
/
getTwitterFeed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
import urllib2
import json
def getTwitterSearchResults(
url='http://search.twitter.com/search.json?q=%23samsung%20OR%20%23galaxys4%20lang%3Aen&src=typd&rpp=100&page=1',
hashtags=('galaxy', 'samsung', 's4')):
response = urllib2.urlopen(url)
jsonResponse = json.loads(response.read())
print len(jsonResponse['results'])
return jsonResponse['results']
def printResultsToFile(result, myFile):
for item in result:
myFile.write("TWITTER : " + item['text'].encode('ascii', errors='ignore'))
myFile.write("\n")
if __name__ == "__main__":
myFile = open('/Users/asood/work/opensource/play/bostonHackathon/hackathon/twitter.txt', 'a')
url = 'http://search.twitter.com/search.json?q=%23samsung%20OR%20%23galaxys4%20lang%3Aen&src=typd&rpp=100&page='
for i in range(1, 15):
query = url + str(i)
twitterResult = getTwitterSearchResults(query)
printResultsToFile(twitterResult, myFile)
myFile.close()