59 lines
1 KiB
Python
Executable file
59 lines
1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import tools
|
|
|
|
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:
|
|
fr = tools.getDate(arg)
|
|
mode = 0
|
|
else:
|
|
to = tools.getDate(arg)
|
|
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)
|
|
|
|
|
|
def getDataByDate(fr, to, path = tools.dbpath(), headers = True):
|
|
db = tools.dbHelper(path)
|
|
|
|
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__":
|
|
tools.printCSV(getDataByDate(*dateArgs(), headers = True))
|