def read_clan_ranking(rankings, clan_tag, clan_stats, attr_name):
    """
    Sets global or local clan ranking info on a clan history object
    :param list rankings:
    :param str clan_tag:
    :param ClanHistory clan_stats:
    :param str attr_name: must be in (local, global, local_war, global_war) - see backend.models.clashroyale.ClanHistory
    :return:
    """
    try:
        ranking = next(x for x in rankings if x.tag[1:] == clan_tag)
    except StopIteration:
        return None
    setattr(clan_stats, '{}_rank'.format(attr_name), ranking.rank)
    setattr(clan_stats, 'prev_{}_rank'.format(attr_name), ranking.previous_rank)
    return ranking