Skip to content

Commit

Permalink
Merge pull request #102 from gm3dmo/w59
Browse files Browse the repository at this point in the history
Adding companies to railway.json
  • Loading branch information
gm3dmo authored Nov 7, 2023
2 parents a43a01e + 81fb8fd commit 75272e7
Show file tree
Hide file tree
Showing 3 changed files with 32 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 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",
"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 runscript insert-all-companies && 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-companies.py
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()
26 changes: 26 additions & 0 deletions scripts/insert-all-companies.py
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

0 comments on commit 75272e7

Please sign in to comment.