Skip to content
Permalink
Browse files

fix for mementos containing (non-animated) GIFs posting to Twitter

  • Loading branch information...
shawnmjones committed Jul 11, 2019
1 parent 79b3561 commit a1753ee1c5bf7211495b131f6b07a9d9c249593f
Showing with 19 additions and 3 deletions.
  1. +1 −1 docs/source/conf.py
  2. +17 −1 raintale/storytellers/twitter.py
  3. +1 −1 raintale/version.py
@@ -26,7 +26,7 @@
# The short X.Y version
version = u''
# The full version, including alpha/beta/rc tags
release = u'0.2019.07.11.031608'
release = u'0.2019.07.11.140435'


# -- General configuration ---------------------------------------------------
@@ -3,12 +3,15 @@
import tempfile
import os
import time
import io
import sys # for debugging
import pprint # for debugging

import twitter
import requests

from jinja2 import Template
from PIL import Image

from .storyteller import ServiceStoryteller, get_story_elements, StoryTellerCredentialParseError, split_multipart_template
from ..surrogatedata import datauri_to_data
@@ -94,10 +97,23 @@ def publish_story(self, story_output_data):
f.write(filedata)
module_logger.debug("temporary file name is {}".format(f.name))
tweet_media.append(f)
elif os.path.splitext(media_uri)[1] == '.gif':
# Twitter does not allow multiple animated GIFs, and an imagereel would be a data URI, but it still blocks regular GIFs
# TODO: actually check the content-type

r = requests.get(media_uri)

if r.status_code == 200:
ifp = io.BytesIO(r.content)
converted_im = Image.open(ifp)
converted = tempfile.NamedTemporaryFile(prefix='raintale-', suffix="png", delete=False)
converted_im.save(converted, "PNG")
tweet_media.append(converted)

else:
tweet_media.append(media_uri)

module_logger.info("thread tweet media: \n{}".format(
module_logger.debug("thread tweet media: \n{}".format(
tweet_media
))

@@ -1,3 +1,3 @@
__appname__ = "raintale"
__appversion__ = '0.2019.07.11.031608'
__appversion__ = '0.2019.07.11.140435'
__useragent__ = "{}/{}".format(__appname__, __appversion__)

0 comments on commit a1753ee

Please sign in to comment.
You can’t perform that action at this time.