예제 #1
0
 def test_select_and_save(self):
     b2 = Bangumi(name='test_select_and_save', update_time='Sun')
     d = b2.select()
     self.assertEqual(d, [])
     b2.save()
     ret = b2.select(one=True)
     self.assertIsInstance(ret, dict)
예제 #2
0
    def test_update(self):
        b1 = Bangumi(name='test_update', update_time='Sun')
        b1.save()
        b1.update_time = 'Mon'
        b1.update()
        ret = b1.select(one=True)
        self.assertEqual(ret['update_time'], 'Mon')

        b1.update(data={'name': 'test666', 'update_time': 'Sat'})
        ret = b1.select(one=True)
        self.assertIsInstance(ret, dict)
예제 #3
0
파일: main.py 프로젝트: xxoxx/BGmi
def add(ret):
    # action add
    # add bangumi by a list of bangumi name
    if not Bangumi.get_all_bangumi():
        print_warning('No bangumi data in database, fetching...')
        update(ret)

    for bangumi in ret.action.add.name:
        bangumi_obj = Bangumi(name=bangumi)
        data = bangumi_obj.select(one=True, fields=['id', 'name', 'keyword'])
        if data:
            followed_obj = Followed(bangumi_name=data['name'],
                                    status=STATUS_FOLLOWED)
            followed_obj.select_obj()
            if not followed_obj or followed_obj.status == STATUS_NORMAL:
                if not followed_obj:
                    ret, _ = get_maximum_episode(bangumi_obj, subtitle=False)
                    followed_obj.episode = ret['episode']
                    followed_obj.save()
                else:
                    followed_obj.status = STATUS_FOLLOWED
                    followed_obj.save()
                print_success('{0} has followed'.format(bangumi_obj))
            else:
                print_warning('{0} already followed'.format(bangumi_obj))

        else:
            print_error('{0} not found, please check the name'.format(bangumi))
예제 #4
0
 def test_add_and_remove_followed(self):
     f = Followed(bangumi_name='test_add_and_remove_followed',
                  status=STATUS_FOLLOWED,
                  episode=6)
     f.save()
     b = Bangumi(name='test_add_and_remove_followed')
     b.save()
     bangumi_data = b.select(
         one=True,
         join='LEFT JOIN %s ON %s.bangumi_name=%s.name' %
         (Followed.table, Followed.table, Bangumi.table))
     self.assertEqual(bangumi_data['status'], STATUS_FOLLOWED)
     f.delete()
     bangumi_data = b.select(
         one=True,
         join='LEFT JOIN %s ON %s.bangumi_name=%s.name' %
         (Followed.table, Followed.table, Bangumi.table))
     self.assertEqual(bangumi_data['status'], STATUS_NORMAL)
예제 #5
0
파일: controllers.py 프로젝트: luoxiai/BGmi
def add(name, episode=None):
    """
    ret.name :str
    """
    # action add
    # add bangumi by a list of bangumi name
    # result = {}
    if not Bangumi.get_all_bangumi():
        website.fetch(save=True, group_by_weekday=False)

    bangumi_obj = Bangumi(name=name)
    data = bangumi_obj.select(one=True, fields=['id', 'name', 'keyword'])
    if data:
        followed_obj = Followed(bangumi_name=data['name'],
                                status=STATUS_FOLLOWED)
        followed_obj.select_obj()
        if not followed_obj or followed_obj.status == STATUS_NORMAL:
            if not followed_obj:
                bangumi_data, _ = website.get_maximum_episode(bangumi_obj,
                                                              subtitle=False,
                                                              max_page=1)
                followed_obj.episode = bangumi_data[
                    'episode'] if episode is None else episode
                followed_obj.save()
            else:
                followed_obj.status = STATUS_FOLLOWED
                followed_obj.save()
            result = {
                'status': 'success',
                'message': '{0} has been followed'.format(bangumi_obj)
            }
        else:
            result = {
                'status': 'warning',
                'message': '{0} already followed'.format(bangumi_obj)
            }
    else:
        result = {
            'status': 'error',
            'message': '{0} not found, please check the name'.format(name)
        }
    return result
예제 #6
0
 def test_delete(self):
     b1 = Bangumi(name='test_delete', update_time='Sun')
     b1.save()
     self.assertEqual(b1.select(one=True)['name'], 'test_delete')
     b1.delete()
     self.assertEqual(b1.select(one=True), None)