<commit_before>import logging
import urllib2
import xml.etree.ElementTree as ET

from errors import *

class TheTvDb():
    series = ""
    url = 'http://www.thetvdb.com/api/'
    apikey = '<KEY>'
    get_series = 'GetSeries.php?seriesname='
    
    def __init__(self, series_name):
        self.series = series_name
        
    def __get_series_id(self):
        url = self.url + self.get_series + urllib2.quote(self.series)
        try: data = urllib2.urlopen(url).read()
        except urllib2.URLError: raise
        dom = ET.fromstring(data)
        if dom == None: raise Exception('Error retriving XML for for: '+ self.series)
        for name in dom.findall("Series"):
            s = name.find("SeriesName").text
            if s.lower() == self.series.lower():
                self.series = s
                return name.find("seriesid").text
        
    def get_episode_name(self, season, episode):
        series_id = self.__get_series_id()
        episode_url = self.url + self.apikey +'/series/'+ series_id +'/default/'+ str(int(season)) +'/'+ str(int(episode)) +'/en.xml'
        try: f = urllib2.urlopen(episode_url)
        except urllib2.URLError: raise
        dom = ET.fromstring(f.read())
        if dom != None: return dom.find("Episode").find("EpisodeName").text
        else: raise EpisodeNotFoundException(self.series + " - " + season + episode)<commit_msg>added show not found exception<commit_after>import logging
import urllib2
import xml.etree.ElementTree as ET

from errors import *

class TheTvDb():
    series = ""
    url = 'http://www.thetvdb.com/api/'
    apikey = '<KEY>'
    get_series = 'GetSeries.php?seriesname='
    
    def __init__(self, series_name):
        self.series = series_name
        
    def __get_series_id(self):
        url = self.url + self.get_series + urllib2.quote(self.series)
        try: data = urllib2.urlopen(url).read()
        except urllib2.URLError: raise
        dom = ET.fromstring(data)
        if dom == None: raise Exception('Error retriving XML for for: '+ self.series)
        for name in dom.findall("Series"):
            s = name.find("SeriesName").text
            if s.lower() == self.series.lower():
                self.series = s
                return name.find("seriesid").text
            else: raise ShowNotFoundException(self.series)
        
    def get_episode_name(self, season, episode):
        series_id = self.__get_series_id()
        episode_url = self.url + self.apikey +'/series/'+ series_id +'/default/'+ str(int(season)) +'/'+ str(int(episode)) +'/en.xml'
        try: f = urllib2.urlopen(episode_url)
        except urllib2.URLError: raise EpisodeNotFoundException(season+episode)
        dom = ET.fromstring(f.read())
        if dom != None: return dom.find("Episode").find("EpisodeName").text
        else: raise EpisodeNotFoundException(self.series + " - " + season + episode)
{'fraction_non_alphanumeric': 0.1320623916811092, 'fraction_numerical': 0.004159445407279029, 'mean_word_length': 2.5806451612903225, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4346072', 'n_tokens_mistral': 926, 'n_tokens_neox': 903, 'n_words': 197}