Last active
July 4, 2017 12:31
-
-
Save arsenlosenko/2e223a8a1cb0cbf27e54973783cbb167 to your computer and use it in GitHub Desktop.
Script for import of json data into database
This file contains hidden or 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
import subprocess | |
import json | |
import sys | |
#from imp import reload | |
#reload(sys) | |
#sys.setdefaultencoding('utf-8') | |
with open('country_codes.json', encoding='utf-8', ) as data_file: | |
data = json.load(data_file) | |
for item in data: | |
print('{}\n{}\n{}\n{}\n{}\n{}\n'.format(item["ISO3166-1-Alpha-2"], | |
item["ISO4217-currency_country_name"], | |
item["name"], | |
item["ISO3166-1-Alpha-3"], | |
item["M49"], | |
item["Dial"])) | |
subprocess.call(['psql', 'application', '-c', "insert into country (iso, name, nicename, iso3, numcode, phonecode) values ('{}','{}','{}','{}','{}','{}')".format(item["ISO3166-1-Alpha-2"], | |
item["ISO4217-currency_country_name"], | |
item["name"], | |
item["ISO3166-1-Alpha-3"], | |
item["M49"], | |
item["Dial"].encode('utf-8','strict'))]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment