-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fork of code from ScraperWiki at https://classic.scraperwiki.com/scra…
- Loading branch information
soundball
committed
Jul 8, 2014
0 parents
commit 38f910a
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Ignore output of scraper | ||
data.sqlite |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
################################################################################### | ||
# Twitter API scraper - designed to be forked and used for more interesting things | ||
################################################################################### | ||
|
||
import scraperwiki | ||
import simplejson | ||
import urllib2 | ||
|
||
|
||
QUERY = 'hochwasser' | ||
GEOINFO = '49.486816,8.442256,500km' | ||
RESULTS_PER_PAGE = '1000' | ||
LANGUAGE = 'de' | ||
NUM_PAGES = 15 | ||
|
||
for page in range(1, NUM_PAGES+1): | ||
base_url = 'http://search.twitter.com/search.json?q=%s&geocode=%s&rpp=%s&lang=%s&page=%s' \ | ||
% (urllib2.quote(QUERY), urllib2.quote(GEOINFO), RESULTS_PER_PAGE, LANGUAGE, page) | ||
try: | ||
results_json = simplejson.loads(scraperwiki.scrape(base_url)) | ||
for result in results_json['results']: | ||
data = {} | ||
data['id'] = result['id'] | ||
data['text'] = result['text'] | ||
data['from_user'] = result['from_user'] | ||
data['geo'] = result['geo'] | ||
print data['from_user'], data['text'] | ||
scraperwiki.sqlite.save(["id"], data) | ||
except: | ||
print 'Oh dear, failed to scrape %s' % base_url | ||
|
||
|