Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
Merge pull request #49 from guillp/fixes
Browse files Browse the repository at this point in the history
small fixes and typos
  • Loading branch information
jamesmeneghello committed Feb 25, 2014
2 parents 0830be5 + 3df740f commit f95cf60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
35 changes: 17 additions & 18 deletions pynab/tvrage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytz
import pymongo
from lxml import etree
from collections import defaultdict

from pynab.db import db
from pynab import log
Expand Down Expand Up @@ -140,32 +141,30 @@ def search_lxml(show, content):
log.error('Problem parsing XML with lxml')
return None

from itertools import chain

matches = {}
matches = defaultdict(list)
# parse show names in the same order as returned by tvrage, first one is usually the good one
for xml_show in XPATH_SHOW(tree):
for name in extract_names(xml_show):
ratio = int(difflib.SequenceMatcher(None, show['clean_name'], clean_name(name)).ratio() * 100)
if ratio == 100:
log.debug('lxml Found 100% xml_match: {}'.format(name))
log.debug('Found 100% xml_match: {}'.format(name))
return xmltodict.parse(etree.tostring(xml_show))['show']
matches[ratio] = xml_show
matches[ratio].append(xml_show)

# if no 100% is found, check highest ratio matches
for ratio, xml_match in sorted(matches.items(), reverse=True):
if ratio >= 80:
log.debug('lxml Found {:d}% xml_match: {}'.format(ratio, XPATH_NAME(xml_match)[0]))
return xmltodict.parse(etree.tostring(xml_match))['show']
elif 80 > ratio > 60:
if 'country' in show and show['country'] and XPATH_COUNTRY(xml_match):
if str.lower(show['country']) == str.lower(XPATH_COUNTRY(xml_match)):
log.debug('lxml Found {:d}% xml_match: {}'.format(ratio, XPATH_NAME(xml_match)[0]))
return xmltodict.parse(etree.tostring(xml_match))['show']

ratio, highest = sorted(matches.items(), reverse=True)[0]
log.warning('No TVRage match found for {}.'.format(show['clean_name']))
log.debug('lxml highest xml_match was {}% with {}.'.format(ratio, XPATH_NAME(highest)[0]))
for ratio, xml_matches in sorted(matches.items(), reverse=True):
for xml_match in xml_matches:
if ratio >= 80:
log.debug('Found {:d}% xml_match: {}'.format(ratio, XPATH_NAME(xml_match)[0]))
return xmltodict.parse(etree.tostring(xml_match))['show']
elif 80 > ratio > 60:
if 'country' in show and show['country'] and XPATH_COUNTRY(xml_match):
if str.lower(show['country']) == str.lower(XPATH_COUNTRY(xml_match)):
log.debug('Found {:d}% xml_match: {}'.format(ratio, XPATH_NAME(xml_match)[0]))
return xmltodict.parse(etree.tostring(xml_match))['show']

ratio, highests = sorted(matches.items(), reverse=True)[0]
log.warning('No TVRage match found for {}, highest match was {}%.'.format(show['clean_name'], ratio))


def clean_name(name):
Expand Down
9 changes: 3 additions & 6 deletions scripts/groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/local/bin/python2.7
# encoding: utf-8

import argparse
import os
import re
Expand Down Expand Up @@ -75,7 +72,7 @@ def remove(args):
for group in groups:
db.groups.remove(group['_id'])
if skipped_names:
print('These groups where not in the database and where skipped:')
print('These groups were not in the database and were skipped:')
for name in skipped_names:
print(' ', name)

Expand All @@ -84,7 +81,7 @@ def enable(args):
for group in groups:
db.groups.update({'_id': group['_id']}, {'$set': {'active': 1}})
if skipped_names:
print('These groups where not in the database and where skipped:')
print('These groups were not in the database and were skipped:')
for name in skipped_names:
print(' ', name)

Expand All @@ -93,7 +90,7 @@ def disable(args):
for group in groups:
db.groups.update({'_id': group['_id']}, {'$set': {'active': 0}})
if skipped_names:
print('These groups where not in the database and where skipped:')
print('These groups were not in the database and were skipped:')
for name in skipped_names:
print(' ', name)

Expand Down

0 comments on commit f95cf60

Please sign in to comment.