Skip to content

Commit

Permalink
Seperated TV Show & TV Sries in 2 DBs
Browse files Browse the repository at this point in the history
  • Loading branch information
TheurgicDuke771 committed Aug 14, 2023
1 parent 6d2e924 commit f123f8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions python_scripts/mdl_invalid_record_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


ETL_TIME = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
DB_LIST = ['tv', 'movie']
DB_LIST = ['tv', 'drama', 'movie']

for db_name in DB_LIST:
try:
Expand All @@ -14,7 +14,7 @@

fetch_query = f"select * from public.{db_name} where DATE_PART('day', localtimestamp(0) - update_ts) > 30;"
df = sqlio.read_sql_query(fetch_query, conn)
print(f"{ETL_TIME} INFO: Fetched {len(df)} records for DB {db_name}")
print(f"{ETL_TIME} INFO: Fetched {len(df)} records for {db_name} DB")

id_list = []
for index, row in df.iterrows():
Expand All @@ -35,9 +35,9 @@
"""
cur.execute(update_query)
conn.commit()
print(f"{ETL_TIME} INFO: {len(id_list)} records are updated for DB {db_name}")
print(f"{ETL_TIME} INFO: {len(id_list)} records are updated for {db_name} DB")
else:
print(f"{ETL_TIME} INFO: No record to update for DB {db_name}")
print(f"{ETL_TIME} INFO: No record to update for {db_name} DB")
except Exception as e:
print(f"{ETL_TIME} ERROR: {str(e)}")

Expand Down
13 changes: 9 additions & 4 deletions python_scripts/mdl_psql.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ def inset_into_db(content_list: list) -> int:
except:
rating = 99999

table_name = "movie" if item_type == "Movie" else "tv"
if item_type == "Movie":
table_name = "movie"
elif (item_type == "Drama") or (item_type == "Special"):
table_name = "drama"
else:
table_name = "tv"

fetch_query = f'SELECT * FROM {table_name} WHERE "id" = {item_id};'
result = pd.read_sql(fetch_query, conn)
Expand All @@ -107,7 +112,7 @@ def inset_into_db(content_list: list) -> int:
INSERT INTO {table_name}
("id", "title", "episodes", "ranking",
"best_ranking", "popularity", "best_popularity",
"country", "content_type", "type", "synopsis",
"country", "content_type", "record_type", "synopsis",
"released_at", "url", "genres", "thumbnail",
"cover", "rating", "best_rating", "insert_ts", "update_ts")
VALUES
Expand Down Expand Up @@ -143,7 +148,7 @@ def inset_into_db(content_list: list) -> int:
"best_popularity" = case when ("best_popularity" > {popularity}) then {popularity} else "best_popularity" end,
"country" = '{country}',
"content_type" = '{content_type}',
"type" = '{item_type}',
"record_type" = '{item_type}',
"synopsis" = '{synopsis}',
"released_at" = '{released_at}',
"url" = '{url}',
Expand All @@ -170,7 +175,7 @@ def inset_into_db(content_list: list) -> int:
"best_popularity" = case when ("best_popularity" > {popularity}) then {popularity} else "best_popularity" end,
"country" = '{country}',
"content_type" = '{content_type}',
"type" = '{item_type}',
"record_type" = '{item_type}',
"released_at" = '{released_at}',
"url" = '{url}',
"genres" = '{genres}',
Expand Down

0 comments on commit f123f8e

Please sign in to comment.