#!/usr/bin/env python
#
-# this script get the results of the twitter api for the keywords in
-# the list "keywords".
+# this script get the results of the twitter api for the KEYWORDS in
+# the list "KEYWORDS".
# the results are then saved in a timestamped file.
#
# usage: scrapper output_dir
-keywords = ["romney", "obama", "gary johnson", "ryan", "ron paul"]
+KEYWORDS = ["romney", "obama", "gary johnson", "ryan", "ron paul"]
+DURATION = 120 # in seconds
import os
import sys
import json
import urllib, urllib2
import datetime
+from time import sleep
def timeStamped(fname, fmt='{fname}%Y-%m-%d-%H-%M-%S.json'):
return datetime.datetime.now().strftime(fmt).format(fname=fname)
def runQuery():
queryString = ""
- for keyword in keywords:
- if keyword != keywords[-1]:
+ for keyword in KEYWORDS:
+ if keyword != KEYWORDS[-1]:
queryString += keyword + " OR "
else:
queryString += keyword
outf.write(getPage(url))
os.chdir(sys.argv[1])
-runQuery()
+
+while True:
+ print "Querying..."
+ runQuery()
+ sleep(DURATION)