-
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 #95 from gm3dmo/w44
w44
- Loading branch information
Showing
11 changed files
with
93 additions
and
342 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,30 @@ | ||
|
||
def run(): | ||
|
||
import sys | ||
import urllib3 | ||
import csv | ||
from cmp.models import Country | ||
|
||
ref_data_url = "https://raw.githubusercontent.com/mledoze/countries/master/dist/countries.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()) | ||
|
||
# create a dictionary from the reader with key ccna2 and value flag | ||
flags = {row['cca2']: row['flag'] for row in reader} | ||
|
||
print(flags['GB']) | ||
|
||
# for every country in the database, add the flag if the country is in the dictionary | ||
for country in Country.objects.all(): | ||
if country.Alpha2 in flags: | ||
country.Flag = flags[country.Alpha2] | ||
country.save() | ||
print(f"""{country.name} {country.Alpha2} {country.Flag}""") | ||
else: | ||
print(f"""{country.name} {country.Alpha2} no flag""") | ||
|
||
|
Oops, something went wrong.