-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from gm3dmo/w59
Adding companies to railway.json
- Loading branch information
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from cmp.models import Company | ||
|
||
def run(): | ||
companies = Company.objects.all() | ||
companies.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
def run(): | ||
|
||
import sys | ||
import urllib3 | ||
import csv | ||
from cmp.models import Company | ||
|
||
ref_data_url = "https://raw.githubusercontent.com/gm3dmo/old-cmp/main/data/company.csv" | ||
http = urllib3.PoolManager() | ||
r = http.request('GET', ref_data_url) | ||
print(r.status) | ||
# load the response into a csv dictionary reader | ||
reader = csv.DictReader(r.data.decode('utf-8').splitlines()) | ||
|
||
print(reader.fieldnames) | ||
for row in reader: | ||
print(row['name']) | ||
try: | ||
Company.objects.create( | ||
name = row['name'] | ||
) | ||
except Exception as e: | ||
print("Error with: " + row['name']) | ||
raise e | ||
|