pytumblr icon indicating copy to clipboard operation
pytumblr copied to clipboard

Support for "answer" posts

Open jonfortescue opened this issue 9 years ago • 13 comments

Currently there is no support for answer posts. While answer posts cannot be created, they can be edited.

I tried adding the functionality myself, but ran into issues with pytumblr recognizing answer posts. Any ideas?

jonfortescue avatar Feb 19 '16 12:02 jonfortescue

Do you mean creating answers to questions asked? If so, the way to do that through the tumblr API is to, through editing it, setting the "answer" tag to whatever you want to answer (which requires the changing of the valid parameters in the code), and setting the state from "submission" to "published"

Macman1234 avatar Jul 07 '16 22:07 Macman1234

The method _post_valid_options doesn't have any valid options for answer posts (see https://github.com/tumblr/pytumblr/blob/master/pytumblr/init.py#L469). Last time I tried working on this (which admittedly was a while ago), I thought it was more complicated than simply adding an if-statement to this one method... if I have time this weekend, I'll see if I can dig up what I did to get answer support. IIRC, though, it was fairly kludgey, which is why I opened an issue instead of making a pull request.

jonfortescue avatar Jul 09 '16 05:07 jonfortescue

Sorry about not responding earlier, but I got that to work simply by changing

valid = ['type', 'state', 'tags', 'tweet', 'date', 'format', 'slug']

to

valid = ['type', 'state', 'tags', 'tweet', 'date', 'format', 'slug', 'answer']

then used

asklist = client.submission('[my blog's name]')

for ask in asklist['posts']:
    if ask['type'] == 'answer':
        if ask['state'] == 'submission':
            client.edit_post('[my blog's name]', id=ask['id'], answer=[whatever I want my bot to answer to any given ask], state='published');

to answer every ask that hasn't yet been answered.

sorry if that was weirdly ambiguous with the brackets.

Macman1234 avatar Jul 30 '16 17:07 Macman1234

However, if you mean submitting answer posts to other blogs using pytumblr, I have no idea whether that is possible or how to do that if it is.

Macman1234 avatar Jul 30 '16 17:07 Macman1234

@Macman1234 I may have a slight improvement on your solution for answering questions: instead of adding 'answer' to the list of valid options for all post types, what about adding elif post_type == 'answer': valid += ['answer'] near the bottom of _post_valid_options() where all the other if statements are, and then answer asks using client.edit_post('[blog name]', id=[ask ID], type='answer', answer=[answer], state='published') (note the inclusion of a 'type' arg)?

sintelligentdesign avatar Aug 03 '16 02:08 sintelligentdesign

@sintelligentdesign That looks great to me. Have you done any testing with that solution?

jonfortescue avatar Aug 03 '16 18:08 jonfortescue

I've been using it in one of my projects and it's been working reliably. That said, I haven't written any tests for it. It's a minor change but that's still probably important (I'm just garbage at writing tests).

sintelligentdesign avatar Aug 03 '16 18:08 sintelligentdesign

@sintelligentdesign That's almost certainly a better way of implementing that then the way that I've been using: a lot more sane to prevent using "answer" in editing other types of posts. Thanks for that, I'll probably switch over to using it that way.

Macman1234 avatar Aug 08 '16 17:08 Macman1234

For answering the ask, is there a way to use an image with it?

bratchan avatar Jul 20 '18 19:07 bratchan

You can include an HTML <img> element in your answer field, which appears to work on desktop (but not mobile?), unless the post is set to a draft before being published, in which case the image seems to disappear (??). I can try to see if I can figure out something better (read: reliable) sometime this week.

sintelligentdesign avatar Jul 21 '18 22:07 sintelligentdesign

Cool

bratchan avatar Jul 23 '18 13:07 bratchan

Any luck for images? I know that when i answer one it auto uploads it. I was hoping not to host the images and let tumbrl handle them like i have been with answers.

bratchan avatar Jul 27 '18 18:07 bratchan

By "when I answer one it auto uploads it," are you talking about using the website and answering questions with images manually, or using the API? I assume the first but i just wanted to be sure.

According to the API docs, answer posts don't support the data field used in image posts, and when I gave editing an answer post by adding a data field a shot, it didn't return an error but it didn't work either.

One possibility, although you mentioned wanting to avoid hosting images outside of Tumblr, could be to use an image hosting service's API (I initially was going to suggest Imgur but when I looked the Imgur Python API was deprecated, bummer) and adding the link to the image in the answer field of the answer post. That still has the issue though of apparently not working on mobile (Maybe? Can anybody else test this? Maybe I'm just doing something wrong and dumb. I haven't tried Markdown as the post format but I can't imagine it would make a difference).

sintelligentdesign avatar Jul 30 '18 15:07 sintelligentdesign