add upload report method
This commit is contained in:
parent
1d17bac3da
commit
db888a8236
|
|
@ -1,6 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
import time
|
||||
import requests
|
||||
import argparse
|
||||
|
||||
from pathlib import Path
|
||||
from watchdog.observers import Observer
|
||||
|
|
@ -8,21 +10,33 @@ from watchdog.events import PatternMatchingEventHandler
|
|||
|
||||
|
||||
class FileWatchdog(PatternMatchingEventHandler):
|
||||
def __init__(self, file_pattern):
|
||||
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_created(self, event):
|
||||
print(event.src_path)
|
||||
self.upload_report(event)
|
||||
|
||||
def upload_report(self, event):
|
||||
report = open(os.path.join(event.src_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")
|
||||
file_pattern = os.path.join("*.zevtc")
|
||||
|
||||
|
||||
observer = Observer()
|
||||
observer.schedule(FileWatchdog(file_pattern), watch_path, recursive=True)
|
||||
observer.schedule(FileWatchdog(file_pattern, args.user_token), watch_path, recursive=True)
|
||||
observer.start()
|
||||
|
||||
while True:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user