seitime-frappe/frappe/geo/country_info.py
2014-09-29 12:21:12 +05:30

42 lines
1.2 KiB
Python

# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
# all country info
from __future__ import unicode_literals
import os, json, frappe
from frappe.utils.momentjs import get_all_timezones
def get_country_info(country=None):
data = get_all()
data = frappe._dict(data.get(country, {}))
if not 'date_format' in data:
data.date_format = "dd-mm-yyyy"
return data
def get_all():
with open(os.path.join(os.path.dirname(__file__), "country_info.json"), "r") as local_info:
all_data = json.loads(local_info.read())
return all_data
@frappe.whitelist()
def get_country_timezone_info():
return {
"country_info": get_all(),
"all_timezones": get_all_timezones()
}
def update():
with open(os.path.join(os.path.dirname(__file__), "currency_info.json"), "r") as nformats:
nformats = json.loads(nformats.read())
all_data = get_all()
for country in all_data:
data = all_data[country]
data["number_format"] = nformats.get(data.get("currency", "default"),
nformats.get("default"))["display"]
with open(os.path.join(os.path.dirname(__file__), "country_info.json"), "w") as local_info:
local_info.write(json.dumps(all_data, indent=1))