Make getmentions use argparse. Finally.
This commit is contained in:
parent
593213bb2e
commit
c3575e6d76
|
@ -1,8 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import dbtools
|
import dbtools
|
||||||
|
import argparse, operator, re, sys
|
||||||
import operator, re, sys
|
|
||||||
|
|
||||||
def getTweets(mode = "@", db = dbtools.dbObject()):
|
def getTweets(mode = "@", db = dbtools.dbObject()):
|
||||||
handles = dict()
|
handles = dict()
|
||||||
|
@ -24,20 +23,18 @@ def getTweets(mode = "@", db = dbtools.dbObject()):
|
||||||
return handles
|
return handles
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
mode = "@"
|
parser = argparse.ArgumentParser()
|
||||||
if len(sys.argv) > 1:
|
g = parser.add_mutually_exclusive_group()
|
||||||
if len(sys.argv) > 3 or (len(sys.argv) == 3 and "-h" not in sys.argv):
|
g.add_argument("-t", "--hashtags", help="count only #hashtags", action="store_true")
|
||||||
raise ValueError("Invalid arguments passed.")
|
g.add_argument("-w", "--words", help="count all words", action="store_true")
|
||||||
|
g.add_argument("-m", "--mentions", help="count only @mentions (default)", action="store_true")
|
||||||
|
args = parser.parse_args()
|
||||||
|
if args.hashtags:
|
||||||
|
mode = "#"
|
||||||
|
elif args.words:
|
||||||
|
mode = ""
|
||||||
|
else:
|
||||||
|
mode = "@"
|
||||||
|
|
||||||
path = None
|
for handle, tweets in sorted(list(getTweets(mode,dbtools.dbObject()).items()), key=operator.itemgetter(1), reverse=True):
|
||||||
|
|
||||||
for arg in sys.argv[1:]:
|
|
||||||
if arg == "-h":
|
|
||||||
mode = "#"
|
|
||||||
if arg == "-w":
|
|
||||||
mode = ""
|
|
||||||
else:
|
|
||||||
path = arg
|
|
||||||
|
|
||||||
for handle, tweets in sorted(list(getTweets(mode,dbtools.dbObject(path=path)).items()), key=operator.itemgetter(1), reverse=True):
|
|
||||||
print(handle + "," + str(tweets))
|
print(handle + "," + str(tweets))
|
||||||
|
|
Loading…
Reference in a new issue