def handleMoney(endpoint): if endpoint.startswith('shop/list'): return flask.jsonify({'userCommonMoneyList': dt.readJson('data/commonMoneyList.json'), 'resultCode': 'success'}) elif endpoint.startswith('process'): return process() else: flask.abort(501, description='Not implemented')
def check(): userQuestBattleResult = dt.readJson('data/user/userQuestBattleResult.json') userSection = dt.getUserObject('userSectionList', userQuestBattleResult['questBattle']['sectionId']) response = { 'resultCode': 'success', 'gameUser': dt.readJson('data/user/gameUser.json'), 'user': dt.readJson('data/user/user.json'), 'userQuestBattleResultList': [userQuestBattleResult], 'userQuestBattleList': [dt.getUserObject('userQuestBattleList', userQuestBattleResult['questBattleId'])], 'userSectionList': [userSection], 'userChapterList': [] } chapter = dt.getUserObject('userChapterList', userSection['section']['genericId']) if chapter is not None: response['userChapterList'] = [chapter] return flask.jsonify(response)
def resetShop(): today = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0) lastMonth = today.month - 1 skipTypes = ['PIECE', 'MAXPIECE', 'FORMATION_SHEET', 'CARD'] # afaik these don't need to be reset... shopList = dt.readJson('data/shopList.json') # figure out if it needs to be reset (end date is prior to today), then reset it # kinda hacky way to get the last time the shop was reset # finds the first limited (and available) item in the mirrors coins shop, then takes its end time # reverse order because limited items are at the bottom of the shopItempList. for shopItem in reversed(shopList[1]['shopItemList']): if 'endAt' in shopItem: shopExpiryTime = shopItem['endAt'] if shopExpiryTime != "2050/01/01 00:00:00": break if not beforeToday(shopExpiryTime): return for shopIdx in range( 4): # magia chips, mirrors coins, support pts, daily coins shopItems = shopList[shopIdx]['shopItemList'] deleteIdxs = [ i for i in range(len(shopItems)) if 'endAt' in shopItems[i] and beforeToday(shopItems[i]['endAt']) and not shopItems[i]['shopItemType'] in skipTypes ] for i in reversed(deleteIdxs): del shopItems[i] # from Stack Overflow endOfMonth = today.replace(day=28) + timedelta(days=4) endOfMonth = ((endOfMonth - timedelta(days=endOfMonth.day)).replace( hour=23, minute=59, second=59)).strftime(DATE_FORMAT) newItems = [] alreadyCopied = set([]) for item in shopItems: if 'endAt' not in item \ or item['endAt']!= "2050/01/01 00:00:00" \ or item['shopItemType'] in skipTypes \ or item['genericId'] in alreadyCopied: continue alreadyCopied.add(item['genericId']) newItem = copy.deepcopy(item) newItem['startAt'] = today.strftime(DATE_FORMAT) newItem['endAt'] = endOfMonth newItems.append(newItem) # also need to clear out the user's history dt.deleteUserObject('userShopItemList', newItem['id']) shopList[shopIdx]['shopItemList'] += newItems dt.saveJson('data/shopList.json', shopList)
def receiveAll(): response = {"resultCode": "success"} userChallenges = dt.readJson('data/user/userDailyChallengeList.json') finalChallenges = [] for challenge in userChallenges: if challenge['clearedCount'] >= challenge['challenge']['count']: response = dt.updateJson(response, receiveReward(challenge)) finalChallenges.append(challenge) response['userDailyChallengeList'] = finalChallenges return flask.jsonify(response)
def changeLogName(): for handler in logging.root.handlers[:]: handler.close() logging.root.removeHandler(handler) logLevel = dt.readJson('config.json')['logLevel'] date = nowstr().split(' ')[0].replace('/', '_') hour = datetime.now().hour logging.basicConfig( level=logLevel, filename='logs/{0}-{1}.log'.format(date, hour), format='%(asctime)s %(levelname)s %(name)s : %(message)s')