Esempio n. 1
0
def get_old_skirms(antenna, cfg):
    """
    Retrieve old battles and extract old skirmishes from them. Meant to be a
    helper method for retrieve_combatants, but may have uses elsewhere.

    :param antenna: Antenna to connect to Reddit
    :param cfg: Config that holds viewed battle info
    :return: a list of old skirmishes, in the form of Chrommabot's comments
    """
    viewed_battles = cfg['VIEWED_BATTLES']
    # get old battles
    battle_gen = antenna.search('[Invasion]', subreddit='FieldOfKarmicGlory')
    raw_battles = [b for b in battle_gen if str(b.author) == 'chromabot']
    #filter out battles we've already looked at
    battles = [b for b in raw_battles if b.fullname not in viewed_battles]
    for b in battles:
        cfg['VIEWED_BATTLES'].append(b.fullname)
    configReader.save(cfg)

    #get skirmish comments
    skirms = []
    for battle in battles:
        battle.replace_more_comments()
        comments = praw.helpers.flatten_tree(battle.comments)
        for cmnt in comments:
            if hasattr(cmnt, 'author') and str(cmnt.author) == 'chromabot':
                skirms.append(cmnt)

    return skirms
Esempio n. 2
0
def set_thread():
    """
    Set the recruitment thread of a side.
    """
    if session["usertype"] == 0:
        return redirect("/")
    thread_link = request.args.get("link")
    thread_side = int(request.args.get("side"))
    thread_id = re.search("(?<=/)([1-z]{6})(?=/)", thread_link).group(0)
    if thread_side == 0:
        CONFIG["OR_RECRUIT_THREAD"] = thread_id
    elif thread_side == 1:
        CONFIG["PW_RECRUIT_THREAD"] = thread_id
    else:
        raise excs.InvalidSideError(__name__, thread_side)
    configReader.save(CONFIG)
    return redirect("/")