Changeset - 935a6b927e50
[Not reviewed]
default
0 3 0
Dennis Fink - 7 years ago 2018-03-31 16:20:58
dennis.fink@c3l.lu
Added mastodon support
3 files changed with 27 insertions and 6 deletions:
0 comments (0 inline, 0 general)
requirements.txt
Show inline comments
 
#
 
# This file is autogenerated by pip-compile
 
# Make changes in requirements.in, then run this to update:
 
# To update, run:
 
#
 
#    pip-compile requirements.in
 
#    pip-compile --output-file requirements.txt requirements.in
 
#
 
decorator==4.2.1          # via mastodon.py
 
dominate==2.1.17          # via flask-bootstrap
 
flask-bootstrap==3.3.5.7
 
flask-httpauth==3.1.0
 
@@ -12,10 +13,13 @@ itsdangerous==0.24        # via flask
 
jinja2==2.8               # via flask
 
jsonschema==2.5.1
 
markupsafe==0.23          # via jinja2
 
mastodon.py==1.2.2
 
oauthlib==1.0.3           # via requests-oauthlib
 
python-dateutil==2.7.2    # via mastodon.py
 
pytz==2018.3              # via mastodon.py
 
requests-oauthlib==0.6.1  # via tweepy
 
requests==2.9.1           # via requests-oauthlib, tweepy
 
six==1.10.0               # via tweepy
 
requests==2.9.1           # via mastodon.py, requests-oauthlib, tweepy
 
six==1.10.0               # via mastodon.py, python-dateutil, tweepy
 
tweepy==3.5.0
 
visitor==0.1.2            # via flask-bootstrap
 
werkzeug==0.11.4          # via flask
setup.py
Show inline comments
 
@@ -9,7 +9,7 @@ packages.append('spaceapi.schema')
 

	
 
setup(
 
    name='c3l_spaceapi',
 
    version='0.0.12',
 
    version='0.0.13',
 
    url=None,
 
    license='GPLv3+',
 
    author='Dennis Fink',
 
@@ -27,5 +27,6 @@ setup(
 
        'Flask-Bootstrap',
 
        'jsonschema',
 
        'tweepy',
 
        'Mastodon.py',
 
    ]
 
)
spaceapi/utils.py
Show inline comments
 
@@ -7,7 +7,7 @@ from functools import wraps
 
from flask import request, current_app
 

	
 
import tweepy
 

	
 
import mastodon
 

	
 
default_json_file = os.path.abspath('default.json')
 
last_state_file = os.path.abspath('laststate.json')
 
@@ -65,6 +65,16 @@ def post_tweet(tweet, spaceapi=None):
 
            api.update_status(tweet, lat=spaceapi['location']['lat'], lon=spaceapi['location']['lon'])
 

	
 

	
 
def post_toot(toot):
 
    if 'MASTODON_USERCRED_FILE' in current_app.config:
 
        api = mastodon.Mastodon(
 
            client_id='c3l_spaceapi_clientcred.secret',
 
            access_token=current_app.config['MASTODON_USERCRED_FILE'],
 
            api_base_url='https://chaos.social'
 
        )
 
        api.status_post(toot, visibility='public')
 

	
 

	
 
class Singleton:
 

	
 
    def __new__(cls, *args, **kwargs):
 
@@ -160,6 +170,12 @@ class ActiveStatus(Singleton, dict):
 
            current_app.logger.error('Sending tweet failed! %s' % e,
 
                                     exc_info=True)
 

	
 
        try:
 
            post_toot(tweet)
 
        except Exception as e:
 
            current_app.logger.error('Sending toot failed! %s' % e,
 
                                     exc_info=True)
 

	
 
    def set_new_state(self, value=None, trigger_person=None, message=None):
 

	
 
        if value is not None and value != self['state']['open']:
0 comments (0 inline, 0 general)