tumblr / pytumblr

A Python Tumblr API v2 Client
Apache License 2.0
723 stars 196 forks source link

How can I add a schedule state to my post #108

Closed DrunkCodes closed 6 years ago

DrunkCodes commented 6 years ago

Please I have being looking for away to add the schedule state to my post.

Any help will be appreciated .

jasonpenny commented 6 years ago

It's not documented, but there is a parameter that you can specify with the date and time for a post to be published when setting up a "queued" post: publish_on

import pytumblr

# pytumblr does not currently have support for setting 'publish_on', but this adds it for this file
old_post_valid_options = pytumblr.TumblrRestClient._post_valid_options
def new_post_valid_options(self, post_type=None):
    return ['publish_on'] + old_post_valid_options(self, post_type)
pytumblr.TumblrRestClient._post_valid_options = new_post_valid_options

client = pytumblr.TumblrRestClient(...)  # pass in your credentials
txt = client.create_text(
    "blogName",
    state="queue",
    publish_on="2018-05-17T21:59:00",  # I believe this time needs to be in UTC
    title="Testing",
    body="body of text post")
DrunkCodes commented 6 years ago

Thanks.

But am still trying to understand the code.

No big deal. I can still use it.

jasonpenny commented 6 years ago

The pytumblr.TumblrRestClient._post_valid_options = new_post_valid_options line is basically monkey-patching the pytumblr code to change its behavior.

Because the pytumblr code that you're using was probably installed with pip, you can't easily edit it and it does not currently allow you to use the param publish_on, so this code changes how pytumblr works when used in this file to add publish_on as a valid parameter to use.