Пример #1
0
def main():
    today = datetime.date.today()

    results = Scrapper.getTracks()
    titles = Playlist.clean(results)
    formatted_titles = Playlist.format(titles)

    known_titles = []
    if r.exists("playlist"):
        known_titles = list(map(
            pickle.loads,
            r.lrange("playlist", 0, -1),
        ))

    unknown_titles = list(
        filter(lambda title: title not in known_titles, formatted_titles))

    for title in unknown_titles:
        r.lpush("playlist", pickle.dumps(title))

        message = "{} ({}/{})\n{}\n{}".format(title["time"], today.day,
                                              today.month,
                                              title["artist_album"],
                                              title["track_title"])
        Tooter.toot(message)

    r.ltrim("playlist", 0, 49)
Пример #2
0
    def test_clean_method_remove_jingle(self):
        cleaned_playlist = Playlist.clean(self.results)
        jingle = BeautifulSoup(
            "<td class='Cell'>21:01:05<br><br/>Astrid RM.com (Jingle)</td>",
            "html.parser"
        )

        self.assertTrue(str(jingle) != str(cleaned_playlist[2]))
Пример #3
0
    def test_clean_method_keeps_titles_containing_jingle(self):
        cleaned_playlist = Playlist.clean(self.results)
        jingle_title = BeautifulSoup(
            "<td class='Cell'>20:27:02<br>Fake title containing Jingle<br/>So fake</td>",
            "html.parser"
        )

        self.assertTrue(str(jingle_title) == str(cleaned_playlist[-2]))
Пример #4
0
    def test_clean_method_keeps_titles_containing_ellipsis(self):
        cleaned_playlist = Playlist.clean(self.results)
        ellipsis_title = BeautifulSoup(
            "<td class='Cell'>20:22:45<br>Fake title containing ...<br/>So fake</td>",
            "html.parser"
        )

        self.assertTrue(str(ellipsis_title) == str(cleaned_playlist[-1]))
Пример #5
0
    def test_clean_method_remove_upcoming_title(self):
        cleaned_playlist = Playlist.clean(self.results)
        upcoming_title = BeautifulSoup(
            "<td class='Cell'>...<br>El Michels Affair - Return to the 37th Chamber<br/>Verbal Intercourse (R&B)</td>",
            "html.parser"
        )

        self.assertTrue(str(upcoming_title) != str(cleaned_playlist[0]))
Пример #6
0
    def test_clean_method_returns_rest_of_titles(self):
        cleaned_playlist = Playlist.clean(self.results)

        self.assertEqual(len(cleaned_playlist), 8)