patrick_logger.log_it("INFO:    And the length of that title is: " + str(the_length), 2)
    if the_title in open('/lovecraft/titles.txt').read():    # Incidentally, this is a really bad idea if the log of titles ever gets very big
        patrick_logger.log_it("That title's been used! Trying again ...\n\n\n")
        the_length = 300                                                            # Force the loop to grind through again
    else:
        patrick_logger.log_it("   That's a new title!", 2)

patrick_logger.log_it("OK, we've got a title.\n\n", 2)

patrick_logger.log_it('INFO: tags are:' + pprint.pformat(normal_tags + temporary_tags), 2)
patrick_logger.log_it('INFO: requested story length is: ' + str(story_length) + ' sentences ... generating ...', 2)

the_content = gen_text(the_mapping, the_starts, markov_length=the_markov_length, sentences_desired=story_length, paragraph_break_probability=0.2)
the_lines = ["<p>" + the_line.strip() + "</p>" for the_line in the_content.split('\n\n')]
patrick_logger.log_it("the_lines: " + pprint.pformat(the_lines), 2)
the_content = "\n\n".join(the_lines)
patrick_logger.log_it("the_content: \n\n" + the_content)

# All right, we're ready. Let's go.
patrick_logger.log_it('INFO: Attempting to post the content', 2)
the_status = social_media.tumblr_text_post(autolovecraft_client, normal_tags + temporary_tags, the_title, the_content)
patrick_logger.log_it('INFO: the_status is: ' + pprint.pformat(the_status), 2)

try:
    patrick_logger.log_it('INFO: Adding title of that post to list of titles', 2)
    open('/lovecraft/titles.txt', 'a').write(the_title + '\n')
except IOError:
    patrick_logger.log_it("ERROR: Can't add the title to the list of used titles.", 0)

patrick_logger.log_it('INFO: We\'re done', 2)
    the_file.close()
except IOError:
    patrick_logger.log_it("ERROR: Couldn't open, or couldn't read, or couldn't close, the content file", 0)
    sys.exit(2)

the_maximum_roll = weighted_probability(len(the_content))
the_dice_roll = random.random()
patrick_logger.log_it('INFO: Length of content is ' + str(len(the_content)) + '\n   and the dice roll was ' + str(the_dice_roll) + '\n   And the maximum score to post at that length is ' + str(the_maximum_roll), 2)
if the_dice_roll < the_maximum_roll:
    # Make the request
    patrick_logger.log_it('INFO: Attempting to post the content', 2)
    the_lines = ["<p>" + the_line.strip() + "</p>" for the_line in the_content.split('\n\n')]
    patrick_logger.log_it("the_lines: " + pprint.pformat(the_lines))
    the_content = "\n\n".join(the_lines)
    patrick_logger.log_it("the_content: \n\n" + the_content)
    the_status = social_media.tumblr_text_post(Irish_lit_discourses_client, normal_tags + temporary_tags, the_title, the_content)
    # Empty the existing content file.
    try:
        patrick_logger.log_it('INFO: Opening the file for writing', 2)
        the_file = open(the_content_path, 'w')
        patrick_logger.log_it('INFO: About to truncate file; file position is ' + str(the_file.tell()), 2)
        the_file.truncate(0)
        patrick_logger.log_it('INFO: About to close file', 2)
        the_file.close()
    except IOError:
        patrick_logger.log_it('ERROR: unable to fully empty ' + the_content_path, 0)
        patrick_logger.log_it('... the_file is' + pprint.pformat(the_file), 2)
else:
    patrick_logger.log_it("INFO: Not posting; length of accumulated content is currently " + str(len(the_content)), 2)

patrick_logger.log_it('INFO: We\'re done', 2)
예제 #3
0
        patrick_logger.log_it("   That's a new title!", 2)

patrick_logger.log_it("OK, we've got a title.\n\n", 2)

patrick_logger.log_it('INFO: tags are:' + pprint.pformat(the_tags), 2)
patrick_logger.log_it('INFO: requested story length is: ' + str(story_length) + ' sentences ... generating ...', 2)

the_content = genny.gen_text(sentences_desired=story_length, paragraph_break_probability=0.2)
the_lines = ["<p>" + the_line.strip() + "</p>" for the_line in the_content.split('\n\n')]
patrick_logger.log_it("the_lines: " + pprint.pformat(the_lines), 2)
the_content = "\n\n".join(the_lines)
patrick_logger.log_it("the_content: \n\n" + the_content)

# All right, we're ready. Let's go.
patrick_logger.log_it('INFO: Attempting to post the content', 2)
the_status, the_tumblr_data = social_media.tumblr_text_post(autolovecraft_client, the_tags, the_title, the_content)
patrick_logger.log_it('INFO: the_status is: ' + pprint.pformat(the_status), 2)
patrick_logger.log_it('INFO: the_tumblr_data is: ' + pprint.pformat(the_tumblr_data), 2)

try:
    patrick_logger.log_it('INFO: Adding title of that post to list of titles', 2)
    with open('/lovecraft/titles.txt', 'a') as f:
        f.write(the_title + '\n')
except IOError:
    patrick_logger.log_it("ERROR: Can't add the title to the list of used titles.", 0)

# Keep an archived copy
post_data = {'title': the_title, 'text': the_content, 'time': datetime.datetime.now().isoformat() }
post_data['formatted_text'], post_data['tags'] = the_lines, the_tags
post_data['status_code'], post_data['tumblr_data'] = the_status, the_tumblr_data
archive_name = "%s — %s.json.bz2" % (the_status['id'], the_title)
예제 #4
0
    first_sentence = ''.join(
        list(filter(None, re.split("([!?.]+)", content_lines[0])))
        [0:2])  # We'll use this as the summary in the table of contents.
    content_lines = [
        "<p>" + the_line.strip() + "</p>" for the_line in content_lines
        if len(the_line.strip()) > 0
    ]
    the_content = '\n'.join(content_lines)
    print("INFO: postprocessed content is:\n\n" + "\n".join(content_lines))

    print('INFO: Chapter title is "%s."' % the_title)
    print("INFO: tags are %s." % str(recurring_tags + temporary_tags))

    # All right, post this content
    print('\nINFO: Attempting to post the content')
    the_status, the_tumblr_data = social_media.tumblr_text_post(
        ulysses_client, the_tags, the_title, the_content)
    print('\nINFO: the_status is: ' + dump_str(the_status))
    print('\nINFO: the_tumblr_data is: ' + dump_str(the_tumblr_data))

    new_post_url = blog_url + "post/" + str(the_status['id'])

    # Assemble some text to write to the index file
    html_tags = ' | '.join([
        '<a rel="me muse" href="%s">%s</a>' %
        (html.escape(blog_url + "tagged/" + the_tag), the_tag)
        for the_tag in the_tags.split(', ')
    ])

    # Avoid using a really really long first sentence as a summary (a problem sometimes in tests with "Penelope").
    while len(first_sentence) > 600 or len(first_sentence.split(' ')) > 150:
        first_sentence = ' '.join(
content_lines = the_content.split("\n")

# Now, split the first paragraph into sentences, keeping the final punctuation and joining it back to the end of the sentence.
first_sentence = ''.join(list(filter(None, re.split("([!?.]+)", content_lines[0])))[0:2])       # We'll use this as the summary in the table of contents.

content_lines = [ "<p>" + the_line.strip() + "</p>" for the_line in content_lines if len(the_line.strip()) > 0 ]
the_content = '\n'.join(content_lines)
log_it("INFO: postprocessed content is:\n\n" + "\n".join(content_lines), 3)

log_it('INFO: Chapter title is "%s."' % the_title, 2)
log_it("INFO: tags are %s." % str(recurring_tags + temporary_tags), 2)

# All right, post this content
log_it('\nINFO: Attempting to post the content', 1)
the_status = social_media.tumblr_text_post(ulysses_client, the_tags, the_title, the_content)
log_it('\nINFO: the_status is: ' + pprint.pformat(the_status), 2)
log_it(dump(the_status), 2)

new_post_url = blog_url + "post/" + str(the_status['id'])

# Assemble some text to write to the index file
html_tags = ' | '.join([ '<a rel="me muse" href="%s">%s</a>' % (html.escape(blog_url + "tagged/" + the_tag), the_tag) for the_tag in the_tags.split(', ') ])

# Avoid using a really really long first sentence as a summary (a problem sometimes in tests with "Penelope").
while len(first_sentence) > 600 or len(first_sentence.split(' ')) > 150:
    first_sentence = ' '.join(first_sentence.split(' ')[0 : math.floor(len(first_sentence.split(' ')) * 0.75)]) + '…'   # Lop off the last quarter and try again.

the_line = '<li><a rel="me muse" href="%s">%s</a>' %(new_post_url, the_title)
the_line += ' (%s), ' %  datetime.date.today().strftime("%d %B %Y")
the_line += current_run_data[ 'ch%02ddesc' % which_script ]