twitools/gettweets.py
Klaus-Uwe Mitterer aad1531392 Futher preparation for MySQL, which is not working yet though...
Make filler handle direct messages
Add table and functions for direct messages
2016-06-30 12:33:09 +02:00

57 lines
1 KiB
Python
Executable file

#!/usr/bin/env python3
import dbtools, setuptools
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 = setuptools.getDate(arg)
mode = 0
else:
to = setuptools.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, db = dbtools.dbHelper(), headers = True):
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__":
setuptools.printCSV(getDataByDate(*dateArgs(), headers = True))