-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportRW.py
37 lines (30 loc) · 1.01 KB
/
importRW.py
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
import csv
import time
import os
from utils import post, get
from dotenv import load_dotenv
load_dotenv()
api_token = os.getenv("API_TOKEN")
api_url = os.getenv("HOST")
with open('datasetsRW.csv')as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
name = row[2]
code = row[0]
result = post(
payload={
"name": name,
"provider": "resourcewatch",
"connectorType": "rest",
"tableName": code
}, endpoint='v1/dataset', api_url=api_url, api_token=api_token)
datasetId = result['data']['id']
status = 'pending'
while status == 'pending':
getResult = get(payload={}, endpoint='v1/dataset/'+datasetId, api_url=api_url, api_token=api_token)
status = getResult['data']['attributes']['status']
if status == 'pending':
print('Sleeping...')
time.sleep(2)
print(name, code, status)
exit(0)