-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_json.py
24 lines (21 loc) · 925 Bytes
/
load_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import psycopg
import csv
import httpx
#dynamodb = boto3.resource('dynamodb',region_name='us-east-1')
#table = dynamodb.Table('stocks')
url = "https://www.asx.com.au/asx/research/ASXListedCompanies.csv"
r=httpx.get(url)
r.raise_for_status()
with open('ASXListedCompanies.csv', 'wb') as f:
f.write(r.content)
with psycopg.connect("postgresql://postgres:[email protected]"
".us-east-1.rds.amazonaws.com:5432/postgres") as conn:
with conn.cursor() as cur:
cur.execute("TRUNCATE TABLE asx_stocks")
with open('ASXListedCompanies.csv') as csvfile:
csvfile.readline()
csvfile.readline()
reader=csv.DictReader(csvfile)
with cur.copy("COPY asx_stocks (stock_code, stock_name) FROM STDIN") as copy:
for row in reader:
copy.write_row((row["ASX code"], row["Company name"]))