40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from twitter.tweet import Tweet
|
|
from base.dbdata import DataDBRow
|
|
|
|
|
|
class TwitterDBHelper:
|
|
pymysql = __import__('pymysql.cursors')
|
|
|
|
def __init__(self):
|
|
self.conn = self.pymysql.connect(host='bigbird.iptime.org',
|
|
user='admin', passwd='admin123',
|
|
db='concepters', charset='utf8',
|
|
cursorclass=self.pymysql.cursors.DictCursor)
|
|
|
|
def __del__(self):
|
|
self.conn.close()
|
|
|
|
def get_param(self, keyword_id):
|
|
query = "select * from keyword where id = " + str(keyword_id)
|
|
params = []
|
|
try:
|
|
with self.conn.cursor() as cursor:
|
|
cursor.execute(query)
|
|
params = cursor.fetchone()
|
|
|
|
except Exception as e:
|
|
print(e)
|
|
exit(1)
|
|
|
|
return params
|
|
|
|
def insert_tweet(self, db_num: int, tweet: Tweet):
|
|
query = tweet.get_insert_query(self.conn, db_num)
|
|
|
|
try:
|
|
with self.conn.cursor() as cursor:
|
|
cursor.execute(query)
|
|
self.conn.commit()
|
|
except Exception as e:
|
|
print(e)
|