Commit 652fe03a authored by andytnt's avatar andytnt

Added DB history for users

parent 499f070f
import sqlite3 import sqlite3
import sys import sys
import time import time
import hashlib
def Conn(database): def Conn(database):
if database: if database:
...@@ -40,8 +41,9 @@ def init(db): ...@@ -40,8 +41,9 @@ def init(db):
verified integer not null, verified integer not null,
profile_image_url text not null, profile_image_url text not null,
background_image text, background_image text,
hex_dig text not null,
time_update integer not null, time_update integer not null,
CONSTRAINT users_pk PRIMARY KEY (id) CONSTRAINT users_pk PRIMARY KEY (id, hex_dig)
); );
""" """
cursor.execute(table_users) cursor.execute(table_users)
...@@ -181,37 +183,27 @@ def follow(conn, Username, Followers, User): ...@@ -181,37 +183,27 @@ def follow(conn, Username, Followers, User):
except sqlite3.IntegrityError: except sqlite3.IntegrityError:
pass pass
def get_user_id(conn, id): def get_hash_id(conn, id):
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute('SELECT id FROM users WHERE id = ? LIMIT 1', (id,)) cursor.execute('SELECT hex_dig FROM users WHERE id = ? LIMIT 1', (id,))
resultset = cursor.fetchall() resultset = cursor.fetchall()
return resultset[0][0] if resultset else -1 return resultset[0][0] if resultset else -1
def user(conn, config, User): def user(conn, config, User):
try: try:
time_ms = round(time.time()*1000) time_ms = round(time.time()*1000)
cursor = conn.cursor() cursor = conn.cursor()
entry = (int(User.id), user = [int(User.id), User.id, User.name, User.username, User.bio, User.location, User.url,User.join_date, User.join_time, User.tweets, User.following, User.followers, User.likes, User.media_count, User.is_private, User.is_verified, User.avatar, User.background_image]
User.id,
User.name, hex_dig = hashlib.sha256(','.join(str(v) for v in user).encode()).hexdigest()
User.username, entry = tuple(user) + (hex_dig,time_ms,)
User.bio, old_hash = get_hash_id(conn, User.id)
User.location,
User.url, if old_hash == -1 or old_hash != hex_dig:
User.join_date, query = f"INSERT INTO users VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
User.join_time, cursor.execute(query, entry)
User.tweets, else:
User.following, pass
User.followers,
User.likes,
User.media_count,
User.is_private,
User.is_verified,
User.avatar,
User.background_image,
time_ms)
query = f"INSERT INTO users VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
cursor.execute(query, entry)
if config.Followers or config.Following: if config.Followers or config.Following:
table = uTable(config.Followers) table = uTable(config.Followers)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment