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()
    def _get_rmtp_address(self):
        '''Query for rmtp uploading server address'''
        
        channel_info = get_channel_info(self._host_id)
        # Wowza server 54.255.137.225 does not generate replay video
        data = {
            "host": '54.255.137.225',
            "port": channel_info['info']['port'],
            "application": channel_info['info']['application'],
            "stream": channel_info['info']['stream']
        }

        return "rtmp://{host}:{port}/{application}/{stream}".format(**data)
Exemple #3
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
    def _get_rmtp_address(self):
        '''Query for rmtp uploading server address'''
        channel_info = get_channel_info(self._host_id)

        def _choose_upload_host(available_upload_hosts):
            if not isinstance(available_upload_hosts, list) or \
                len(available_upload_hosts) < 1:
                raise Exception("no available_upload_hosts. for host id="+self._host_id)
            
            for host in available_upload_hosts:
                if host == '52.74.32.141': # the best one
                    return host
            
            # if the best server is not in the list, returen first one
            return available_upload_hosts[0]

        data = {
            "host": _choose_upload_host(channel_info['info']['available_upload_hosts']),
            "port": channel_info['info']['port'],
            "application": channel_info['info']['application'],
            "stream": channel_info['info']['stream']
        }

        return "rtmp://{host}:{port}/{application}/{stream}".format(**data)