Skip to content

Commit

Permalink
Increase Twitter character limit to 280
Browse files Browse the repository at this point in the history
Also increase minimum version of Python-Twitter to 3.0.

Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Nov 9, 2017
1 parent b677065 commit 7a9d2d3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# pywws - Python software for USB Wireless Weather Stations
# http://github.com/jim-easterbrook/pywws
# Copyright (C) 2008-16 pywws contributors
# Copyright (C) 2008-17 pywws contributors

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -214,7 +214,7 @@ def run(self):
extras_require = {
'daemon' : ['python-daemon'],
'sftp' : ['paramiko', 'pycrypto'],
'twitter' : ['python-twitter >= 2.1', 'oauth2'],
'twitter' : ['python-twitter >= 3.0', 'oauth2'],
},
zip_safe = False,
use_2to3 = True,
Expand Down
4 changes: 2 additions & 2 deletions src/doc/essentials/dependencies.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. pywws - Python software for USB Wireless Weather Stations
http://github.com/jim-easterbrook/pywws
Copyright (C) 2008-16 pywws contributors
Copyright (C) 2008-17 pywws contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -171,7 +171,7 @@ Twitter updates
The :py:mod:`pywws.ToTwitter` module can be used to send weather status messages to Twitter.
Posting to Twitter requires these modules:

* `python-twitter <https://github.com/bear/python-twitter>`_ v2.1 or higher
* `python-twitter <https://github.com/bear/python-twitter>`_ v3.0 or higher
* `python-oauth2 <https://github.com/simplegeo/python-oauth2>`_

::
Expand Down
5 changes: 3 additions & 2 deletions src/doc/guides/twitter.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. pywws - Python software for USB Wireless Weather Stations
http://github.com/jim-easterbrook/pywws
Copyright (C) 2008-14 Jim Easterbrook jim@jim-easterbrook.me.uk
Copyright (C) 2008-17 pywws contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -107,8 +107,9 @@ Include an image in your tweet

.. versionadded:: 14.05.dev1216

You can add an image to your tweets by specifying an image file location in the tweet template.
You can add up to four images to your tweets by specifying the image file locations in the tweet template.
Make the first line of the tweet ``media path`` where ``path`` is the absolute location of the file.
Repeat for any additional image files.
The "tweet_media.txt" example template shows how to do this.

The image could be from a web cam, or for a weather forecast it could be an icon representing the forecast.
Expand Down
27 changes: 10 additions & 17 deletions src/pywws/ToTwitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# pywws - Python software for USB Wireless Weather Stations
# http://github.com/jim-easterbrook/pywws
# Copyright (C) 2008-16 pywws contributors
# Copyright (C) 2008-17 pywws contributors

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -81,9 +81,9 @@ def post(self, status, media):
if len(media) > 1:
self.logger.error('Tweepy library cannot post multiple media')
if media:
self.api.update_with_media(media[0], status[:117], **self.kwargs)
self.api.update_with_media(media[0], status[:257], **self.kwargs)
else:
self.api.update_status(status[:140], **self.kwargs)
self.api.update_status(status[:280], **self.kwargs)

class PythonTwitterHandler(object):
def __init__(self, key, secret, latitude, longitude, timeout):
Expand All @@ -99,25 +99,18 @@ def __init__(self, key, secret, latitude, longitude, timeout):
'display_coordinates' : True}
else:
self.kwargs = {}
self.kwargs['verify_status_length'] = False

def post(self, status, media):
max_len = 140
max_len = 280
if media:
max_len -= len(media[:4]) * 23
status = status.strip()[:max_len]
if tuple(map(int, twitter.__version__.split('.'))) >= (3, 0):
args = dict(self.kwargs)
if media:
args['media'] = media
args['verify_status_length'] = False
self.api.PostUpdate(status, **args)
return
if len(media) > 1:
self.api.PostMultipleMedia(status, media[:4], **self.kwargs)
elif media:
self.api.PostMedia(status, media[0], **self.kwargs)
else:
self.api.PostUpdate(status, **self.kwargs)
args = dict(self.kwargs)
if media:
args['media'] = media
self.api.PostUpdate(status, **args)


class ToTwitter(object):
def __init__(self, params):
Expand Down
4 changes: 2 additions & 2 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '17.11.0'
_release = '1377'
_commit = '6489c63'
_release = '1378'
_commit = 'b677065'

0 comments on commit 7a9d2d3

Please sign in to comment.