47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
import os
|
|
import time
|
|
import requests
|
|
import argparse
|
|
|
|
from pathlib import Path
|
|
from watchdog.observers import Observer
|
|
from watchdog.events import PatternMatchingEventHandler
|
|
|
|
|
|
class FileWatchdog(PatternMatchingEventHandler):
|
|
def __init__(self, file_pattern, user_token):
|
|
super(FileWatchdog, self).__init__(patterns=[file_pattern], ignore_directories=True)
|
|
self.pattern = file_pattern
|
|
self.user_token = user_token
|
|
|
|
def on_moved(self, event):
|
|
self.upload_report(event)
|
|
|
|
def upload_report(self, event):
|
|
report = open(os.path.join(event.dest_path), 'rb')
|
|
a = requests.post("https://dps.report/uploadContent?json=1&generator=ei&userToken={}".format(self.user_token),
|
|
files={"file": report})
|
|
print(a.json())
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('user_token', action='store')
|
|
args = parser.parse_args()
|
|
|
|
watch_path = os.path.join(Path.home(), "Documents", "Guild Wars 2", "addons", "arcdps", "arcdps.cbtlogs")
|
|
print(watch_path)
|
|
file_pattern = os.path.join("*.zevtc")
|
|
|
|
observer = Observer()
|
|
observer.schedule(FileWatchdog(file_pattern, args.user_token), watch_path, recursive=True)
|
|
observer.start()
|
|
|
|
while True:
|
|
time.sleep(1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|