Skip to content

Instantly share code, notes, and snippets.

@Snuggle
Last active July 24, 2022 15:14
Show Gist options
  • Save Snuggle/265afddef76df0a2359f7daa9302aa53 to your computer and use it in GitHub Desktop.
Save Snuggle/265afddef76df0a2359f7daa9302aa53 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import mastodon as Mastodon
import requests
url = "https://scontent-man2-1.cdninstagram.com/v/t51.2885-15/294852204_824351222308449_3836600275452228447_n.jpg?stp=dst-jpg_e35_p480x480&_nc_ht=scontent-man2-1.cdninstagram.com&_nc_cat=109&_nc_ohc=gNaRLPxrcjUAX-Esrfg&tn=I6IE7pLwRFWQAD-P&edm=AJ9x6zYBAAAA&ccb=7-5&ig_cache_key=Mjg4Nzg5OTEyNjA1NDM4NTUwNQ%3D%3D.2-ccb7-5&oh=00_AT8KLG2PPEayIRAT7hVQtGSp48nE9vGGNWz8_ZdoBywfpg&oe=62E3A11E&_nc_sid=cff2a4"
print(Mastodon)
#Mastodon.Mastodon.create_app(
# 'snuggle_pixelfed',
# api_base_url = 'https://pixelfed.social',
# to_file = 'pytooter_clientcred.secret'
#)
mastodon = Mastodon.Mastodon(
debug_requests = False,
access_token = 'pytooter_usercred.secret',
api_base_url = 'https://pixelfed.social'
)
def get_image(url):
try:
response = requests.get(url)
response.raw.decode_content = True
return response.content
except Exception as e:
print(e)
media = mastodon.media_post(media_file = get_image(url), mime_type = "image/jpeg")
print(media["id"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment