The code below delivers reports to a Discord server
Note - it requires discordhook to be set in your settings, pointing to a WebHook for your Discord server/channel.
import time import sys import requests import datetime import os import json import traceback f = open(sys.argv[1]) content = f.read() f.close() details = json.loads(content) #Settings hookid = details['options']['discordhook'] #Gather the files to send fileset = {} for n in details['files']: try: fileset[n[1]] = open(n[0],'rb') except: traceback.print_exc() pass #print(str(fileset)) #If there are any files, send 'em. if len(fileset) > 0: #Create an embed embd = {} embd['title'] = details['options']['title'] embd['description'] = "The Reports For " + datetime.datetime.now().strftime("%x") embd['footer'] = {} embd['footer']['text'] = 'From the ' + details['options']['sitename'] embd['author'] = {} embd['author']['name'] = details['options']['sitename'] embd['author']['url'] = details['options']['reporturl'].replace("http://","https://") content = {} content['embeds'] = [embd] #You can send an Embed OR files, not both. So send an introductory embed, wait a moment, then follow with files. try: requests.post(hookid,json=content) #Wait one second time.sleep(1) #Send the files themselves. requests.post(hookid,json=content, files=fileset) print('-----') print('SUCCESS') except: print('-----') print('FAILURE') #Clean up file handles for n in fileset: fileset[n].close()