Пример #1
0
def table_build(data):
    keys = data.keys
    count = 0
    table = ''
    master_body = ''
    # flight_content = ''
    # mma_content = ''
    # regural_content = ''

    latest_year = last_year(data)

    for key in keys():
        p = Podcast()
        p.from_json_file(key, data[key])

        if (year(p)) < latest_year:
            table += interim_table(master_body, latest_year)
            latest_year -= 1
            master_body = ''

        table_content = wiki_entry(p)
        # print(table_content)
        if table_content[0] == 'Master':
            master_body += table_content[1]
        # if table_content[0] == 'Fight':
        #     flight_content += table_content[1]
        # elif table_content[0] == 'MMA':
        #     mma_content += table_content[1]
        # else:
        #     regural_content += table_content[1]

    return table  # flight_content, mma_content, regural_content
Пример #2
0
 def download(self, shortname, epId):
     self.load()
     if shortname not in self.listOfPodcasts:
         print '"{}" not in list of podcasts'.format(shortname)
     else:
         p = Podcast('', self.rootDir, shortname)
         p.download(epId)
Пример #3
0
 def show(self, shortname):
     self.load()
     if shortname not in self.listOfPodcasts:
         print '"{}" not in list of podcasts'.format(shortname)
     else:
         p = Podcast('', self.rootDir, shortname)
         p.showEpisodes()
Пример #4
0
def test2():
    # First podcast
    podcast1 = Podcast("Do Aliens Exist?", "Joe Rogan", "1:53:02",
                       "/desktop/made_up_folder/podcast",
                       "do_aliens_exist.wav", "JRE",
                       datetime.date(2019, 6, 15), datetime.time(0))

    print()

    # Second podcast
    podcast2 = Podcast("Eddie Bravo argues over flat earth", "Joe Rogan",
                       "25:08", "/desktop/made_up_folder/podcast",
                       "eddie_bravo_earth.wav", "JRE",
                       datetime.date(2019, 9, 7), datetime.time(0))
Пример #5
0
def deleteAPI(audioFileType, audioFileID):
    if request.method == "DELETE":
        if audioFileType == "song":
            obj = Song()
            if obj.deleteItem(database, audioFileID):
                return success()

            else:
                return notfoundError()

        elif audioFileType == "podcast":
            obj = Podcast()
            if obj.deleteItem(database, audioFileID):
                return success()
            else:
                return notfoundError()

        elif audioFileType == "audiobook":
            obj = Audiobook()
            if obj.deleteItem(database, audioFileID):
                return success()
            else:
                return notfoundError()

        else:
            return notfoundError()

    else:
        return notfoundError()
Пример #6
0
def updateAPI(audioFileType, audioFileID):
    if request.method == "PUT":
        res = request.json
        metadata = res.get("audioFileMetadata", None)
        if audioFileType == "song":
            obj = Song()
            if obj.updateItem(database, metadata):
                return success()
            else:
                return notfoundError()

        elif audioFileType == "podcast":
            obj = Podcast()
            if obj.updateItem(database, metadata):
                return success()
            else:
                return notfoundError()

        elif audioFileType == "audiobook":
            obj = Audiobook()
            if obj.updateItem(database, metadata):
                return success()
            else:
                return notfoundError()

        else:
            notfoundError()

    else:
        notfoundError()
Пример #7
0
def createAPI():
    if request.method == "POST":
        req = request.json
        audioFileType = req["audioFileType"]
        metadata = req.get("audioFileMetadata", None)
        if audioFileType == "song":
            obj = Song()
            obj.Add(database, metadata)
            return success()

        elif audioFileType == "podcast":
            obj = Podcast()
            if obj.Add(database, metadata):
                return success()
            return notfoundError()

        elif audioFileType == "audiobook":
            obj = Audiobook()
            obj.Add(database, metadata)
            return success()

        else:
            return notfoundError()

    else:
        return notfoundError()
Пример #8
0
    def podcast(self, uuid):
        response = self._session.post("https://play.pocketcasts.com"
                                      "/web/podcasts/podcast.json",
                                      json={'uuid': uuid})
        response.raise_for_status()
        response_json = response.json()
        podcast = Podcast._from_json(response_json['podcast'], self)

        return podcast
Пример #9
0
    def trending_podcasts(self):
        response = self._session.get("https://static.pocketcasts.com"
                                     "/discover/json/trending.json")
        response.raise_for_status()

        podcasts = []
        for podcast_json in response.json()['result']['podcasts']:
            podcast = Podcast._from_json(podcast_json, self)
            podcasts.append(podcast)
        return podcasts
Пример #10
0
    def my_podcasts(self):
        response = self._session.post("https://play.pocketcasts.com"
                                      "/web/podcasts/all.json")
        response.raise_for_status()

        podcasts = []
        for podcast_json in response.json()['podcasts']:
            podcast = Podcast._from_json(podcast_json, self)
            podcasts.append(podcast)
        return podcasts
Пример #11
0
 def remove(self, shortname):
     self.load()
     if not shortname in self.listOfPodcasts:
         print '"{}" not in list of podcasts'.format(shortname)
     else:
         del self.listOfPodcasts[shortname]
         p = Podcast('', self.rootDir, shortname)
         shutil.rmtree(p.podcastDir)
         print '"{}" removed from list of podcasts'.format(shortname)
         self.dump()
Пример #12
0
 def add(self, url, shortname):
     self.load()
     if shortname in self.listOfPodcasts:
         print '"{}" already in list of podcasts'.format(shortname)
         print 'check pyCast show "{}"'.format(shortname)
     else:
         """
   1) check for validity of feed
   2) save to dist
   3) run podcast Update
   """
         newPodcast = Podcast(url, self.rootDir, shortname)
         if newPodcast.updateFeed():
             self.listOfPodcasts[shortname] = url
             print "{}:{} added to list of podcasts".format(shortname, url)
             self.dump()
         else:
             del newPodcast
             print "{}:{} cound not be added.".format(shortname, url)
Пример #13
0
    def search_podcasts(self, search_string):
        params = {'term': search_string}
        response = self._session.get("https://play.pocketcasts.com"
                                     "/web/podcasts/search.json",
                                     data=params)
        response.raise_for_status()

        podcasts = []
        for podcast_json in response.json()['podcasts']:
            podcast = Podcast._from_json(podcast_json, self)
            podcasts.append(podcast)
        return podcasts
Пример #14
0
    def datos_podcast(self):
        """Sacamos los datos pertinentes de cada podcast"""

        self.sacar_secciones_html()

        for i in range(0, 10):
            podcast = Podcast()

            podcast.twitter = self.obtener_twitter(i)
            podcast.invitado = self.obtener_invitado(i)
            podcast.numero = self.obtener_numero(i)
            podcast.fecha = self.obtener_fecha(i)
            podcast.descripcion = self.obtener_descripcion(i)

            if len(
                    podcast.twitter
            ) > 0 or podcast.invitado is not None or podcast.numero is not None or podcast.fecha is not None or podcast.descripcion is not None:
                self.lista_podcasts.append(podcast)
Пример #15
0
 def setUp(self):
     """Sets up each test by initializing default objects"""
     self.logPoint()
     self.podcastdefault = Podcast('Fight Companion #046', 'Joe Rogan',
                                   '240:00',
                                   r'.\Podcasts\Fight Companion #046.mp3',
                                   'The Joe Rogan Experience',
                                   datetime.datetime(2020, 1, 9))
     self.podcastseason = Podcast('Fight Companion #046', 'Joe Rogan',
                                  '240:00',
                                  r'.\Podcasts\Fight Companion #046.mp3',
                                  'The Joe Rogan Experience',
                                  datetime.datetime(2020, 1, 9), '2020')
     self.podcastall = Podcast('Fight Companion #046', 'Joe Rogan',
                               '240:00',
                               r'.\Podcasts\Fight Companion #046.mp3',
                               'The Joe Rogan Experience',
                               datetime.datetime(2020, 1, 9), '2020', 17)
Пример #16
0
class TestPodcast(unittest.TestCase):
    """A class that holds the tests to be run


        Roy Ortega - A01078553
        ACIT 2515 - Set B
        February 13, 2020
    """
    def setUp(self):
        """Sets up each test by initializing default objects"""
        self.logPoint()
        self.podcastdefault = Podcast('Fight Companion #046', 'Joe Rogan',
                                      '240:00',
                                      r'.\Podcasts\Fight Companion #046.mp3',
                                      'The Joe Rogan Experience',
                                      datetime.datetime(2020, 1, 9))
        self.podcastseason = Podcast('Fight Companion #046', 'Joe Rogan',
                                     '240:00',
                                     r'.\Podcasts\Fight Companion #046.mp3',
                                     'The Joe Rogan Experience',
                                     datetime.datetime(2020, 1, 9), '2020')
        self.podcastall = Podcast('Fight Companion #046', 'Joe Rogan',
                                  '240:00',
                                  r'.\Podcasts\Fight Companion #046.mp3',
                                  'The Joe Rogan Experience',
                                  datetime.datetime(2020, 1, 9), '2020', 17)

    def tearDown(self):
        """Introduces an end log point for each test"""
        self.logPoint()

    def logPoint(self):
        """Creates the log point function to be run after each set up and tear down"""
        currentTest = self.id().split('.')[-1]
        callingFunction = inspect.stack()[1][3]
        print('in %s - %s()' % (currentTest, callingFunction))

    def test_constructor_creation(self):
        """TP-010A Tests the successful creation of a Podcast and Audio class"""
        self.assertIsInstance(self.podcastdefault, Podcast)
        self.assertIsInstance(self.podcastseason, AudioFile)
        self.assertIsInstance(self.podcastseason, Podcast)
        self.assertIsInstance(self.podcastall, Podcast)

    def test_constructor_path(self):
        """TP-010B Tests for a valid file path"""
        self.assertRaises(FileNotFoundError, Podcast, 'Fight Companion #046',
                          'Joe Rogan', '240:00',
                          r'.\Pdcasts\Fight Companion #046.mp3',
                          'The Joe Rogan Experience',
                          datetime.datetime(2020, 1, 9), '2020', 17)

    def test_constructor_invalid(self):
        """TP-010C Tests invalid arguments of a Podcast"""
        self.assertRaises(ValueError, Podcast, 1, 'Joe Rogan', '240:00',
                          r'.\Podcasts\Fight Companion #046.mp3',
                          'The Joe Rogan Experience',
                          datetime.datetime(2020, 1, 9), '2020', 17)
        self.assertRaises(TypeError, Podcast, 1, 'Joe Rogan', '240:00',
                          r'.\Podcasts\Fight Companion #046.mp3',
                          'The Joe Rogan Experience')

    def test_get_description_valid(self):
        """TP-020A Tests if the description returns a valid string"""
        self.assertEqual(type(self.podcastdefault.get_description()), str,
                         "Should return a string")

    def test_get_description_output(self):
        """TP-020B Tests the proper output of a description"""
        self.assertEqual(
            self.podcastdefault.get_description(),
            'The Joe Rogan Experience: Fight Companion #046, January 09 (0 mins)'
        )
        self.assertEqual(
            self.podcastseason.get_description(),
            'The Joe Rogan Experience: Fight Companion #046, January 09, Season 2020 (0 mins)'
        )
        self.assertEqual(
            self.podcastall.get_description(),
            'The Joe Rogan Experience: Fight Companion #046, January 09, Season 2020 Episode 17 (0 mins)'
        )

    def test_getters(self):
        """TP-030A Tests that the Podcast getters provide the proper info"""
        self.assertEqual(self.podcastdefault.artist, 'Joe Rogan',
                         'Should be Joe Rogan')
        self.assertEqual(self.podcastdefault.title, 'Fight Companion #046',
                         'Should be The Fight Companion #046')
        self.assertEqual(self.podcastdefault.series,
                         'The Joe Rogan Experience',
                         'Should be The Joe Rogan Experience')
        self.assertEqual(self.podcastdefault.season, None, 'Should be None')
        self.assertEqual(self.podcastdefault.progress, datetime.time(0, 0),
                         'Should be None')
        self.assertEqual(self.podcastdefault.user_rating, None,
                         'Should be None')
        self.assertEqual(self.podcastdefault.runtime, '240:00',
                         'Should be 240:00')

    def test_getter_type(self):
        """TP-030B Tests that the Podcast getter types are the proper type"""
        self.assertEqual(type(self.podcastdefault.artist), str,
                         'Should be a string')
        self.assertEqual(type(self.podcastdefault.title), str,
                         'Should be a string')
        self.assertEqual(type(self.podcastdefault.series), str,
                         'Should be a string')
        self.assertIsNone(self.podcastdefault.season, 'Should be None')
        self.assertEqual(type(self.podcastdefault.progress), datetime.time,
                         'Should be None')
        self.assertIsNone(self.podcastdefault.user_rating, 'Should be None')
        self.assertEqual(type(self.podcastdefault.runtime), str,
                         'Should be a string')

    def test_setters(self):
        """TP-040A Tests that the Podcast setters properly set their corresponding values"""
        self.podcastdefault.progress = datetime.time(0, 5)
        self.podcastdefault.user_rating = 5

        self.assertEqual(self.podcastdefault.progress, '05',
                         'Should return a formatted datetime to 05')
        self.assertEqual(self.podcastdefault.user_rating, 5,
                         'Should be an integer of 5')

    # FIX THIS LOL
    def test_setter_value(self):
        """TP-040B Tests that the setters raise a value error if an improper value is entered"""
        with self.assertRaises(ValueError):
            self.podcastdefault.user_rating = '5'
        with self.assertRaises(ValueError):
            self.podcastdefault.progress = 12

    def test_meta_dict_type(self):
        """TP-050A Tests that the meta_dict method returns a dictionary"""
        self.assertEqual(type(self.podcastdefault.meta_data()), dict,
                         'Should be of a type dict')

    #
    def test_meta_dict_output(self):
        """TP-050B Tests that meta_dict returns the proper output"""
        self.assertEqual(
            self.podcastdefault.meta_data(), {
                'artist': 'Joe Rogan',
                'date_added': '2020-02-12',
                'episode_date': '2020-01-09',
                'episode_number': None,
                'last_played': None,
                'progress': datetime.time(0, 0),
                'rating': None,
                'runtime': '240:00',
                'season': None,
                'series': 'The Joe Rogan Experience',
                'title': 'Fight Companion #046'
            }, "Should be {'artist': 'Joe Rogan',date_added': '2020-02-12',"
            "'episode_date': '2020-01-09','episode_number': None,'last_played': None,"
            "'progress': datetime.time(0, 0),'rating': None,'runtime': '240:00','season': None,"
            "'series': 'The Joe Rogan Experience','title': 'Fight Companion #046'}"
        )

    def test_usage_stats_valid(self):
        """TP-060A Tests the Audiofile usagestats type """
        self.assertEqual(self.podcastdefault.get_usage_stats().play_count, 0)
        self.assertEqual(self.podcastdefault.get_usage_stats().last_played,
                         None)
        self.assertEqual(self.podcastdefault.get_usage_stats().date_added,
                         '2020-02-12')

        self.podcastdefault.update_usage_stats()

        self.assertEqual(self.podcastdefault.get_usage_stats().play_count, 1)
        self.assertEqual(self.podcastdefault.get_usage_stats().last_played,
                         '2020-02-12')
        self.assertEqual(self.podcastdefault.get_usage_stats().date_added,
                         '2020-02-12')

    def test_file_location(self):
        """TP-070A Tests the AudioFile file_location returns a string an proper output"""
        self.assertTrue(self.podcastdefault.file_location())
        self.assertEqual(type(self.podcastdefault.file_location()), str,
                         'Should be a string')
        self.assertEqual(
            self.podcastdefault.file_location(),
            'The file (Fight Companion #046.mp3) is located in the path (.\Podcasts)',
            'Should be The file (Fight Companion #046.mp3) is located in the path (.\Podcasts)'
        )

    def test_lists(self):
        self.assertEqual(type(self.podcastdefault.meta_data()), dict, '')
Пример #17
0
 def scrap_episode(self, html):
     p = Podcast()
     p.from_html(html)
     self.add(p)
Пример #18
0
 def update(self):
     self.load()
     for i in self.listOfPodcasts:
         print 'updating "{}".'.format(i)
         p = Podcast('', self.rootDir, i)
         p.updateFeed()
Пример #19
0
def last_year(data):
    key = list(data.keys())[0]
    p = Podcast()
    p.from_json_file(key, data[key])
    return year(p)
Пример #20
0
# -*- coding: utf-8 -*-
from podcast import Podcast
import os.path
import json
from glob import glob
from pprint import pprint
# first validate the path given
# second validate the channel.json
# third load the json, add the channel-wide valus to a dict
# fourth iter through files, add them to dict.items or whatever
# fifth write the dict to the path using dicttoxml
files = []
podcastMetadata = json.loads(open('/Users/zac/Code/scratch/fake_pod/channel.json').read())
for filename in glob('/Users/zac/Code/scratch/fake_pod/*.mp3'):
    files.append(filename)
temp = Podcast(podcastMetadata, files)
# write temp.toXml() to index.rss

#for ep in temp:
print temp.toXml()
#pprint (vars(temp))