Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:MythTV/mythtv
- Loading branch information
Showing
7 changed files
with
730 additions
and
39 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
mythtv/bindings/python/MythTV/tmdb3/scripts/populate_locale.py
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,55 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
#----------------------- | ||
# Name: populate_locale.py Helper for grabbing ISO639 and ISO3316 data | ||
# Python Library | ||
# Author: Raymond Wagner | ||
#----------------------- | ||
|
||
import lxml.html | ||
import sys | ||
import os | ||
|
||
def sanitize(name): | ||
name = ' '.join(name.split()) | ||
return name | ||
|
||
fpath = os.path.join(os.getcwd(), __file__) if not __file__.startswith('/') else __file__ | ||
fpath = os.path.join(fpath.rsplit('/',2)[0], 'tmdb3/locales.py') | ||
|
||
fd = open(fpath, 'r') | ||
while True: | ||
line = fd.readline() | ||
if len(line) == 0: | ||
print "code endpoint not found, aborting!" | ||
sys.exit(1) | ||
if line.startswith('########'): | ||
endpt = fd.tell() | ||
break | ||
|
||
fd = open(fpath, 'a') | ||
fd.seek(endpt) | ||
fd.truncate() | ||
fd.write('\n') | ||
|
||
root = lxml.html.parse('http://www.loc.gov/standards/iso639-2/php/English_list.php') | ||
for row in root.getroot().getchildren()[3].getchildren()[2].getchildren()[0]\ | ||
.getchildren()[0].getchildren()[9]: | ||
if row.getchildren()[0].tag == "th": | ||
# skip header | ||
continue | ||
if row.getchildren()[-1].text == u"\xa0": | ||
# skip empty 639-1 code | ||
continue | ||
name, _, _, iso639_2, iso639_1 = [t.text for t in row] | ||
|
||
fd.write('Language("{0}", "{1}", u"{2}")\n'.format(iso639_1, iso639_2, sanitize(name).encode('utf8'))) | ||
|
||
root = lxml.html.parse('http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm').getroot() | ||
for row in root.get_element_by_id('tc_list'): | ||
if row.tag == 'thead': | ||
# skip header | ||
continue | ||
name, _, alpha2 = [t.text if t.text else t.getchildren()[0].tail for t in row] | ||
fd.write('Country("{0}", u"{1}")\n'.format(alpha2, sanitize(name).encode('utf8'))) | ||
|
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
Oops, something went wrong.