Daily Steem-Python Challenge #10, Win 1 Steem!

in #contest8 years ago

For each tutorial we release there will be a relevant challenge where the winner receives 1 STEEM!

Challenge

Take the code from the tutorial from here. In the code you learned how to extract image urls from the Post object. However not every Steem platform stores the post metadata as gracefully as Steemit.com does. Below are 3 example posts where image urls are not as straight forward to retrieve from.

  1. Alter the code that is checks which platform was used to submit the post and use another way to retrieve the image url.
https://steemit.com/bescouted/@vladkuneberg/red-green-contrast
https://steemit.com/photofeed/@pcusine/hotel-w-barcelona-1516230216
https://steemit.com/colourfulphotography/@klborillo/flowers-for-sale-2018-01-18-00-15-59



That's it! Good luck to everyone participating!

Deadline

The prize money will be rewarded to the person that solves the problem first. If there is no solution within 7 days after this post has been submitted the prize pool expires.

Relevant Tutorial

Part 10: Use Urls To Retrieve Post Data And Construct A Dynamic Post With Steem-Python


If you have questions about the tutorial or the challenge then don't hesitate to comment below or contact us on Discord!

Sort:  

Look at the Steemd for this comment.

Unfortunately I think this challenge is much harder than it appears if you want to get finniky with it- especially since some markdown parsers don't always work the way you expect them to. How do you tell the difference between say a link that isn't really part of a post, and an image? You can also escape the ! to make an image appear as a link. Example: !link

Also - can't assume that the image is going to have a valid extension.
For example, this is a link if I paste it in straight up.
https://steemitimages.com/DQmS9uzwXDM9HWNSM5G5EPhFd9VLi5Miva5MZdTPjcwL6rb/image
Now if I add the ![](stuff) it gets interpreted as an image.

I think the only way to come up with a solution that really works for all platforms is to render the page on Steemit and inspect that for valid image tags with something like BeautifulSoup. Anything else will only work 99% of the time ;)

This one is indeed a lot harder that you might initially think. Actually an issue I have to deal with on a daily basis :P Will be going over your code now

Took some time to go over your comment. All of your points are valid and what they truly show is how complicated a decentralised system is. All of the different apps using their own slight variations makes for these annoying exceptions.

As for "render the page on Steemit and inspect that for valid image tags with something like BeautifulSoup" that sounds interesting. I have no experience with this.

How I currently deal with the issue is basically verifying each post beforehand and filtering out any 1% by hand ;)

Here is my solution.

I guess the best shot is creating different patterns/adapters for every known platform and if it's not a known platform fallback to general image finder pattern.

I agree on that. Will be going over the code now.

Your code check out fine, will transfer the Steem. Also learned something from you code, thanks ;)