def show_blacklist(): if not session.get('logged_in'): flash('You are not logged in') logging.info('Non-Loggedin user with IP: %s try to access showBlacklist', request.remote_addr) return redirect(url_for('login')) else: crawled_user_dao = CrawledUserDao() black_user_list = crawled_user_dao.load_blacklist() crawled_user_dao.close() return render_template('show_blacklist.html', user_list = black_user_list)
def _notify(self): """ notify the server upcoming stream is uploading """ push_event_notification(self._event_id, self._host_id) user_dao = CrawledUserDao() try: video_session_id = get_channel_details(self._host_id, self._channel_id) update_session_category(self._host_id, video_session_id, self._category_id) user_dao.update_crawled_user_upcoming_live_count(self._host_id) except: logging.exception("update session category error.", exc_info=True) finally: user_dao.close()
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 remove_blacklist(): if not session.get('logged_in'): flash('You are not logged in') return redirect(url_for('login')) else: if request.method == 'POST': user_list = request.form.getlist('black_list') if len(user_list) > 0: crawled_user_dao = CrawledUserDao() user_list = ['\''+user+'\'' for user in user_list] crawled_user_dao.remove_blacklist( '(' + ', '.join(user_list) + ')') else: flash('There is no user selected.') return redirect(url_for('show_blacklist'))
def add_blacklist(): if not session.get('logged_in'): flash('You are not logged in') return redirect(url_for('login')) else: owner = request.args.get('owner', '') owner_url = request.args.get('owner_url', '') if owner and owner_url: crawled_user_dao = CrawledUserDao() if crawled_user_dao.save_to_blacklist(owner, owner_url) == 1: flash('%s has been added to the blacklist.' % owner) else: flash('Cannot add %s to the blacklist' % owner) crawled_user_dao.close() else: flash('Parameters error.') return redirect(url_for('show_upcoming'))
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