Ejemplo n.º 1
0
def gen_parenthetical(notes):
    """
    generates a parenthetical containing notes and a private property notice when needed
    assumes at least one of these is true or populated
    :param notes: notes about the nest (list of strings)
    :return: a parenthetical statement containing notes and any private property reminders
    """

    return decorate_text("; ".join(notes), "()")
Ejemplo n.º 2
0
def disc_important_species(s_list):
    """
    discord post of top/important species & parks
    maybe this should be from a config file?
    :param s_list: species-arranged nested_dict, like elsewhere
    :return: a species summary for the popular species
    """

    important_species = [
        "Magikarp",
        "Walimer",
        "Water Biome",
        "Cubone",
        "Omanyte",
        "Kabuto",
    ]
    out = decorate_text("Popular Species", "__****__")
    pre_list = {}

    # list of nests with noteworthy species
    s_list = s_list.filter(
        Q(species_txt__in=important_species)
        | Q(species_name_fk__type1=8)  # important/popular species for quests
        | Q(species_name_fk__type2=8)  # (ghosts for Kanto research)
        | Q(species_name_fk__category=50)  # starters
    )

    if len(s_list) == 0:
        return ""

    # Sort the list into categories/species
    pre_list[f"Ghost|{ghost_icon}Ghosts"] = s_list.filter(
        Q(species_name_fk__type1=8) | Q(species_name_fk__type2=8)
    )
    s_list = s_list.exclude(Q(species_name_fk__type1=8) | Q(species_name_fk__type2=8))
    pre_list["Start|Starters"] = s_list.filter(species_name_fk__category=50)
    s_list = s_list.exclude(species_name_fk__category=50)
    for i_s in important_species:
        pre_list[f"{i_s}|{annotate_species_txt(i_s)}{i_s}"] = s_list.filter(
            species_txt=i_s
        )

    # actually generate the output string
    for sp_cat in sorted(pre_list.keys()):
        if len(pre_list[sp_cat]) == 0:
            continue
        out += f"\n• {sp_cat.split('|')[-1]}:"
        first = True
        for nest in sorted(pre_list[sp_cat]):
            out += f"{'' if first else ','} \
{decorate_text(nest.nestid.get_name(), '****' if nest.confirmation else '__')}"
            first = False

    return out
Ejemplo n.º 3
0
def disc_preamble(updated8, rotationday, rotnum):
    """
    dates should be previously-formatted as strings
    :param updated8: string for the date of the update generation
    :param rotationday: string for the rotation date
    :param rotnum: rotation number (int)
    :return: Preamble for Discord post
    """

    out = decorate_text(rotationday, "``") + " nest shift (#" + str(rotnum) + ")\n"
    out += "Last updated: " + updated8 + "\n\n"
    out += "**Bold** species are confirmed; _italic_ are single-reported\n\n"
    return out
Ejemplo n.º 4
0
def FB_format_nests(nnl):
    """
    Facebook-specific formatting
    :param nnl: nested_dict in the form of nnl[location][nest], where location is text and nest is a NSLA object
    :return: a formatted string of all the nests arranged alphabetically by park divided by neighborhood/region
    """

    list_txt = ""
    for location in sorted(nnl.keys()):
        # use "ZZZ" instead of just "Z" to accommodate Zanesville
        # and any city that two consecutive Z in its name
        list_txt += decorate_text(location.split("ZZZ")[-1], "{~()~}") + "\n"
        for nest in sorted(nnl[location]):
            # nest = nnl[location][nest_txt]
            if nest.species_name_fk is not None and nest.species_name_fk.is_type(
                Type.objects.get(id=8)
            ):  # type 8 is Ghost
                list_txt += ghost_icon
            if nest.nestid.private is True:
                list_txt += private_reminder  # private property reminder
            list_txt += nest.nestid.get_name()  # nest name
            alts = NstAltName.objects.filter(main_entry=nest.nestid).exclude(
                hide_me=True
            )
            if len(alts) > 0:
                for alt in alts:
                    list_txt += "/" + alt.name
            if nest.nestid.notes is not None or nest.special_notes is not None:
                notef = []
                if nest.nestid.notes is not None:
                    notef.append(nest.nestid.notes)
                if nest.special_notes is not None:
                    notef.append(nest.special_notes)
                list_txt += " " + gen_parenthetical(notef)
            list_txt += ": " + (
                nest.species_name_fk.name
                if nest.species_name_fk is not None
                else nest.species_txt
            )
            if nest.confirmation is not True:
                list_txt += "*"
            list_txt += "\n"  # prepare for next item
        list_txt += "\n"
    return list_txt
Ejemplo n.º 5
0
def FB_empty(empties):
    """
    Handle parks with no reports for Facebook
    :param empties: nested_dict of empty nests in the form of empties[Neighborhood][nest] = NstLocation object
    :return: formatted string of parks arranged by neighborhood
    """

    mt_txt = decorate_text("No Reports", "[--  --]") + "\n"
    for location in sorted(empties.keys()):
        mt_txt += "• " + location + ": "
        first = True
        for park in empties[location]:
            if first is False:
                mt_txt += ", "
            if park.private:
                mt_txt += private_reminder
            mt_txt += park.get_name()
            first = False
        mt_txt += "\n"
    return mt_txt
Ejemplo n.º 6
0
def FB_post(nnl, rundate, shiftdate, mt=None, slist=None, rotnum=0):
    """
    generate and copy a Facebook post to the clipboard
    :param nnl: nested_dict in the format of nnl[area][nest] = NSLA object
    :param rundate: string of the date the list was generated
    :param shiftdate: string of the date of the nest shift
    :param mt: nested_dict of empty nests—mt[nest] = NstLocation object
    :param slist: nested_dict of species-sorted nests—slist[species][nest] = NSLA object
    :param rotnum: rotation number (int)
    :return: the FB-formatted nest post
    """

    post = FB_preamble(rundate, shiftdate, rotnum)
    if slist is not None:
        post += FB_summary(slist)
        post += decorate_text(" • ", "---==<>==---") + "\n\n"
    post += FB_format_nests(nnl)
    if mt is not None:
        # post += decorate_text(" • ", "---==<>==---") + "\n\n"
        post += FB_empty(mt)
    return post
Ejemplo n.º 7
0
def FB_summary(summary):
    """
    :param summary: nested_dict in form summary[species][park] = park, where species is a string and park is NSLA
    :return: formatted string of nests organized by species
    """

    out = decorate_text("Summary", "[--  --]")
    for species in sorted(summary.keys()):
        out += "\n" + annotate_species_txt(species) + species + ": "
        first = True
        for nest in sorted(summary[species]):
            if first is False:
                out += ", "
            if nest.nestid.private:
                out += private_reminder
            out += nest.nestid.get_name()
            if nest.confirmation is not True:
                out += "*"
            first = False
    out += "\n\n"
    return out
Ejemplo n.º 8
0
def disc_posts(nnl2, rundate, shiftdate, rotnum=0, raw_nests=None):
    """
    generate and copy a Discord post to the clipboard

    assumes all lines are roughly the same length and you don't troll with a 2000+ chars line for a single region

    :param nnl: nested_dict in the format of nnl[area][nest] = NSLA object
    :param rundate: string of the date the list was generated
    :param shiftdate: string of the date of the nest shift
    :param mt: nested_dict of empty nests—mt[nest] = NstLocation object
    :param raw_nests: QuerySet of NSLA objects to pass to the important species finder
    :param rotnum: rotation number (int)
    :return: array of strings of Discord posts
    """

    list = []
    olen = 0
    max = 2000  # Discord post length limit
    pre = disc_preamble(rundate, shiftdate, rotnum)
    olen += len(pre)
    list.append("")  # this is required for things to split up right later
    list.append(pre)

    for loc in sorted(nnl2.keys()):
        loclst = decorate_text(loc, "__****__") + "\n"
        for nest in sorted(nnl2[loc]):
            loclst += nest.nestid.get_name()
            alts = NstAltName.objects.filter(main_entry=nest.nestid).exclude(
                hide_me=True
            )
            for alt in alts:
                loclst += "/" + alt.name
            loclst += (
                ": "
                + decorate_text(nest.species_txt, "****" if nest.confirmation else "__")
                + "\n"
            )
        if len(loclst) > 2000:
            raise Exception(
                f"""Nest list for sub-region {loc} exceeds 2000 characters,\
which causes Discord problems.  Consider breaking into smaller areas."""
            )
        olen += len(loclst)
        list.append(loclst)

    # Discord bean-counting to fit character limits
    num = olen // max + 1
    trg = olen // num
    outparts = []
    ix = 0
    count = 0
    tmpstr = ""
    for nbh in list:  # I honestly can't remember what nbh means
        if len(nbh) + count < max and count <= trg:
            tmpstr += nbh
            count += len(nbh)
        else:
            outparts.append(tmpstr)
            tmpstr = nbh
            count = 0
            ix += 1
    outparts.append(tmpstr)

    outparts.append(disc_important_species(raw_nests))

    return outparts