Add latest challenge

This commit is contained in:
Klaus-Uwe Mitterer 2016-12-07 14:12:26 +01:00
parent 25ce567048
commit 3eeb777583

View file

@ -1,15 +1,13 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import tools import dbtools, setuptools
import operator, re, sys import operator, re, sys
def getTweets(path, mon, mode = "@"): def getTweets(mon, mode = "@", db = dbtools.dbHelper()):
db = tools.dbHelper(path)
handles = dict() handles = dict()
tweets = db.executeQuery("SELECT text FROM tweets WHERE SUBSTR(timestamp,0,11)>='%s-01' AND SUBSTR(timestamp,0,11)<='%s-31'" % (mon, mon)) tweets = db.executeQuery("SELECT text FROM tweets WHERE SUBSTR(timestamp,0,11)>='%s-01' AND SUBSTR(timestamp,0,11)<='%s-31'" % (mon, mon))
for tweet in tweets: for tweet in tweets:
for word in tweet[0].lower().split(): for word in tweet[0].lower().split():
if word[0] == mode or mode == "": if word[0] == mode or mode == "":
@ -27,10 +25,9 @@ def getTweets(path, mon, mode = "@"):
if __name__ == "__main__": if __name__ == "__main__":
mode = "@" mode = "@"
path = tools.dbpath() mon = "2016-07"
mon = "2016-03"
if len(sys.argv) > 1: if len(sys.argv) > 1:
if len(sys.argv) > 3 or (len(sys.argv) == 3 and "-h" not in sys.argv): if len(sys.argv) > 3 or (len(sys.argv) == 3 and "-h" not in sys.argv):
raise ValueError("Invalid arguments passed.") raise ValueError("Invalid arguments passed.")
@ -42,5 +39,6 @@ if __name__ == "__main__":
else: else:
mon = arg mon = arg
for handle, tweets in sorted(list(getTweets(path,mon,mode).items()), key=operator.itemgetter(1), reverse=True): for handle, tweets in sorted(list(getTweets(mon,mode).items()), key=operator.itemgetter(1), reverse=True):
print(handle + "," + str(tweets)) print(handle + "," + str(tweets))