VS
#!/usr/local/bin/python3.9
print("Content-type:text/html\n\n")
import datetime
import cherrypy
import simplejson
path_log = '/var/www/project/tmp/HOOKS.txt'
data_log = datetime.date.today()
class Root(object):
@cherrypy.expose
def update(self):
cl = cherrypy.request.headers['Content-Length']
rawbody = cherrypy.request.body.read(int(cl))
body = simplejson.loads(rawbody)
# do_something_with(body)
#return "Updated %r." % (rawbody,)
#return "Updated %r." % (rawbody)
# print(rawbody)
@cherrypy.expose
def index(self):
cl = cherrypy.request.headers['Content-Length']
rawbody = cherrypy.request.body.read(int(cl))
with open(path_log, 'a') as e:
e.write(data_log.strftime('%d-%m-%Y %H:%M:%S') + f' {rawbody}\n')
print(rawbody)
# return rawbody
cherrypy.config.update({
'server.socket_host' : '0.0.0.0',
'server.socket_port' : 5000,
})
#cherrypy.quickstart(self, script_name='/')
cherrypy.quickstart(Root(), script_name='/wt')
