From c6c994926d8e617e3df7485e89abbbb41c6f069f Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Fri, 8 Apr 2016 00:15:21 +0200 Subject: [PATCH] Fixed filler dependencies --- dbtools/__init__.py | 15 +++++++++++++-- filler.py | 24 ++++-------------------- tools/__init__.py | 5 ++++- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/dbtools/__init__.py b/dbtools/__init__.py index 64c2c27..b8683f1 100644 --- a/dbtools/__init__.py +++ b/dbtools/__init__.py @@ -4,6 +4,9 @@ SQLITE = 0 MYSQL = 1 MARIADB = MYSQL +MIN = 0 +MAX = 1 + class dbObject: # --------------------------------------------- Initialization ------------------------------------------------- @@ -56,9 +59,17 @@ class dbObject: except: return False - def getFLDate(self, val = 0): - if val == 0: + def getFLDate(self, val = MIN): + if val == MIN: mode = "MIN" else: mode = "MAX" return getDate(str(list(self.executeQuery("SELECT %s(SUBSTR(timestamp,0,11)) FROM tweets" % mode))[0][0])) + + def getLatestTweet(db): + db.executeQuery("SELECT max(tweet_id) FROM tweets") + try: + return int(db.getNext()[0]) + except: + return 0 + diff --git a/filler.py b/filler.py index 8ef8710..5e5e822 100755 --- a/filler.py +++ b/filler.py @@ -1,26 +1,10 @@ #!/usr/bin/env python3 -import tools +import dbtools, tools -import html.parser, os - -def getSavepoint(db): - db.executeQuery("SELECT max(tweet_id) FROM tweets") - try: - return int(db.getNext()[0]) - except: - print("No tweets stored yet.") - return 0 - -def unescapeText(text): - return html.parser.HTMLParser().unescape(text).replace("'","''") - -def fill(dbpath=tools.dbpath(), user=tools.user(), two=tools.twObject()): +def fill(db=dbtools.dbObject(), user=tools.user(), two=tools.twObject()): query = "from:" + user - - db = tools.dbHelper(dbpath) - - savepoint = getSavepoint(db) + savepoint = db.getLatestTweet() last = savepoint timeline = two.search(query, savepoint) @@ -29,7 +13,7 @@ def fill(dbpath=tools.dbpath(), user=tools.user(), two=tools.twObject()): for status in timeline: timestamp = status.created_at.strftime('%Y-%m-%d %H:%M:%S') + " +0000" - text = unescapeText(status.text) + text = tools.unescapeText(status.text) db.executeQuery("INSERT INTO tweets('tweet_id','timestamp','text') VALUES(" + str(status.id) + ",'" + timestamp + "','" + text + "')") db.commit() diff --git a/tools/__init__.py b/tools/__init__.py index d39a1eb..9358a6e 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -1,4 +1,4 @@ -import configparser, csv, datetime, itertools, os, sqlite3, sys, tweepy +import configparser, csv, datetime, html.parser, itertools, os, sqlite3, sys, tweepy class SetupException(Exception): def __str__(self): @@ -158,3 +158,6 @@ def printCSV(inlist): writer = csv.writer(sys.stdout) writer.writerows(inlist) +def unescapeText(text): + return html.parser.HTMLParser().unescape(text).replace("'","''") +