Esempio n. 1
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
Esempio n. 2
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
Esempio n. 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
Esempio n. 4
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