Skip to content

Commit

Permalink
Merge branch 'master' of github.com:MythTV/mythtv
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Riendeau committed Mar 26, 2012
2 parents 36cdbfd + 12823e7 commit f404b65
Show file tree
Hide file tree
Showing 7 changed files with 730 additions and 39 deletions.
55 changes: 55 additions & 0 deletions mythtv/bindings/python/MythTV/tmdb3/scripts/populate_locale.py
@@ -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')))

1 change: 1 addition & 0 deletions mythtv/bindings/python/MythTV/tmdb3/tmdb3/__init__.py
Expand Up @@ -3,5 +3,6 @@
from tmdb_api import Configuration, searchMovie, searchPerson, Person, \
Movie, Collection, __version__
from request import set_key, set_cache
from locales import get_locale, set_locale
from tmdb_exceptions import *

0 comments on commit f404b65

Please sign in to comment.