Publishing Reports to Discord

Before you use this script, you'll need to make a webhook on the channel you'd like to publish your reports to.

Then, paste the channel URL over «webhook url» in the code below, and paste it into your publish.py file in the reports folder.

import time
import sys
import requests
import datetime
import os
 
#Read the list of files to be uploaded
f = open(sys.argv[1],'r')
dta = f.read()
f.close()
 
#Settings 
hookid = "<<webhook url>>"
 
#Gather the files to send
lines = dta.split("\n")
fileset = {}
for n in lines:
    if len(n) > 0:        
        fileset[os.path.basename(n)] = open(n,'rb')
 
#If there are any files, send 'em.
if len(fileset) > 0:
 
    #Create an embed
    embd = {}
    embd['title'] = 'Daily Reports'
    embd['description'] = "The Reports For " + datetime.datetime.now().strftime("%x")
    embd['footer'] = {}
    embd['footer']['text'] = 'From the ARDI Demo Paintline System'
    embd['author'] = {}
    embd['author']['name'] = 'ARDI Paintline System'
    embd['author']['url'] = 'https://demo.optrix.com.au/s/pl/reportlist/'
 
    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.
    requests.post(hookid,json=content)
 
    #Wait one second
    time.sleep(1)
 
    #Send the files themselves.
    requests.post(hookid,json=content, files=fileset)
 
#Clean up file handles
for n in fileset:
    fileset[n].close()