Skip to content

Commit

Permalink
Merge pull request #101 from gm3dmo/w57
Browse files Browse the repository at this point in the history
Adding decorations scripts
  • Loading branch information
gm3dmo authored Nov 7, 2023
2 parents 2746ed9 + 879bb5f commit a43a01e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion railway.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python manage.py makemigrations && python manage.py migrate && python manage.py runscript delete-all-countries && python manage.py runscript insert-all-countries && python manage.py runscript insert-all-cemeteries && python manage.py runscript insert-all-ranks && python manage.py runscript add-flags-to-countries && python manage.py runscript insert-all-pow-camps && python manage.py collectstatic && python manage.py runserver 0.0.0.0:$PORT",
"startCommand": "python manage.py makemigrations && python manage.py migrate && python manage.py runscript delete-all-countries && python manage.py runscript insert-all-countries && python manage.py runscript add-flags-to-countries && python manage.py runscript insert-all-pow-camps && python manage.py runscript insert-all-decorations && python manage.py collectstatic && python manage.py runserver 0.0.0.0:$PORT",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
Expand Down
5 changes: 5 additions & 0 deletions scripts/delete-all-decorations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from cmp.models import Decoration

def run():
Ranks = Decoration.objects.all()
Ranks.delete()
27 changes: 27 additions & 0 deletions scripts/insert-all-decorations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

def run():

import urllib3
import csv
from cmp.models import Decoration

ref_data_url = "https://raw.githubusercontent.com/gm3dmo/old-cmp/main/data/decoration.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())

# add a country model for each row in the csv file
for row in reader:
print(row['id'])
try:
Decoration.objects.create(
id=row['id'],
name=row['name'],
country_id=row['country_id'],
details_link=row['details_link']
)
except Exception as e:
print("Error with: " + row['name'])
raise e

0 comments on commit a43a01e

Please sign in to comment.