Fixed filler dependencies

This commit is contained in:
Klaus-Uwe Mitterer 2016-04-08 00:15:21 +02:00
parent c688162300
commit c6c994926d
3 changed files with 21 additions and 23 deletions

View file

@ -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

View file

@ -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()

View file

@ -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("'","''")