Пример #1
0
    def find_new_entries(self):
        """Find all new entries in all feeds
        """
        new_entries = []

        for rss_feed_url in config().get_key('FEED_URLS'):
            for entry in feed.get_rss_feed_entries(rss_feed_url):
                try:
                    # find out if it's new
                    self.db.query_torrents().filter_by(name=entry['title']).one()
                except NoResultFound:
                    # it's new
                    db_entry = db.Torrent(entry['title'], entry['link'])

                    # save it to the database
                    if not self.db.save_torrent(db_entry):
                        log.warning("Unable to commit torrent to database: %s", db_entry.name)
                        raise Exception("Unable to commit torrent to database: %s" % db_entry.name)

                    new_entries.append(db_entry)

                    # notify the app that a new torrent was seen
                    evt = NewTorrentSeenEvent()
                    evt.torrent = db_entry
                    wx.PostEvent(wx.GetApp(), evt)
                else:
                    # not new. ignore
                    continue

        return new_entries
Пример #2
0
def test_feed_parsing():
    feed.urllib2.urlopen = fake_urllib2_urlopen

    rss_entries = list(feed.get_rss_feed_entries('fake url'))

    assert len(rss_entries) == 3

    assert rss_entries[2]['title'] == 'Some.Show.S01E02.Name.of.the.Episode.HDTV.XviD-ASDF'
    assert rss_entries[2]['link'] == 'http://test.me/download/torrent/1/'
    assert rss_entries[2]['description'] == 'Some Show: Name of the Episode'

    assert rss_entries[1]['title'] == 'Some.Other.Show.S01E03.Other.Name.of.the.Episode.720p.HDTV.x264-QWERTY'
    assert rss_entries[1]['link'] == 'http://test.me/download/torrent/2/'
    assert rss_entries[1]['description'] == 'Some Other Show: Other Name of the Episode'

    assert rss_entries[0]['title'] == 'Last.Show.S01E04.Last.Name.HDTV.XviD-ZXCV'
    assert rss_entries[0]['link'] == 'http://test.me/download/torrent/3/'
    assert rss_entries[0]['description'] == 'Last Show: Last Name'