Exemplo n.º 1
0
    def test_save(self):
        user = User()
        user.username = '******'
        user.save()
        get_user = User.objects.get(username="******")
        follower = TwAccount()
        follower.screen_name = "test"
        follower.follower_id = "123456"
        follower.user = get_user
        follower.save()

        self.assertEqual(
            TwAccount.objects.filter(follower_id="123456").exists(), True)

        status = TwStatus()
        status.id = u'107809348885028864'
        status.twFollower = follower
        status.text = u'hello world'
        raw_time = 'Sun Aug 28 13:38:46 +0000 2011'
        # ts = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(raw_time,'%a %b %d %H:%M:%S +0000 %Y'))
        ts = '2015-11-03 05:07:07'
        status.created_at = ts
        status.save()
        self.assertEqual(
            TwStatus.objects.filter(id=u'107809348885028864').exists(), True)
Exemplo n.º 2
0
def save_account(follower, **kwargs):
    new_account = TwAccount(follower=follower)
    new_account.act_id = kwargs['act_id']
    new_account.screen_name = kwargs['screen_name']
    new_account.save()

    return True
Exemplo n.º 3
0
def save_account(follower, **kwargs):
    new_account = TwAccount(follower=follower)
    new_account.act_id = kwargs['act_id']
    new_account.screen_name = kwargs['screen_name']
    new_account.save()

    return True
Exemplo n.º 4
0
def add_follower(request):
    if request.method == 'POST':
        tw_crawler = Crawler_twitter()
        follower_id = request.POST['follower_id']
        screen_name = request.POST['screen_name']

        kwargs = {'screen_name': screen_name,
                  'id': follower_id}
        is_exist_follower = tw_crawler.add_follower(**kwargs)
        if not is_exist_follower:
            return HttpResponse(False)
        else:
            if TwAccount.objects.filter(user_id=request.user.id).filter(follower_id=is_exist_follower['id']).exists():
                return HttpResponse(False)
            new_follower = TwAccount()
            new_follower.follower_id = is_exist_follower['id']
            new_follower.screen_name = is_exist_follower['screen_name']
            new_follower.user = request.user
            new_follower.save()
            return HttpResponse(True)
    else:
        raise Http404
Exemplo n.º 5
0
def add_follower(request):
    if request.method == 'POST':
        tw_crawler = Crawler_twitter()
        follower_id = request.POST['follower_id']
        screen_name = request.POST['screen_name']

        kwargs = {'screen_name': screen_name, 'id': follower_id}
        is_exist_follower = tw_crawler.add_follower(**kwargs)
        if not is_exist_follower:
            return HttpResponse(False)
        else:
            if TwAccount.objects.filter(user_id=request.user.id).filter(
                    follower_id=is_exist_follower['id']).exists():
                return HttpResponse(False)
            new_follower = TwAccount()
            new_follower.follower_id = is_exist_follower['id']
            new_follower.screen_name = is_exist_follower['screen_name']
            new_follower.user = request.user
            new_follower.save()
            return HttpResponse(True)
    else:
        raise Http404
Exemplo n.º 6
0
    def test_save(self):
        user = User()
        user.username = '******'
        user.save()
        get_user = User.objects.get(username="******")
        follower = TwAccount()
        follower.screen_name = "test"
        follower.follower_id = "123456"
        follower.user = get_user
        follower.save()

        self.assertEqual(TwAccount.objects.filter(follower_id="123456").exists(), True)

        status = TwStatus()
        status.id = u'107809348885028864'
        status.twFollower = follower
        status.text = u'hello world'
        raw_time = 'Sun Aug 28 13:38:46 +0000 2011'
        # ts = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(raw_time,'%a %b %d %H:%M:%S +0000 %Y'))
        ts = '2015-11-03 05:07:07'
        status.created_at = ts
        status.save()
        self.assertEqual(TwStatus.objects.filter(id=u'107809348885028864').exists(), True)