twitools/gethandles.py
Klaus-Uwe Mitterer 0c4eb44444 Convert gethandles.py to Python 3
Directly output datecsv.sh results
2015-04-13 22:11:42 +02:00

29 lines
705 B
Python
Executable file

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import operator, re, sqlite3
def getTweets(database_filename = "Database.db"):
sql_conn = sqlite3.connect(database_filename)
cur = sql_conn.cursor()
handles = dict()
tweets = cur.execute("SELECT text FROM tweets")
for tweet in tweets:
for word in tweet[0].split():
if word[0] == "@":
handle = "@" + re.split('[\\W]',word[1:])[0].lower()
if handle != "@":
try:
handles[handle] += 1
except KeyError:
handles[handle] = 1
return handles
if __name__ == "__main__":
data = sorted(list(getTweets().items()), key=operator.itemgetter(1), reverse=True)
for handle, tweets in data:
print(handle + "," + str(tweets))