Skip to content

Commit 77608d4

Browse files
committed
use f strings
1 parent 451cfcd commit 77608d4

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

dbt_docs_to_notion.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,19 @@ def make_request(endpoint, querystring='', method='GET', **request_kwargs):
1818
'Content-Type': 'application/json',
1919
'Notion-Version': '2022-02-22'
2020
}
21-
url = 'https://api.notion.com/v1/%s%s' % (endpoint, querystring)
21+
url = f'https://api.notion.com/v1/{endpoint}{querystring}'
2222
resp = requests.request(method, url, headers=headers, **request_kwargs)
2323

2424
if not resp.status_code == 200:
2525
raise Exception(
26-
"Request returned status code %d\nResponse text: %s"
27-
% (resp.status_code, resp.text)
26+
f"Request returned status code {resp.status_code}\nResponse text: {resp.text}"
2827
)
2928

3029
return resp.json()
3130

3231
def main():
3332
model_records_to_write = sys.argv[1:] # 'all' or list of model names
34-
print('Model records to write: %s' % model_records_to_write)
33+
print(f'Model records to write: {model_records_to_write}')
3534

3635
###### load nodes from dbt docs ######
3736
f = open('target/manifest.json', encoding='utf-8')
@@ -49,7 +48,7 @@ def main():
4948
###### create database if not exists ######
5049
children_query_resp = make_request(
5150
endpoint='blocks/',
52-
querystring='%s/children' % DATABASE_PARENT_ID,
51+
querystring=f'{DATABASE_PARENT_ID}/children',
5352
method='GET'
5453
)
5554

@@ -61,7 +60,7 @@ def main():
6160
break
6261

6362
if database_id:
64-
print('database %s already exists, proceeding to update records!' % database_id)
63+
print(f'database {database_id} already exists, proceeding to update records!')
6564
else:
6665
database_obj = {
6766
"title": [
@@ -117,7 +116,7 @@ def main():
117116
json=database_obj
118117
)
119118
database_id = database_creation_resp['id']
120-
print('\ncreated database %s, proceeding to create records!' % database_id)
119+
print(f'\ncreated database {database_id}, proceeding to create records!')
121120

122121
##### create / update database records #####
123122
for model_name, data in sorted(list(models.items()), reverse=True):
@@ -420,16 +419,16 @@ def main():
420419
}
421420
record_query_resp = make_request(
422421
endpoint='databases/',
423-
querystring='%s/query' % database_id,
422+
querystring=f'{database_id}/query',
424423
method='POST',
425424
json=query_obj
426425
)
427426

428427
if record_query_resp['results']:
429-
print('\nupdating %s record' % model_name)
428+
print(f'\nupdating {model_name} record')
430429
record_id = record_query_resp['results'][0]['id']
431430
_record_update_resp = make_request(
432-
endpoint='pages/%s' % record_id,
431+
endpoint=f'pages/{record_id}',
433432
querystring='',
434433
method='PATCH',
435434
json=record_obj
@@ -438,7 +437,7 @@ def main():
438437
# children can't be updated via record update, so we'll delete and re-add
439438
record_children_resp = make_request(
440439
endpoint='blocks/',
441-
querystring='%s/children' % record_id,
440+
querystring=f'{record_id}/children',
442441
method='GET'
443442
)
444443
for record_child in record_children_resp['results']:
@@ -451,13 +450,13 @@ def main():
451450

452451
_record_children_replacement_resp = make_request(
453452
endpoint='blocks/',
454-
querystring='%s/children' % record_id,
453+
querystring=f'{record_id}/children',
455454
method='PATCH',
456455
json={"children": record_children_obj}
457456
)
458457

459458
else:
460-
print('\ncreating %s record' % model_name)
459+
print(f'\ncreating {model_name} record')
461460
record_obj['children'] = record_children_obj
462461
_record_creation_resp = make_request(
463462
endpoint='pages/',

0 commit comments

Comments
 (0)