Skip to content

Instantly share code, notes, and snippets.

@liesen
Created August 9, 2019 17:54
Show Gist options
  • Save liesen/5eb81e5977a9e80c90baa3a5b84d55e1 to your computer and use it in GitHub Desktop.
Save liesen/5eb81e5977a9e80c90baa3a5b84d55e1 to your computer and use it in GitHub Desktop.
Find a particular post from marklovejoydotcom.tumblr.com
import requests
import xmltodict
def find_post_by_photo_url(photo_url, start=0, num=50):
total = start + 1
while start < total:
r = requests.get('https://marklovejoydotcom.tumblr.com/api/read', params={'start': start, 'num': num})
r.raise_for_status()
d = xmltodict.parse(r.text)
posts = d['tumblr']['posts']
total = int(posts['@total'])
for post in posts['post']:
if post['@type'] == 'photo':
for post_photo_url in post['photo-url']:
if post_photo_url['#text'] == photo_url:
return post
start += num
if __name__ == '__main__':
post = find_post_by_photo_url('https://66.media.tumblr.com/tumblr_mej8emjrim1rbed58o1_500.jpg')
print(post['@url'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment