def page_base_processor(request): m = get_maintenance() ld = request.user.is_authenticated() bot = get_steam_bot_status() times = 0 wpct = 0 cost = 0.0 income = 0.0 times_week = 0 wpct_week = 0 cost_week = 0.0 income_week = 0.0 user = current_user(request) if user and user.is_authenticated(): times, wpct, cost, income = getWins(user) times_week, wpct_week, cost_week, income_week = getWins(user, 6) context = { 'chat_smiles': chat_smiles, 'maintenance': m, 'ld': False, 'steam_bot': bot, 'times': times, 'wpct': wpct, 'cost': cost, 'income': round(income, 2), 'times_week': times_week, 'wpct_week': wpct_week, 'cost_week': cost_week, 'income_week': round(income_week, 2), } return context
def create(self, request): try: m = get_maintenance() if m: return reformat_ret( 201, [], _('The site in on maintenance, please wait for a while.')) steamer = current_user(request) if steamer: code, result = join_coinflip_game(request.data, steamer) if code == 0: return reformat_ret(0, result, 'create coinflip successfully') elif code == 201: return reformat_ret(201, {}, _l("Someone has joined the game.")) else: return reformat_ret(101, {}, result) return reformat_ret(0, {}, 'coinflip') except CoinFlipGame.DoesNotExist as e: _logger.error(e) return reformat_ret(301, {}, 'Invalid game') except Exception as e: _logger.exception(e) return reformat_ret(500, {}, 'coinflip exception')
def process_request(self, request): m = get_maintenance() if m and (not request.path.startswith('/fanmin/') and not request.path.startswith('/login/') and not request.path.startswith('/complete/')): return render_to_response('pages/maintenance.html') return None
def game_bot_worker(): time.sleep(30) while True: m = get_maintenance() bot_status = get_steam_bot_status() if not m and bot_status: try: bot_join_coinflip() except Exception as e: _logger.exception(e) finally: time.sleep(5) try: bot_create_coinflip() except Exception as e: _logger.exception(e) finally: time.sleep(5) try: bot_join_jackpot() except Exception as e: _logger.exception(e) finally: time.sleep(50)
def update_online(): try: m = get_maintenance() if m: return online = get_online() ws_send_online(online) bot_status = get_steam_bot_status() ws_send_bot_status(bot_status) except Exception as e: _logger.exception(e)
def check_trading(): r = get_redis() while True: time.sleep(1) try: if not is_connection_usable(): connection.close() m = get_maintenance() if not m: keys = r.lrange(_trade_list_key, 0, -1) for key in keys: val = r.get(key) if val: trade = json.loads(val, encoding='utf-8') trade_no = trade.get('trade_no', None) if trade_no: update_store_trade_no(trade['uid'], trade_no, data=trade) result = trade.get('status', TradeStatus.Initialed.value) if result == TradeStatus.Accepted.value: exchanged = trade.get('exchanged', False) if exchanged: confirm_store_items(trade['uid'], data=trade) r.lrem(_trade_list_key, key, num=1) r.delete(key) _logger.info( u'confirm trade {0} items to {1} on {2}'. format(len(trade['theirItems']), trade['steamer']['steamid'], trade['steamer']['tradeurl'])) elif result == TradeStatus.Cancelled.value: cancel_store_items(trade['uid'], data=trade) r.lrem(_trade_list_key, key, num=1) r.delete(key) _logger.info( u'cancel trade {0} items to {1} on {2}'.format( len(trade['theirItems']), trade['steamer']['steamid'], trade['steamer']['tradeurl'])) except Exception as e: _logger.exception(e)
def create(self, request): # _logger.debug('create deposit') try: m = get_maintenance() if m: return reformat_ret( 201, [], _('The site in on maintenance, please wait for a while.')) steamer = current_user(request) if steamer: code, result = join_jackpot_game(request.data, steamer) if code == 0: return reformat_ret(0, {'uid': result.uid}, _l('join jackpot successfully')) else: return reformat_ret(101, {}, result) return reformat_ret(0, {}, 'jackpot') except Exception as e: _logger.exception(e) return reformat_ret(500, {}, 'jackpot exception')
def coinflip_countdown_checker(): r = get_redis() while True: try: if not is_connection_usable(): connection.close() m = get_maintenance() if not m: keys = r.smembers(_cf_game_set) for key in keys: game_data = r.get(key) if not game_data: continue game = json.loads(game_data, encoding='utf-8') winner = game.get('winner', None) time_now = dt.now() ts_now = aware_datetime_to_timestamp(time_now) canceled = False if winner: ts = game['win_ts'] expires = settings.COINFLIP_END_EXPIRE - (ts_now - ts) else: ts = game['ts_get'] expires = settings.COINFLIP_EXPIRE_TIMEOUT - (ts_now - ts) canceled = expires <= 0 if expires <= 0: r.srem(_cf_game_set, key) r.delete(key) if canceled: ws_send_cf_remove(game['gid']) trade_items_back_to_joiners(game['gid']) except Exception as e: _logger.exception(e) finally: time.sleep(60)