Skip to content

Commit f5ad211

Browse files
committed
load_pinterest_report_into_temp_dataset added start_date, end_date and granularity
1 parent 0b15a7f commit f5ad211

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

bigfunctions/load/saas/load_pinterest_report_into_temp_dataset.yaml

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: |
66
77
To get the needed `client_id`, `client_secret` and `refresh_token` from Pinterest, read their documentation [here](https://developers.pinterest.com/docs/getting-started/connect-app/) and then [there](https://developers.pinterest.com/docs/getting-started/set-up-authentication-and-authorization/).
88
9-
If you need help in getting thoses, you can get help on our [Slack](https://join.slack.com/t/unytics/shared_invite/zt-1gbv491mu-cs03EJbQ1fsHdQMcFN7E1Q).
9+
If you need help in getting those, you can get help on BigFunctions [Slack](https://join.slack.com/t/unytics/shared_invite/zt-1gbv491mu-cs03EJbQ1fsHdQMcFN7E1Q).
1010
1111
??? note "More on temporary datasets"
1212
@@ -44,13 +44,19 @@ examples:
4444
arguments:
4545
- 12345
4646
- 678910
47+
- '123445666'
4748
- ENCRYPTED_SECRET(kdoekdswlxzapdldpzlfpfd)
49+
- ENCRYPTED_SECRET(sqdksdoxlkwcmll;d;smgre)
50+
- current_date - 14
51+
- current_date - 1
52+
- 'DAY'
4853
output: "bigfunctions.temp_6bdb75ca_7f72_4f1f_b46a_6ca59f7f66ac.file_data"
4954
code: | #python
5055
import requests
5156
import time
5257
import urllib
5358
import duckdb
59+
import datetime
5460
import google.cloud.bigquery
5561
import slugify.slugify
5662
@@ -59,7 +65,10 @@ code: | #python
5965
assert client_id, 'missing client_id'
6066
assert client_secret, 'missing client_secret'
6167
assert refresh_token, 'missing refresh_token'
62-
assert refresh_token.startswith('pina_'), 'invalid refresh_token'
68+
assert refresh_token.startswith('pinr.'), 'invalid refresh_token'
69+
start_date = start_date or (datetime.datetime.now(datetime.UTC) - datetime.timedelta(days=14)).strftime('%Y-%m-%d')
70+
end_date = end_date or (datetime.datetime.now(datetime.UTC) - datetime.timedelta(days=1)).strftime('%Y-%m-%d')
71+
granularity = granularity or 'DAY'
6372
6473
def get_access_token():
6574
token_url = "https://api.pinterest.com/v5/oauth/token"
@@ -75,6 +84,7 @@ code: | #python
7584
"refresh_token": refresh_token,
7685
}
7786
response = requests.post(token_url, headers=headers, data=payload)
87+
assert response.ok, 'Could not get access token: ' + response.text
7888
data = response.json()
7989
return data['access_token']
8090
@@ -88,6 +98,7 @@ code: | #python
8898
}
8999
base_url = 'https://api.pinterest.com/v5'
90100
response = requests.request(method, base_url + url, headers=headers)
101+
assert response.ok, f'Error during {method} {url}: {response.text}'
91102
return response.json()
92103
93104
def get(url):
@@ -97,7 +108,7 @@ code: | #python
97108
return request('POST', url)
98109
99110
def create_report_from_template():
100-
report = post(f'/ad_accounts/{ad_account_id}/templates/{report_template_id}/reports')
111+
report = post(f'/ad_accounts/{ad_account_id}/templates/{report_template_id}/reports?start_date={start_date}&end_date={end_date}&granularity={granularity}')
101112
report['report_status'] = 'TO_CHECK'
102113
report_token = report['token']
103114
while report['report_status'] != 'FINISHED':

0 commit comments

Comments
 (0)