-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
45 lines (35 loc) · 1 KB
/
test.py
File metadata and controls
45 lines (35 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import psycopg2
import os
from dotenv import load_dotenv
load_dotenv()
db_settings = {
"host": f"{os.getenv('POSTGRES_HOST')}",
"port": f"{os.getenv('POSTGRES_PORT')}",
"database": f"{os.getenv('POSTGRES_DB')}",
"user": f"{os.getenv('POSTGRES_USER')}",
"password": f"{os.getenv('POSTGRES_PASSWORD')}",
}
try:
# Connect to PostgreSQL database
conn = psycopg2.connect(**db_settings)
# Create a cursor object
cursor = conn.cursor()
# SQL query to update download_link column
update_query = """
UPDATE audioarchives
SET download_link = REPLACE(download_link, 'audioarchives', 'broadcasting')
WHERE download_link LIKE '%audioarchives%';
"""
# Execute the update query
cursor.execute(update_query)
# Commit the changes
conn.commit()
print("Download links updated successfully.")
except Exception as e:
print(f"Error: {e}")
finally:
# Close cursor and connection
if cursor:
cursor.close()
if conn:
conn.close()