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
import tools
import dbtools, setuptools
import operator, re, sys
def getTweets(path, mon, mode = "@"):
db = tools.dbHelper(path)
def getTweets(mon, mode = "@", db = dbtools.dbHelper()):
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))
for tweet in tweets:
for word in tweet[0].lower().split():
if word[0] == mode or mode == "":
@ -27,10 +25,9 @@ def getTweets(path, mon, mode = "@"):
if __name__ == "__main__":
mode = "@"
path = tools.dbpath()
mon = "2016-03"
mon = "2016-07"
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):
raise ValueError("Invalid arguments passed.")
@ -42,5 +39,6 @@ if __name__ == "__main__":
else:
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))