Merge git.klaus-uwe.me:kumitterer/twistats

This commit is contained in:
Klaus-Uwe Mitterer 2015-04-14 14:14:24 +02:00
commit 305eed1519
2 changed files with 43 additions and 0 deletions

15
datecsv.sh Executable file
View file

@ -0,0 +1,15 @@
#!/bin/bash
DATAFILE=Database.db
SQLITE="sqlite3 -csv -header"
QUERY="SELECT SUBSTR(t.timestamp,0,11) AS 'Date', (SELECT COUNT(*) FROM tweets e WHERE SUBSTR(e.timestamp,0,11) = SUBSTR(t.timestamp,0,11)) AS 'Tweets'"
for i in $@;
do QUERY="$QUERY, (SELECT COUNT(*) FROM tweets e WHERE SUBSTR(e.timestamp,0,11) = SUBSTR(t.timestamp,0,11) AND LOWER(e.text) LIKE '%${i,,}%') AS '$i'"
done
QUERY="$QUERY FROM tweets t GROUP BY SUBSTR(t.timestamp,0,11);"
$SQLITE $DATAFILE "$QUERY"

28
gethandles.py Executable file
View file

@ -0,0 +1,28 @@
#!/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))