2015-05-14 14:29:55 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2016-05-30 18:40:21 +00:00
|
|
|
import dbtools, setuptools
|
2015-05-14 14:29:55 +00:00
|
|
|
|
|
|
|
import sys, datetime
|
|
|
|
|
|
|
|
def dateArgs(argv = sys.argv[1:]):
|
|
|
|
fr = None
|
|
|
|
to = None
|
|
|
|
|
|
|
|
mode = 0
|
|
|
|
|
|
|
|
for arg in argv:
|
|
|
|
if mode == 0:
|
|
|
|
if arg == "-f":
|
|
|
|
mode = 1
|
|
|
|
elif arg == "-t":
|
|
|
|
mode = 2
|
|
|
|
else:
|
|
|
|
strings += [arg]
|
|
|
|
mode = 0
|
|
|
|
elif mode == 1:
|
2016-05-30 18:40:21 +00:00
|
|
|
fr = setuptools.getDate(arg)
|
2015-05-14 14:29:55 +00:00
|
|
|
mode = 0
|
|
|
|
else:
|
2016-05-30 18:40:21 +00:00
|
|
|
to = setuptools.getDate(arg)
|
2015-05-14 14:29:55 +00:00
|
|
|
mode = 0
|
|
|
|
|
|
|
|
if mode in (1, 2):
|
|
|
|
raise ValueError("Date missing.")
|
|
|
|
|
|
|
|
if to != None and fr != None and to < fr:
|
|
|
|
raise ValueError("From date must be before To date.")
|
|
|
|
|
|
|
|
return fr, to
|
|
|
|
|
|
|
|
|
|
|
|
def queryBuilder(fr, to):
|
|
|
|
return "SELECT * FROM tweets WHERE SUBSTR(timestamp,0,11) >= '%s' AND SUBSTR(timestamp,0,11) <= '%s'" % (fr, to)
|
|
|
|
|
|
|
|
|
2016-05-30 18:40:21 +00:00
|
|
|
def getDataByDate(fr, to, db = dbtools.dbObject(), headers = True):
|
2015-05-14 14:29:55 +00:00
|
|
|
if fr == None:
|
|
|
|
fr = db.getFLDate()
|
|
|
|
if to == None:
|
|
|
|
to = db.getFLDate(1)
|
|
|
|
|
|
|
|
cur = list(db.executeQuery(queryBuilder(fr, to)))
|
|
|
|
|
|
|
|
if headers:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return cur
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2016-05-30 18:59:41 +00:00
|
|
|
setuptools.printCSV(getDataByDate(*dateArgs(), headers = True))
|