From 716a5721a997c2667750eeeb606b171ce95b5869 Mon Sep 17 00:00:00 2001 From: karim hamidou Date: Fri, 2 Nov 2012 11:51:49 +0100 Subject: [PATCH] le scrapper semble marcher --- scrapper.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scrapper.py b/scrapper.py index abb7b1d..7fc6a71 100644 --- a/scrapper.py +++ b/scrapper.py @@ -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) -- 2.43.0