Skip to content

Commit

Permalink
Adding demonstration scripts to load countries for #15
Browse files Browse the repository at this point in the history
  • Loading branch information
gm3dmo committed Oct 20, 2023
1 parent d2237f5 commit 98d8fe0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmp/country-import-to-model-naive-csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# read csv.py
# read csv_file and create a country model for each row in the csv file
# the csv_file has the format "id,name,alpha2,alpha3,country_code"

from cmp.models import Country

csv_file = "/tmp/countries.csv"

with open(csv_file, "r") as f:
for line in f:
line = line.strip()
if line.startswith("#"):
continue
id, name, alpha2, alpha3, old_id, blah = line.split(",")
c = Country(name=name, alpha2=alpha2, alpha3=alpha3, old_id=old_id)
print(c)
c.save()
18 changes: 18 additions & 0 deletions cmp/country-import-to-model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# read csv.py
# read csv_file and create a country model for each row in the csv file
# the csv_file has the format "id,name,alpha2,alpha3,country_code"

from cmp.models import Country

csv_file = "/tmp/countries.csv"

with open(csv_file, "r") as f:
for line in f:
line = line.strip()
if line.startswith("#"):
continue
id, name, alpha2, alpha3, old_id, blah = line.split(",")
c = Country(name=name, alpha2=alpha2, alpha3=alpha3, old_id=old_id)
print(c)
c.save()

0 comments on commit 98d8fe0

Please sign in to comment.