This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
twitter_media_tool/lib/TweetStreamer.py

48 lines
1.5 KiB
Python
Raw Permalink Normal View History

#!/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
2020-04-25 17:09:07 -05:00
import logging
class TweetStreamer(StreamListener):
"""
TweetStreamer class definition
Arguments:
StreamListener {obj} -- Tweepy API StreamListener object
"""
def on_status(self, status):
"""
Method definition for what happens when a new status is made
Arguments:
status {obj} -- Tweepy "Status" object
Returns:
super -- on_status() super method
"""
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)