-
Notifications
You must be signed in to change notification settings - Fork 0
/
importWB.py
38 lines (31 loc) · 1.08 KB
/
importWB.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
38
import csv
import requests
import json
import os
from dotenv import load_dotenv
load_dotenv()
api_token = os.getenv("API_TOKEN")
api_url = os.getenv("HOST")
# Convenience function for registering datasets
def register(payload, endpoint='v1/dataset', api_url=api_url, api_token=api_token):
print("Doing authenticated request to the API")
headers = {'User-Agent': 'python-requests', 'Content-Type': 'application/json',
'Authorization': api_token}
result = requests.post('/'.join((api_url, endpoint)), json=payload, headers=headers)
status_code, result = result.status_code, result.text
print(f"Status code: {status_code}")
return json.loads(result)
with open('datasetsWB.csv')as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
name = row[0]
code = row[1]
result = register(
payload={
"name": name,
"provider": "worldbank",
"connectorType": "rest",
"tableName": code
})
print(name, code, result)
exit(0)