Пример #1
0
 def searchshow(self, name):
     '''
     @type name: str
     @rtype: list
     '''
     data = self._request('http://www.thetvdb.com/api/GetSeries.php?seriesname=%s' % name)
     
     xml = QDomDocument()
     xml.setContent(data)
     
     showsxml = xml.elementsByTagName('Series')
     shows = []
     
     for i in range(len(showsxml)):
         newshow = show()
         newshow.id = unicode(QString(showsxml.at(i).toElement().elementsByTagName('seriesid').at(0).childNodes().at(0).toText().data()))
         newshow.name = unicode(QString(showsxml.at(i).toElement().elementsByTagName('SeriesName').at(0).childNodes().at(0).toText().data()))
         newshow.description = unicode(QString(showsxml.at(i).toElement().elementsByTagName('Overview').at(0).childNodes().at(0).toText().data()))
         newshow.image = unicode(QString(showsxml.at(i).toElement().elementsByTagName('banner').at(0).firstChild().toText().data()))
         newshow.data = showsxml.at(i).toElement()
         
         if len(newshow.image):
             self._download(urljoin(urljoin(choice(self.__mirrors[1]), '/banners/'), newshow.image), newshow.image)
         
         shows.append(newshow)
         
     return shows
Пример #2
0
    def getlocalshows(self):
        '''
        @rtype: list
        '''
        shows = []
        
        if self._storage.exists('shows'):
            showdirs = self._storage.listdir('shows')
            
            for showdir in showdirs:
                data = self._storage.getdata('shows/%s/en.xml' % showdir)
                
                if data != None:
                    xml = QDomDocument()
                    xml.setContent(data)
            
                    showxml = xml.elementsByTagName('Series').at(0)
                    
                    newshow = show()
                    newshow.id = unicode(QString(showxml.toElement().elementsByTagName('id').at(0).childNodes().at(0).toText().data()))
                    newshow.name = unicode(QString(showxml.toElement().elementsByTagName('SeriesName').at(0).childNodes().at(0).toText().data()))
                    newshow.description = unicode(QString(showxml.toElement().elementsByTagName('Overview').at(0).childNodes().at(0).toText().data()))
                    newshow.image = unicode(QString(showxml.toElement().elementsByTagName('banner').at(0).firstChild().toText().data()))
                    newshow.data = showxml.toElement()
                    
                    newshow.actors = unicode(QString(showxml.toElement().elementsByTagName('Actors').at(0).childNodes().at(0).toText().data())).strip('|').split('|')
                    newshow.contentrating = unicode(QString(showxml.toElement().elementsByTagName('ContentRating').at(0).childNodes().at(0).toText().data()))

                    firstaired = unicode(QString(showxml.toElement().elementsByTagName('FirstAired').at(0).childNodes().at(0).toText().data()))
                    if firstaired != '':
                        newshow.firstaired = datetime.fromtimestamp(mktime(strptime(firstaired, '%Y-%m-%d')))
                    else:
                        newshow.firstaired = datetime.now()

                    newshow.genre = unicode(QString(showxml.toElement().elementsByTagName('Genre').at(0).childNodes().at(0).toText().data())).strip('|').split('|')
                    newshow.imdb = unicode(QString(showxml.toElement().elementsByTagName('IMDB_ID').at(0).childNodes().at(0).toText().data()))
                    newshow.network = unicode(QString(showxml.toElement().elementsByTagName('Network').at(0).childNodes().at(0).toText().data()))

                    rating = unicode(QString(
                        showxml.toElement().elementsByTagName('Rating').at(0).childNodes().at(0).toText().data()))

                    if rating != '':
                        newshow.rating = float(rating)
                    else:
                        newshow.rating = 0.0

                    newshow.runtime = int(unicode(QString(showxml.toElement().elementsByTagName('Runtime').at(0).childNodes().at(0).toText().data())))
                    newshow.status = unicode(QString(showxml.toElement().elementsByTagName('Status').at(0).childNodes().at(0).toText().data()))
                    
                    shows.append(newshow)
        
        return shows
Пример #3
0
    def test_show(self):
        obj = show(u'a', u'b', u'c', u'd', 1, [u'a'], u'e', datetime.min, [u'b'], u'f', u'g', 2.1, 3, u'h')
        self.assertEqual(obj.name, u'a', 'name is assigned incorrectly')
        self.assertEqual(obj.description, u'b', 'description is assigned incorrectly')
        self.assertEqual(obj.image, u'c', 'image is assigned incorrectly')
        self.assertEqual(obj.id, u'd', 'id is assigned incorrectly')
        self.assertEqual(obj.data, 1, 'data is assigned incorrectly')

        self.assertEqual(obj.actors, [u'a'], 'actors is assigned incorrectly')
        self.assertEqual(obj.contentrating, u'e', 'contentrating is assigned incorrectly')
        self.assertEqual(obj.firstaired, datetime.min, 'firstaired is assigned incorrectly')
        self.assertEqual(obj.genre, [u'b'], 'genre is assigned incorrectly')
        self.assertEqual(obj.imdb, u'f', 'imdb is assigned incorrectly')
        self.assertEqual(obj.network, u'g', 'network is assigned incorrectly')
        self.assertEqual(obj.rating, 2.1, 'rating is assigned incorrectly')
        self.assertEqual(obj.runtime, 3, 'runtime is assigned incorrectly')
        self.assertEqual(obj.status, u'h', 'status is assigned incorrectly')
        
        self.assertRaises(exceptions.TypeError, show, (1, 1, 1, 1, None, '', '', 1, 1, '', 1, 1, '', '', 1))