support pycountry if iso-639 is not available

pull/869/head
Daniel Pavel 6 years ago
parent 4b301a7961
commit f7e640fd98

@ -21,7 +21,7 @@ import zipfile
from lxml import etree from lxml import etree
import os import os
import uploader import uploader
from iso639 import languages as isoLanguages import isoLanguages
def extractCover(zipFile, coverFile, coverpath, tmp_file_name): def extractCover(zipFile, coverFile, coverpath, tmp_file_name):

@ -0,0 +1,28 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
try:
from iso639 import languages, __version__
get = languages.get
except ImportError:
from pycountry import languages as pyc_languages
try:
import pkg_resources
__version__ = pkg_resources.get_distribution('pycountry').version + ' (PyCountry)'
del pkg_resources
except:
__version__ = "? (PyCountry)"
def _copy_fields(l):
l.part1 = l.alpha_2
l.part3 = l.alpha_3
return l
def get(name=None, part1=None, part3=None):
if (part3 is not None):
return _copy_fields(pyc_languages.get(alpha_3=part3))
if (part1 is not None):
return _copy_fields(pyc_languages.get(alpha_2=part1))
if (name is not None):
return _copy_fields(pyc_languages.get(name=name))

@ -61,8 +61,7 @@ import base64
from sqlalchemy.sql import * from sqlalchemy.sql import *
import json import json
import datetime import datetime
from iso639 import languages as isoLanguages import isoLanguages
from iso639 import __version__ as iso639Version
from pytz import __version__ as pytzVersion from pytz import __version__ as pytzVersion
from uuid import uuid4 from uuid import uuid4
import os.path import os.path
@ -1657,7 +1656,7 @@ def stats():
versions['Flask'] = 'v' + flaskVersion versions['Flask'] = 'v' + flaskVersion
versions['Flask Login'] = 'v' + flask_loginVersion versions['Flask Login'] = 'v' + flask_loginVersion
versions['Flask Principal'] = 'v' + flask_principalVersion versions['Flask Principal'] = 'v' + flask_principalVersion
versions['Iso 639'] = 'v' + iso639Version versions['Iso 639'] = 'v' + isoLanguages.__version__
versions['pytz'] = 'v' + pytzVersion versions['pytz'] = 'v' + pytzVersion
versions['Requests'] = 'v' + requests.__version__ versions['Requests'] = 'v' + requests.__version__

Loading…
Cancel
Save