Skip to content

Commit 312f7db

Browse files
committed
use save sql string formatting #311
1 parent 9ac03ad commit 312f7db

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

mapswipe_workers/mapswipe_workers/firebase_to_postgres/archive_project.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ def archive_project(project_ids: list) -> None:
1414
Set status = archived for project in Firebase and Postgres.
1515
"""
1616
for project_id in project_ids:
17-
logger.info("Archive project with the id {0}".format(project_id))
18-
logger.info("Delete results of project with the id {0}".format(project_id))
17+
logger.info(f"Archive project with the id {project_id}")
18+
logger.info(f"Delete results of project with the id {project_id}")
1919

2020
fb_db = auth.firebaseDB()
21-
fb_db.reference("v2/results/{0}".format(project_id)).set({})
21+
fb_db.reference(f"v2/results/{project_id}").set({})
2222

2323
# get group keys for this project to estimate size in firebase
24-
groups = fb_db.reference("v2/groups/{0}/".format(project_id)).get(shallow=True)
24+
groups = fb_db.reference(f"v2/groups/{project_id}").get(shallow=True)
2525

2626
if not groups:
2727
logger.info("no groups to delete in firebase")
@@ -33,36 +33,28 @@ def archive_project(project_ids: list) -> None:
3333
# delete groups, tasks in firebase for each chunk using the update function
3434
for i in range(0, chunks):
3535
logger.info(
36-
"Delete max {1} groups and tasks of project with the id {0}".format(
37-
project_id, chunk_size
38-
)
36+
f"Delete max {chunk_size} groups and tasks"
37+
f"of project with the id {project_id}"
3938
)
4039
update_dict = {}
4140
for group_id in group_keys[:chunk_size]:
4241
update_dict[group_id] = None
43-
fb_db.reference("v2/groups/{0}".format(project_id)).update(update_dict)
44-
fb_db.reference("v2/tasks/{0}".format(project_id)).update(update_dict)
42+
fb_db.reference(f"v2/groups/{project_id}").update(update_dict)
43+
fb_db.reference(f"v2/tasks/{project_id}").update(update_dict)
4544
group_keys = group_keys[chunk_size:]
4645

4746
logger.info(
48-
"Set status=archived in Firebase for project with the id {0}".format(
49-
project_id
50-
)
47+
f"Set status=archived in Firebase for project with the id {project_id}"
5148
)
5249
fb_db = auth.firebaseDB()
53-
ref = fb_db.reference("v2/projects/{0}/status".format(project_id))
54-
ref.set("archived")
50+
fb_db.reference(f"v2/projects/{project_id}/status").set("archived")
5551

5652
logger.info(
57-
"Set status=archived in Postgres for project with the id {0}".format(
58-
project_id
59-
)
53+
f"Set status=archived in Postgres for project with the id {project_id}"
6054
)
6155
pg_db = auth.postgresDB()
6256
sql_query = """
6357
UPDATE projects SET status = 'archived'
64-
WHERE project_id = '{0}';
65-
""".format(
66-
project_id
67-
)
68-
pg_db.query(sql_query)
58+
WHERE project_id = %(project_id)s;
59+
"""
60+
pg_db.query(sql_query, {"project_id": project_id})

0 commit comments

Comments
 (0)