Created
May 14, 2020 22:08
-
-
Save grubles/7872c4e2e8289efe41666ebe14129b34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run in satellite/api/examples directory | |
# note 0bin.net pasting requires zerobinpaste tool | |
# https://github.com/sametmax/0bin/blob/master/docs/.build/html/_sources/en/zerobinpaste_tool.txt | |
import time | |
from watchdog.observers import Observer | |
from watchdog.events import FileSystemEventHandler | |
import tweepy | |
import glob | |
import os | |
import subprocess | |
# add your twitter API keys here | |
consumer_key = "" | |
consumer_secret = "" | |
access_token = "" | |
access_token_secret = "" | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
api = tweepy.API(auth) | |
class Watcher: | |
# add the downloads directory you set api_data_reader.py to | |
DIRECTORY_TO_WATCH = "" | |
def __init__(self): | |
self.observer = Observer() | |
def run(self): | |
event_handler = Handler() | |
self.observer.schedule(event_handler, self.DIRECTORY_TO_WATCH, recursive=True) | |
self.observer.start() | |
try: | |
while True: | |
time.sleep(5) | |
except: | |
self.observer.stop() | |
print "Error" | |
self.observer.join() | |
class Handler(FileSystemEventHandler): | |
@staticmethod | |
def on_any_event(event): | |
if event.is_directory: | |
return None | |
elif event.event_type == 'created': | |
# change this to your api_data_reader.py downloads directory and keep the * at the end | |
list_of_files = glob.glob('/home/user/satellite/api/examples/downloads/*') | |
latest_file = max(list_of_files, key=os.path.getctime) | |
print(latest_file) | |
newest_message = open(latest_file, "rb") | |
args = ['zerobinpaste', '-u', 'https://0bin.net', '-n', '-e', 'never', latest_file] | |
print(args) | |
zerobin_return = subprocess.check_output(args) | |
print(zerobin_return) | |
api.update_status(newest_message.read(240) + " \n0bin paste: " + str(zerobin_return)) | |
newest_message.close() | |
if __name__ == '__main__': | |
w = Watcher() | |
w.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment