Skip to content

Commit

Permalink
check profile table exists fix catch-22 in process_all_paid
Browse files Browse the repository at this point in the history
  • Loading branch information
datawhores committed Oct 8, 2023
1 parent c2dd678 commit 0edea8b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
28 changes: 24 additions & 4 deletions ofscraper/db/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions ofscraper/db/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'(
Expand Down
4 changes: 2 additions & 2 deletions ofscraper/utils/of.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0edea8b

Please sign in to comment.