Skip to content

Commit

Permalink
Merge pull request #113 from gm3dmo/v70
Browse files Browse the repository at this point in the history
Adding script titles
  • Loading branch information
gm3dmo authored Nov 14, 2023
2 parents 16b80b9 + dc9852e commit 18cc49b
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 3 deletions.
1 change: 1 addition & 0 deletions insertall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ python manage.py runscript insert-all-ranks
python manage.py runscript insert-all-decorations
python manage.py runscript insert-all-companies
python manage.py runscript insert-all-soldiers
python manage.py runscript insert-all-soldier-imprisonments
5 changes: 5 additions & 0 deletions scripts/delete-all-soldier-imprisonments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from cmp.models import SoldierImprisonment

def run():
Imprisonments = SoldierImprisonment.objects.all()
Imprisonments.delete()
8 changes: 7 additions & 1 deletion scripts/insert-all-cemeteries.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@

def run():

import sys
import urllib3
import csv
from cmp.models import Cemetery


print()
title = sys.argv[2]
print(f"""\033[4;33m{title}\033[0m""")
print("-" * len(title))

ref_data_url = "https://raw.githubusercontent.com/gm3dmo/old-cmp/main/data/cemetery.csv"
http = urllib3.PoolManager()
r = http.request('GET', ref_data_url)
Expand Down
5 changes: 5 additions & 0 deletions scripts/insert-all-companies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ def run():
import urllib3
import csv
from cmp.models import Company

print()
title = sys.argv[2]
print(f"""\033[4;33m{title}\033[0m""")
print("-" * len(title))

ref_data_url = "https://raw.githubusercontent.com/gm3dmo/old-cmp/main/data/company.csv"
http = urllib3.PoolManager()
Expand Down
5 changes: 5 additions & 0 deletions scripts/insert-all-countries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ def run():
import urllib3
import csv
from cmp.models import Country

print()
title = sys.argv[2]
print(f"""\033[4;33m{title}\033[0m""")
print("-" * len(title))

#ref_data_url = "https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.csv"
ref_data_url = "https://raw.githubusercontent.com/gm3dmo/old-cmp/main/data/country.csv"
Expand Down
6 changes: 6 additions & 0 deletions scripts/insert-all-decorations.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@

def run():

import sys
import urllib3
import csv
from cmp.models import Decoration

print()
title = sys.argv[2]
print(f"""\033[4;33m{title}\033[0m""")
print("-" * len(title))

ref_data_url = "https://raw.githubusercontent.com/gm3dmo/old-cmp/main/data/decoration.csv"
http = urllib3.PoolManager()
Expand Down
8 changes: 6 additions & 2 deletions scripts/insert-all-pow-camps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ def run():
import urllib3
import csv
from cmp.models import PowCamp


print()
title = sys.argv[2]
print(f"""\033[4;33m{title}\033[0m""")
print("-" * len(title))

ref_data_url = "https://raw.githubusercontent.com/gm3dmo/old-cmp/main/data/pow-camp.csv"
http = urllib3.PoolManager()
Expand All @@ -16,8 +22,6 @@ def run():
# add a country model for each row in the csv file
for row in reader:
print(f""" {row['id']} {row['Name']} ({row['PresentCountry_id']}) {row['WartimeCountry']} {row['Latitude']} {row['Longitude']}""")
if int(row["id"]) == 59:
break
try:
PowCamp.objects.create(
id=row['id'],
Expand Down
6 changes: 6 additions & 0 deletions scripts/insert-all-ranks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@

def run():

import sys
import urllib3
import csv
from cmp.models import Rank

print()
title = sys.argv[2]
print(f"""\033[4;33m{title}\033[0m""")
print("-" * len(title))

ref_data_url = "https://raw.githubusercontent.com/gm3dmo/old-cmp/main/data/rank.csv"
http = urllib3.PoolManager()
Expand Down
40 changes: 40 additions & 0 deletions scripts/insert-all-soldier-imprisonments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

def run():

import sys
import urllib3
import csv
from cmp.models import SoldierImprisonment

print()
title = sys.argv[2]
print(f"""\033[4;33m{title}\033[0m""")
print("-" * len(title))

ref_data_url = "https://raw.githubusercontent.com/gm3dmo/old-cmp/main/data/soldier-imprisonment.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())
# breakpoint()
print(reader)
# print(reader.fieldnames)
# id,soldier_id,company_id,powNumber,powCamp_id,dateFrom,dateTo,notes
for row in reader:
print(f"""SoldierImprisonment: {row['id']} {row['soldier_id']} """)
try:
SoldierImprisonment.objects.create(
id = row['id'],
soldier_id = row['soldier_id'],
legacy_company = row['company_id'],
pow_number = row['powNumber'],
pow_camp_id = row['powCamp_id'],
legacy_date_from = row['dateFrom'],
legacy_date_to = row['dateTo'],
notes = row['notes']
)
except Exception as e:
print("Error with: " + row['id'])

raise e
5 changes: 5 additions & 0 deletions scripts/insert-all-soldiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ def run():
import urllib3
import csv
from cmp.models import Soldier

print()
title = sys.argv[2]
print(f"""\033[4;33m{title}\033[0m""")
print("-" * len(title))

ref_data_url = "https://raw.githubusercontent.com/gm3dmo/old-cmp/main/data/soldier.csv"
http = urllib3.PoolManager()
Expand Down

0 comments on commit 18cc49b

Please sign in to comment.