Skip to content

Commit

Permalink
Fix insert_data_to_db to catch Json Data with no contact data
Browse files Browse the repository at this point in the history
Some json files contain data that belong to the grouping, with no contact data. 
- Edited src.db.insert_data_to_db function to catch and ignore such files
  • Loading branch information
ioannisvlachos authored Jun 10, 2024
1 parent 5228e8c commit f733248
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,15 @@ def create_database():
def insert_data_to_db(conn, json_files: list):
cur = conn.cursor()
for r in range(len(json_files)):
# try:
print(f'[*] Inserting file {r+1}/{len(json_files)}..')
subscriber = getSubsAllData(json_files[r])
subs_data = json.dumps(subscriber, ensure_ascii = False)
for phone in subscriber['phones']:
try:
try:
print(f'[*] Inserting file {r+1}/{len(json_files)}..')
subscriber = getSubsAllData(json_files[r])
subs_data = json.dumps(subscriber, ensure_ascii = False)
for phone in subscriber['phones']:
# Inserting each phone number along with the rest of the subscriber data
cur.execute("INSERT INTO phone_num (number, data) VALUES (%s, %s::jsonb)", (phone['number'], subs_data))
except Exception as e:
print(f'Error {e} in file {json_files[r]}')
except Exception as e:
print(f'Error {e} in file {json_files[r]}')
conn.commit()
cur.close()

Expand Down

0 comments on commit f733248

Please sign in to comment.