Beispiel #1
0
def renderPlaceQuotation(wander:dict):
    """
    Return a quotation related to the current location.
    """
    talking_about = data.hydrateLocation(wander['location']).pleiades_id
    if not talking_about:
        print("Error: place not found")
        if not WRITE_THE_STORIES:
            writeStory({'type':'placeholder', 'text':str("There was no story for " + str(talking_about)) , 'state':copy.deepcopy(wander)})
        return renderNearbyPlaceQuotation(wander, data.hydrateLocation(wander['location']))
    #    return {'type':'quotation', 'state':copy.deepcopy(wander)}.update(data.renderPerseusFromPleiades(talking_about))
    output_text = None
    if WRITE_THE_STORIES:
        output_text = data.renderPerseusFromPleiades(talking_about)
    else:
        print("Skipping story for " + str(talking_about))
        writeStory({'type':'placeholder', 'text':str("Insert story about " + str(talking_about)) , 'state':copy.deepcopy(wander)})
    #print(output_text)
    if output_text:
        render_base = {'type':'quotation', 'state':copy.deepcopy(wander)}
        render_base.update(output_text)
        writeStory(render_base)
    else:
        print("No output text found for " + str(talking_about))
        return renderNearbyPlaceQuotation(wander, data.hydrateLocation(wander['location']))
Beispiel #2
0
def fleshOutDescription(wander:dict, desc):
    """
    Given a paragraph of text, go through it, replacing the variables with those extracted from the wanderer state.
    """
    text_departing_from_name = data.getNearestName(data.hydrateLocation(wander['last_city']))
    text_travel_route_type = descriptionJourneyType(wander['journey']['type'])
    text_travel_route_type_name = descriptionJourneyTypeName(wander['journey']['type'])
    text_destination_name = data.getNearestName(data.hydrateLocation(wander['destination']))
    miles_distance = (float(wander['journey']['distance']) * settings.KILOMETERS_TO_MILES) # km-to-miles
    distance_text = ["a journey of about {} miles".format(str(math.floor(miles_distance))),
                     "about {} miles away".format(str(math.floor(miles_distance))),
                     "a distance of about {} miles".format(str(math.floor(miles_distance))),
                     "at least {} miles".format(str(math.floor(miles_distance)))]
    text_distance = settings.TEXT_RNG.choice(distance_text)

    variable_swap = {'from':text_departing_from_name, 'type':text_travel_route_type, 'type_name':text_travel_route_type_name, 'destination':text_destination_name, 'distance':text_distance, 'miles':str(math.floor(miles_distance)), 'inscription':'Est in Arcadia Ego' }

    if settings.WRITE_THE_STORIES:
        if "{inscription}" in desc:
            while "{inscription}" in desc:
                if settings.DELAY_FOR_BANDWIDTH:
                    time.sleep(0.6)
                print(desc)
                try:
                    desc = desc.replace("{inscription}", renderInscription(wander), 1)
                except settings.DataSourceAccessProblem as err:
                    desc = desc.replace("{inscription}", "Est in Arcadia Ego", 1)

    output = str(desc.format(**variable_swap))
    if (output != desc):
        return fleshOutDescription(wander, output) # recurse so we can handle nested variables TODO: add nested variables
    return output
Beispiel #3
0
def fleshOutDescription(wander: dict, desc):
    """
    Given a paragraph of text, go through it, replacing the variables with those extracted from the wanderer state.
    """
    text_departing_from_name = data.getNearestName(
        data.hydrateLocation(wander['last_city']))
    text_travel_route_type = descriptionJourneyType(wander['journey']['type'])
    text_travel_route_type_name = descriptionJourneyTypeName(
        wander['journey']['type'])
    text_destination_name = data.getNearestName(
        data.hydrateLocation(wander['destination']))
    miles_distance = (float(wander['journey']['distance']) *
                      settings.KILOMETERS_TO_MILES)  # km-to-miles
    distance_text = [
        "a journey of about {} miles".format(str(math.floor(miles_distance))),
        "about {} miles away".format(str(math.floor(miles_distance))),
        "a distance of about {} miles".format(str(math.floor(miles_distance))),
        "at least {} miles".format(str(math.floor(miles_distance)))
    ]
    text_distance = settings.TEXT_RNG.choice(distance_text)

    variable_swap = {
        'from': text_departing_from_name,
        'type': text_travel_route_type,
        'type_name': text_travel_route_type_name,
        'destination': text_destination_name,
        'distance': text_distance,
        'miles': str(math.floor(miles_distance)),
        'inscription': 'Est in Arcadia Ego'
    }

    if settings.WRITE_THE_STORIES:
        if "{inscription}" in desc:
            while "{inscription}" in desc:
                if settings.DELAY_FOR_BANDWIDTH:
                    time.sleep(0.6)
                print(desc)
                try:
                    desc = desc.replace("{inscription}",
                                        renderInscription(wander), 1)
                except settings.DataSourceAccessProblem as err:
                    desc = desc.replace("{inscription}", "Est in Arcadia Ego",
                                        1)

    output = str(desc.format(**variable_swap))
    if (output != desc):
        return fleshOutDescription(
            wander, output
        )  # recurse so we can handle nested variables TODO: add nested variables
    return output
Beispiel #4
0
def textQuotation(t):

    possible_story_titles = [
        "A story about {place}", "What {author} once said about {place}",
        "A story by {author} about {place} from _{book}_",
        "An extract from _{book}_ by {author}",
        "On {place}, according to {author}", "On the subject of {place}",
        "{place} in _{book}_", "An account of {place}",
        "A story about {place} by {author}", "The story of {place}"
    ]
    place_name = data.getNearestName(t['place'])
    if not place_name:
        place_name = data.getNearestName(
            data.hydrateLocation(t['state']['location']))
    author_name = t['author']
    title_data = {
        'place': place_name,
        'author': author_name,
        'book': t['book_title']
    }

    if author_name == "Virgil":
        intro = quoteIntroductions(t, True)
        writeToBook(intro.format(**title_data))
        writeToBook(
            "\n## {place} in Virgil's _{book}_".format(**title_data).title())
    else:
        intro = quoteIntroductions(t)
        writeToBook(intro.format(**title_data))
        book_string = "\n## " + str(random.choice(possible_story_titles)) + ""
        writeToBook(book_string.format(**title_data).title())
    writeToBook(convertHTML(t['text']))
    #writeToBook(t['text'])
    pass
Beispiel #5
0
def textQuotation(t):
    

    possible_story_titles = ["A story about {place}",
                             "What {author} once said about {place}",
                             "A story by {author} about {place} from _{book}_",
                             "An extract from _{book}_ by {author}",
                             "On {place}, according to {author}",
                             "On the subject of {place}",
                             "{place} in _{book}_",
                             "An account of {place}",
                             "A story about {place} by {author}",
                             "The story of {place}"
                             ]
    place_name = data.getNearestName(t['place'])
    if not place_name:
        place_name = data.getNearestName(data.hydrateLocation(t['state']['location']))
    author_name = t['author']
    title_data = {'place': place_name, 'author': author_name, 'book': t['book_title']}
    
    if author_name == "Virgil":
        intro = quoteIntroductions(t, True)
        writeToBook(intro.format(**title_data))
        writeToBook("\n## {place} in Virgil's _{book}_".format(**title_data).title())
    else:    
        intro = quoteIntroductions(t)
        writeToBook(intro.format(**title_data))
        book_string = "\n## " + str(random.choice(possible_story_titles)) + ""
        writeToBook(book_string.format(**title_data).title())
    writeToBook(convertHTML(t['text']))
    #writeToBook(t['text'])
    pass
Beispiel #6
0
def wanderSelectDestination(wander):
    """
    The wanderer needs to select the next destination.
    """
    if DISPLAY_WANDERING_PROGRESS:
        print("wanderSelectDestination")
    current = data.hydrateLocation(wander['location']).orbis_id
    edges = data.findOrbisEdges(current)
    weighted_edges = scoreEdgesByVisits(wander, edges)
    #weighted_edges = data.scoreByDistance(data.hydrateLocation(wander['location']), edges)
    try:
        #destination = random.choice(edges)
        destination = settings.TRAVEL_RNG.choice(edges, p=weighted_edges)
    except Exception as err:
        print (err)
        return
    wander['destination'] = data.hydrateLocation(data.makeOrbisLocation(destination['target']))
    wander['journey'] = destination
    wander['last_city'] = data.hydrateLocation(wander['location'])
    wander['state'] = wanderTravel
    renderSelectDestination(wander)
    return wander
Beispiel #7
0
def renderPlaceQuotation(wander: dict):
    """
    Return a quotation related to the current location.
    """
    talking_about = data.hydrateLocation(wander['location']).pleiades_id
    if not talking_about:
        print("Error: place not found")
        if not WRITE_THE_STORIES:
            writeStory({
                'type':
                'placeholder',
                'text':
                str("There was no story for " + str(talking_about)),
                'state':
                copy.deepcopy(wander)
            })
        return renderNearbyPlaceQuotation(
            wander, data.hydrateLocation(wander['location']))
    #    return {'type':'quotation', 'state':copy.deepcopy(wander)}.update(data.renderPerseusFromPleiades(talking_about))
    output_text = None
    if WRITE_THE_STORIES:
        output_text = data.renderPerseusFromPleiades(talking_about)
    else:
        print("Skipping story for " + str(talking_about))
        writeStory({
            'type': 'placeholder',
            'text': str("Insert story about " + str(talking_about)),
            'state': copy.deepcopy(wander)
        })
    #print(output_text)
    if output_text:
        render_base = {'type': 'quotation', 'state': copy.deepcopy(wander)}
        render_base.update(output_text)
        writeStory(render_base)
    else:
        print("No output text found for " + str(talking_about))
        return renderNearbyPlaceQuotation(
            wander, data.hydrateLocation(wander['location']))
Beispiel #8
0
def wanderSelectDestination(wander):
    """
    The wanderer needs to select the next destination.
    """
    if DISPLAY_WANDERING_PROGRESS:
        print("wanderSelectDestination")
    current = data.hydrateLocation(wander['location']).orbis_id
    edges = data.findOrbisEdges(current)
    weighted_edges = scoreEdgesByVisits(wander, edges)
    #weighted_edges = data.scoreByDistance(data.hydrateLocation(wander['location']), edges)
    try:
        #destination = random.choice(edges)
        destination = settings.TRAVEL_RNG.choice(edges, p=weighted_edges)
    except Exception as err:
        print(err)
        return
    wander['destination'] = data.hydrateLocation(
        data.makeOrbisLocation(destination['target']))
    wander['journey'] = destination
    wander['last_city'] = data.hydrateLocation(wander['location'])
    wander['state'] = wanderTravel
    renderSelectDestination(wander)
    return wander