]> khamidou — GitHub mirrors - Projet_IC05.git/commitdiff
le scrapper semble marcher
authorkarim hamidou <khamidou@gmail.com>
Fri, 2 Nov 2012 10:51:49 +0000 (11:51 +0100)
committerkarim hamidou <khamidou@gmail.com>
Fri, 2 Nov 2012 10:51:49 +0000 (11:51 +0100)
scrapper.py

index abb7b1df740b876065469973e3d07c3e84456b6b..7fc6a71ff606c2ba2fb7667c1db1d1418c39c8ce 100644 (file)
@@ -1,18 +1,20 @@
 #!/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)
@@ -24,8 +26,8 @@ def getPage(url):
 
 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
@@ -35,4 +37,8 @@ def runQuery():
         outf.write(getPage(url))
 
 os.chdir(sys.argv[1])
-runQuery()
+
+while True:
+    print "Querying..."
+    runQuery()
+    sleep(DURATION)