Beispiel #1
0
    def test_saving_new_channel(self):
        channel = Channel(
            title="Channel Title",
            url="https://www.youtube.com/channel/UCsn8UgBuRxGGqKmrAy5d3gA",
        )
        channel.save()

        saved_channels = Channel.objects.all()
        self.assertEqual(saved_channels.count(), 1)
def resetChannelList(hdid, channelList):
    device = Device.objects.get(hdid=hdid)

    Channel.objects.filter(device=device).delete()

    current_channel = ''

    channel_pattern = re.compile('SCANNING.*us-cable:(\d+)')
    program_pattern = re.compile('PROGRAM\s(\d+):\s(?![0])(.*)')

    for line in channelList:
        m = channel_pattern.match(line)
        if m:
            current_channel = m.group(1)
        else:
            m = program_pattern.match(line)
            if m:
                c = Channel(device=device,
                            channel=int(current_channel),
                            program=int(m.group(1)),
                            desc=m.group(2))
                c.save()
Beispiel #3
0
def import_file(channel_name, file):
    '''
    Import csv file to db.
    '''
    with open(file) as f:
        reader = csv.reader(f)
        try:
            channel = Channel.objects.get(name=channel_name)
        except Channel.DoesNotExist:
            channel = Channel(name=channel_name)
            channel.save()
        for row in reader:
            if row[0] != 'Category':
                categories = row[0].split(' / ')
                i = 0
                category_objs = []
                while i < len(categories):
                    try:
                        if i == 0:
                            channel_category = ChannelCategory.objects.get(
                                name=categories[i],
                                channel=channel,
                                parent_category=None)
                        else:
                            channel_category = ChannelCategory.objects.get(
                                name=categories[i],
                                channel=channel,
                                parent_category=category_objs[i - 1])

                    except ChannelCategory.DoesNotExist:
                        channel_category = ChannelCategory()
                        channel_category.name = categories[i]
                        channel_category.channel = channel
                    if i != 0:
                        channel_category.parent_category = category_objs[i - 1]
                    channel_category.save()
                    category_objs.append(channel_category)
                    i += 1
Beispiel #4
0
 def writeToDataBase(self):
     ch = Channel(name=self.title,
                  country=self.country,
                  subscriberCount=self.subscriberCount)
     ch.save()