def test_get_comments(self):
        group_id = '641749869191341'
        fbgroups_controller = FBGroupsController(group_id)
        comments = fbgroups_controller.get_comments('641749869191341_666135846752743')
        pprint(comments)

        return
    def test_get_posts(self):
        ## test
        ## caronas sao carlos sao paulo
        group_id = '641749869191341'

        fbgroups_controller = FBGroupsController(group_id)
        posts  = fbgroups_controller.get_posts()
        pprint(posts)
        return
Exemplo n.º 3
0
 def clean_deleted_posts(self):
     fb_groups_controller  = FBGroupsController(0)
     ## getting posts in the last 24h
     yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
     caronas = CaronaModel.objects.filter(from_datetime__gte=yesterday)
     for c in caronas:
         if not fb_groups_controller.exists_post(c.fb_post_id):
             # print 'Deleting post', c.fb_post_id
             c.delete()
     return
    def test_get_posts_with_pagination(self):
        group_id = '641749869191341'
        fbgroups_controller = FBGroupsController(group_id)

        ## last 24 hours
        posts = fbgroups_controller.get_posts(last_time_checked=1440)
        pprint(posts)

        ## all time posts
        print('\n\n\n\n\n\n-------------------------------------------------------------')
        posts = fbgroups_controller.get_posts(last_time_checked=10080)
        pprint(posts)
        return
 def test_exists_post(self):
     fb_group_id = '144978565569620'
     fb_post_id = '144978565569620_602785809788891'
     fbgroups_controller = FBGroupsController(fb_group_id)
     comments = fbgroups_controller.exists_post(fb_post_id)
     return
Exemplo n.º 6
0
    def retrieve_posts(self, fb_group_id):

        ## persistence
        persistence = PersistenceController()
        city1, city1_state, city1_list, city2, city2_state, city2_list = \
            persistence.get_cities_by_fb_group_id(fb_group_id)

        ## getting feed
        fb_manager = FBGroupsController(fb_group_id)
        feed = fb_manager.get_posts(last_time_checked=self.time_interval)

        for fb_post in feed:

            ## check if the post is not commented
            if (not self.post_is_commented(fb_post['message'])
                ## check if it is already parsed
                and not persistence.exists_post(fb_post['id'])):

                # pprint(fb_post)
                ## create new carona post
                carona_post  = CaronaPost(fb_post)
                pprint(carona_post.content_clean)

                ## setting origin and destiny
                carona_post.city1 = city1
                carona_post.city1_state = city1_state
                carona_post.city2 = city2
                carona_post.city2_state = city2_state
                
                carona_post.city1_list = city1_list
                carona_post.city2_list = city2_list

                 ## date / time
                has_date_tag = carona_post.retrieve_date_tags()
                carona_post.retrieve_time_tags()
                # has_time_interval = carona_post.retrieve_time_interval()
                has_time_tag = True if carona_post.tag_time else False

                ## origin_destiny
                has_origin_destiny =  carona_post.retrieve_origin_destiny()

                ## oferecer/ procurar
                has_ofereco_procuro = carona_post.retrieve_ofereco_procuro_tag()

                ## [OPTIONAL] numero de vagas
                has_vagas = carona_post.retrieve_vagas()

                ## check the tag requirements
                # print(has_date_tag, has_time_tag, has_origin_destiny, has_ofereco_procuro)
                if has_date_tag and has_time_tag and has_origin_destiny and has_ofereco_procuro:
                    ## saving in the db
                    # pprint(str(carona_post))
                    # pprint('---------------------')
                    persistence.add_carona(carona_post)
                else:
                    print('*************** wrong')
                    pprint(carona_post.content_clean)
                    pprint(str(carona_post))
                    print('*******************************************')
                    self.log_not_parsed_post(carona_post)
            else:
                ## TODO: call logger
                pass

        return