Ejemplo n.º 1
0
    def handle(self, *args, **options):
        ## crawl
        # CaronaModel.objects.all().delete()
        # ParserErrorsModel.objects.all().delete()
        # MainController().crawl_post(time_interval=60)

        ## persistence
        pc = PersistenceController()
        pc.clean_old_posts()
        return
Ejemplo n.º 2
0
def carona_info(request, carona_id):
    carona = PersistenceController().get_carona_info(carona_id)
    comments = FBGroupsController(carona.fb_group_id).get_comments(carona.fb_post_id)
    carona.comments =  comments
    return my_render(request,'carona_info.html',
        {
            'title': u'Informação sobre a carona',
            'result': carona,
        }
    )
Ejemplo n.º 3
0
    def test_search(self):

        results = PersistenceController().search_carona('o', 'sao paulo','SP' ,'sao carlos', 'SP',
                                              datetime.datetime(2013, 10, 28, 11, 0, 0),
                                              datetime.datetime(2013, 10, 28, 11, 30, 0))
        pprint(results.values())
        results = PersistenceController().search_carona('o', 'sao paulo','SP' ,'sao carlos', 'SP',
                                              datetime.datetime(2013, 10, 28, 9, 0, 0),
                                              datetime.datetime(2013, 10, 28, 13, 0, 0))
        pprint(results.values())
        results = PersistenceController().search_carona('o', 'sao paulo','SP' ,'sao carlos', 'SP',
                                              datetime.datetime(2013, 10, 28, 8, 0, 0),
                                              datetime.datetime(2013, 10, 28, 11, 0, 0))
        pprint(results.values())
        results = PersistenceController().search_carona('o', 'sao paulo','SP' ,'sao carlos', 'SP',
                                              datetime.datetime(2013, 10, 28, 11, 0, 0),
                                              datetime.datetime(2013, 10, 28, 16, 0, 0))
        pprint(results.values())
        return
Ejemplo n.º 4
0
 def test_caronas_path(self):
     persistence = PersistenceController()
     paths = persistence.get_carona_paths()
     pprint(paths)
     return
Ejemplo n.º 5
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