def insert_or_update_clan(tag): clan_query = Clan.query.filter_by(tag=tag).first() clan_dict = dict() if clan_query is None: retrieved_data = call_coc(tag, "clan") insert_clan(retrieved_data) elif date_compare(clan_query.date_updated, 0, 1, 0): clan_data = update_clan(tag) clan_dict = clan_data else: clan_dict = convert_class(clan_query) return clan_dict
def insert_or_update_warlog(tag): warlog_query = Warlog.query.filter_by(clan_tag=tag).first() warlog_dict = dict() if warlog_query is None: retrieved_data = call_coc(tag, "warlog") insert_warlog(retrieved_data, tag) warlog_dict = {"log": retrieved_data} elif date_compare(warlog_query.date_updated, 0, 12, 0): print("warlog true") log = update_warlog(tag) warlog_dict = {"log": log} else: warlog_dict = warlog_sql_dict(warlog_query) return warlog_dict
def insert_or_update_currentwar(tag): query = Current_war.query.filter_by(clan_tag=tag).first() if query is None: retrieved_data = call_coc(tag, 'currentwar') if retrieved_data["state"] == "inWar" or retrieved_data[ "state"] == "preparation": insert_currentwar(retrieved_data) return retrieved_data else: return retrieved_data elif date_compare(query.date_updated, 0, 0, 5): current_war_data = update_currentwar(tag) return current_war_data else: return currentwar_sql_dict(query)
def insert_or_update_player(tag): query = Player.query.filter_by(tag=tag).first() account_query = Cocaccounts.query.filter_by(account_tag=tag).first() clan_member_query = Clanmemberslist.query.filter_by(tag=tag).first() print(account_query, clan_member_query) player_dict = dict() if query is None: retrieved_data = call_coc(tag, "players") insert_player(retrieved_data) player_dict = retrieved_data elif date_compare(query.date_updated, 0, 1, 0): player_data = update_player(tag) player_dict = player_data else: player_dict = convert_class(query) if not account_query.role == clan_member_query.role: query = Cocaccounts.query.filter_by(account_tag=tag).update( dict(role=clan_member_query.role)) db.session.commit() return player_dict
def check_update_time(post): if date_compare(post["datePosted"],1,0,0): return True else: return False