Ejemplo n.º 1
0
class CrawlerTestCase(unittest.TestCase):
    def setUp(self):
        self.crawler = Crawler_quora()

    def tearDown(self):
        self.crawler = None

    def test_add_follower(self):
        self.assertFalse(self.crawler.add_follower(),
                         'add follower with empty information')
        self.assertFalse(self.crawler.add_follower(id='51248642'),
                         'add follower with wrong information')
        self.assertFalse(self.crawler.add_follower(user_name='wahahahah'),
                         'no such user')
        self.assertIsNotNone(
            self.crawler.add_follower(user_name='quan-zhang-27'),
            'add follower with correct screen name')
        self.assertEqual(self.crawler.add_follower(user_name='quan-zhang-27'),
                         'quan-zhang-27',
                         'check return id if is equal to given correct id')

    def test_get_status(self):
        self.assertEqual(self.crawler.get_status(), [],
                         'get status with empty information')
        self.assertEqual(self.crawler.get_status(id='51248642'), [],
                         'get status with incorret information')
        self.assertEqual(self.crawler.get_status(user_name='wahahahah'), [],
                         'get status with wrong user name')
        self.assertNotEqual(
            len(self.crawler.get_status(user_name='quan-zhang-27')), 0,
            'get status with correct screen name')
        self.assertNotEqual(
            len(self.crawler.get_status(user_name='Dan-holliday')), 0,
            'get status with correct user name')
class CrawlerTestCase(unittest.TestCase):

    def setUp(self):
        self.crawler = Crawler_quora()

    def tearDown(self):
        self.crawler = None

    def test_add_follower(self):
        self.assertFalse(self.crawler.add_follower(),
                         'add follower with empty information')
        self.assertFalse(self.crawler.add_follower(id = '51248642'),
                         'add follower with wrong information')
        self.assertFalse(self.crawler.add_follower(user_name='wahahahah'),
                         'no such user')
        self.assertIsNotNone(self.crawler.add_follower(user_name='quan-zhang-27'),
                             'add follower with correct screen name')
        self.assertEqual(self.crawler.add_follower(user_name='quan-zhang-27'), 'quan-zhang-27',
                         'check return id if is equal to given correct id')

    def test_get_status(self):
        self.assertEqual(self.crawler.get_status(), [],
                         'get status with empty information')
        self.assertEqual(self.crawler.get_status(id = '51248642'), [],
                         'get status with incorret information')
        self.assertEqual(self.crawler.get_status(user_name='wahahahah'), [],
                         'get status with wrong user name')
        self.assertNotEqual(len(self.crawler.get_status(user_name='quan-zhang-27')), 0,
                         'get status with correct screen name')
        self.assertNotEqual(len(self.crawler.get_status(user_name='Dan-holliday')), 0,
                             'get status with correct user name')
Ejemplo n.º 3
0
def verify_account(**verify_kwargs):
    if verify_kwargs['flr_name'] is not None:
        if QrAccount.objects.filter(follower__name=verify_kwargs['flr_name']).exists():
            return False
    tw_crawler = Crawler_quora()
    crawler_kwargs = {'user_name': verify_kwargs.get('user_name', None)}
    user_name = tw_crawler.add_follower(**crawler_kwargs)
    if not user_name:
        return '404'
    return {'user_name': user_name}
Ejemplo n.º 4
0
def refresh_status(qr_act_list):
    qr_crawler = Crawler_quora()
    status_list = []
    for act in qr_act_list:
        temp_list = qr_crawler.get_status(user_name=act.user_name)
        if temp_list:
            save_status(act, temp_list)
            status_list.extend(temp_list)
    if len(status_list) > 10:
        status_list = status_list[:10]
    for status in status_list:
        status['act_type'] = 'quora'
    return status_list
Ejemplo n.º 5
0
def refresh_status(qr_act_list):
    qr_crawler = Crawler_quora()
    status_list = []
    for act in qr_act_list:
        temp_list = qr_crawler.get_status(user_name=act.user_name)
        if temp_list:
            save_status(act, temp_list)
            status_list.extend(temp_list)
    if len(status_list) > 10:
        status_list = status_list[:10]
    for status in status_list:
        status['act_type'] = 'quora'
    return status_list
Ejemplo n.º 6
0
    def is_update_quora(self, qraccount):
        if not qraccount:
            return False
        try:
            # max_id_status = TwStatus.objects.raw('select max(id) from ChasingSomeoneApp_twstatus')
            status = QrStatus.objects.all().aggregate(Max('time_stamp'))
            max_id_status = status['time_stamp__max']
        except QrStatus.DoesNotExist:
            print 'Can not get status from TwStatus'
            max_id_status = None
        crawler = Crawler_quora()
        status_list = crawler.get_status(user_name=qraccount.user_name)

        if not status_list:
            print 'Can not get posts from user\'s homepage'
            return False
        try:
            if not self.update_quora_status(qraccount, status_list):
                return False
        except KeyError:
            print 'Error occured when updates quora status'
            return False
        return True
Ejemplo n.º 7
0
    def is_update_quora(self, qraccount):
        if not qraccount:
            return False
        try:
            # max_id_status = TwStatus.objects.raw('select max(id) from ChasingSomeoneApp_twstatus')
            status = QrStatus.objects.all().aggregate(Max("time_stamp"))
            max_id_status = status["time_stamp__max"]
        except QrStatus.DoesNotExist:
            print "Can not get status from TwStatus"
            max_id_status = None
        crawler = Crawler_quora()
        status_list = crawler.get_status(user_name=qraccount.user_name)

        if not status_list:
            print "Can not get posts from user's homepage"
            return False
        try:
            if not self.update_quora_status(qraccount, status_list):
                return False
        except KeyError:
            print "Error occured when updates quora status"
            return False
        return True
Ejemplo n.º 8
0
 def setUp(self):
     self.crawler = Crawler_quora()
 def setUp(self):
     self.crawler = Crawler_quora()