#!/usr/bin/python3 from tweepy import StreamListener from lib.setup import import_config_file from lib.archival import archive_media_status from lib.echo_nextcloud import nextcloud_upload_media from lib.echo_mastodon import mastodon_upload_media import logging class TweetStreamer(StreamListener): def on_status(self, status): print(status._json) archive_filenames = archive_media_status(status) if(archive_filenames): config = import_config_file() for filename in archive_filenames: print(filename) try: nextcloud_upload_media( config['nextcloud'], config['nextcloud_upload_path'], filename, status.timestamp_ms) except Exception as e: print('Was unsuccessful in uploading the file.') print(e) try: mastodon_upload_media( config['mastodon'], archive_filenames, status.text) except Exception as e: print('Was unsuccessful echoing this post to Mastodon.') print(e) return super().on_status(status)