-
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 #103 from gm3dmo/w60
Adding soldiers
Showing
4 changed files
with
40 additions
and
2 deletions.
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
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 Soldier | ||
|
||
def run(): | ||
Ranks = Soldier.objects.all() | ||
Ranks.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,33 @@ | ||
|
||
def run(): | ||
|
||
import sys | ||
import urllib3 | ||
import csv | ||
from cmp.models import Soldier | ||
|
||
ref_data_url = "https://raw.githubusercontent.com/gm3dmo/old-cmp/main/data/soldier.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) | ||
for row in reader: | ||
# id,surname,initials,army_number,rank_id,notes | ||
print(f"""{row['id']} {row['surname']}""") | ||
try: | ||
Soldier.objects.create( | ||
id = row['id'], | ||
surname = row['surname'], | ||
initials = row['initials'], | ||
army_number = row['army_number'], | ||
rank_id = row['rank_id'], | ||
notes = row['notes'] | ||
) | ||
except Exception as e: | ||
print("Error with: " + row['surname']) | ||
|
||
raise e |