Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for "answer" posts #79

Open
jonfortescue opened this issue Feb 19, 2016 · 13 comments
Open

Support for "answer" posts #79

jonfortescue opened this issue Feb 19, 2016 · 13 comments

Comments

@jonfortescue
Copy link

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?

@Macman1234
Copy link

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"

@jonfortescue
Copy link
Author

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.

@Macman1234
Copy link

Macman1234 commented Jul 30, 2016

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
Copy link

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.

@sintelligentdesign
Copy link

sintelligentdesign commented Aug 3, 2016

@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)?

@jonfortescue
Copy link
Author

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

@sintelligentdesign
Copy link

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).

@Macman1234
Copy link

@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.

@bratchan
Copy link

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

@sintelligentdesign
Copy link

sintelligentdesign commented Jul 21, 2018

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.

@bratchan
Copy link

Cool

@bratchan
Copy link

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.

@sintelligentdesign
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants