def start_jobs(self, ):
     crawled_lives = self.load_crawled_lives()
     if crawled_lives:
         user_dao = CrawledUserDao()
         for crawled_live in crawled_lives:
             try:
                 account = user_dao.query(crawled_live)
                 if account is None:
                     logging.error('no account found for crawled_live id = %s', crawled_live['id'])
                     continue
                 channel_info = protobful_serve_caller.get_channel_info(account['acc_user_id'])
                 if not self._category_mapping(crawled_live):
                     logging.error('Category Mapping failed, default value used for crawled_live id = %s', crawled_live['id'])
                 upcoming_event_id = protobful_serve_caller.create_upcoming(channel_info, crawled_live)
                 user_dao.update_crawled_lives(crawled_live, upcoming_event_id)
                 user_dao.update_crawled_user_upcoming_count(crawled_live)
                 logging.info("make one upcoming event OK, event id=%s, event title = '%s'",
                              upcoming_event_id,
                              crawled_live['title']
                              )
             except:
                 # todo handle exceptions
                 logging.exception('error when crawled_live id = %s', crawled_live['id'])
 
         user_dao.close()
示例#2
0
def make_events(event_list):
    '''
    Given selected crawled event list. Make corresponding
    events into Rings
    '''
    
    user_dao = CrawledUserDao()
    events_status = []
    
    for crawled_upcoming in event_list:
        try:
            # check whether the crawled event owner has an account
            # if not, create an account
            account = user_dao.query(crawled_upcoming)
            
            # if account creation fail, skip the event
            if account is None:
                logging.error('No account found or cannot create account for crawled_upcoming id = %s', crawled_upcoming['id'])
                events_status.append({'title':crawled_upcoming['title'], 'status':'fail', 'info':'Create account fail'})
                continue
            
            # once a valid account is returned, proceed with the event creating process
            
            # retrieve host owned channel's detail
            channel_info = get_channel_info(account['acc_user_id'])
            
            # map the crawled events category to system standard
            if not _category_mapping(crawled_upcoming):
                logging.error('Category Mapping failed, default value used for crawled_upcoming id = %s', crawled_upcoming['id'])
            
            # call create upcoming event function, return created event id
            upcoming_event_id = create_upcoming(channel_info, crawled_upcoming)
            
            # write back the event id to crawled_live table
            user_dao.update_crawled_lives(crawled_upcoming, upcoming_event_id)
            
            # update total created upcoming event count for this host
            user_dao.update_crawled_user_upcoming_count(crawled_upcoming)
            logging.info("make one upcoming event OK, event id=%s, event title = '%s'",
                            upcoming_event_id,
                            crawled_upcoming['title']
                        )
            events_status.append({'title':crawled_upcoming['title'], 'status':'success', 'info':''})
        except:
            logging.exception('error when crawled_upcoming id = %s', crawled_upcoming['id'], exc_info=True)
            events_status.append({'title':crawled_upcoming['title'], 'status':'fail', 'info':traceback.print_exc()})

    user_dao.close()
    return events_status