From 0edea8b7d623ada5f6998871117ced25b39c1cc3 Mon Sep 17 00:00:00 2001 From: datawhores Date: Sun, 8 Oct 2023 17:18:25 -0500 Subject: [PATCH] check profile table exists fix catch-22 in process_all_paid --- ofscraper/db/operations.py | 28 ++++++++++++++++++++++++---- ofscraper/db/queries.py | 4 ++++ ofscraper/utils/of.py | 4 ++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/ofscraper/db/operations.py b/ofscraper/db/operations.py index c18c9e3a5..09cb976f6 100644 --- a/ofscraper/db/operations.py +++ b/ofscraper/db/operations.py @@ -199,11 +199,16 @@ def get_media_ids_downloaded(model_id=None,username=None,conn=None,**kwargs) -> def get_profile_info(model_id=None,username=None,conn=None) -> list: database_path =placeholder.Placeholders().databasePathHelper(model_id,username) if not pathlib.Path(database_path).exists(): - return None + return None with contextlib.closing(conn.cursor()) as cur: - modelinfo=cur.execute(queries.profileDupeCheck,(model_id,)).fetchall() or [(None,)] - conn.commit() - return modelinfo[0][-1] + try: + modelinfo=cur.execute(queries.profileDupeCheck,(model_id,)).fetchall() or [(None,)] + conn.commit() + return modelinfo[0][-1] + except sqlite3.OperationalError as E: + None + except Exception as E: + raise E @operation_wrapper_async @@ -303,6 +308,21 @@ def write_profile_table(model_id=None,username=None,conn=None) -> list: cur.execute(queries.profileUpdate,insertData) conn.commit() +@operation_wrapper +def check_profile_table_exists(model_id=None,username=None,conn=None): + database_path =placeholder.Placeholders().databasePathHelper(model_id,username) + if not pathlib.Path(database_path).exists(): + return False + with contextlib.closing(conn.cursor()) as cur: + if len(cur.execute(queries.profileTableCheck).fetchall())>0: + conn.commit() + return True + conn.commit() + return False + + + + @operation_wrapper def create_labels_table(model_id=None,username=None,conn=None): with contextlib.closing(conn.cursor()) as cur: diff --git a/ofscraper/db/queries.py b/ofscraper/db/queries.py index f28823a3b..ef913bd2f 100644 --- a/ofscraper/db/queries.py +++ b/ofscraper/db/queries.py @@ -210,6 +210,10 @@ """ SELECT * FROM profiles where user_id=(?) """ +profileTableCheck=\ +""" +SELECT name FROM sqlite_master WHERE type='table' AND name='profiles'; +""" profileInsert=\ f"""INSERT INTO 'profiles'( diff --git a/ofscraper/utils/of.py b/ofscraper/utils/of.py index 669787983..c2436f9f1 100644 --- a/ofscraper/utils/of.py +++ b/ofscraper/utils/of.py @@ -187,8 +187,8 @@ def process_all_paid(): output=[] for model_id,value in user_dict.items(): username=profile.scrape_profile(model_id).get("username") - if username=="modeldeleted": - username=operations.get_profile_info(model_id=model_id,username=username) or username + if username=="modeldeleted" and operations.check_profile_table_exists(model_id=model_id,username=username): + username=operations.get_profile_info(model_id=model_id,username=username) or username log.info(f"Processing {username}_{model_id}") operations.create_tables(model_id,username) operations.create_backup(model_id,username)