auto_website_update.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import time
  2. import webhook_listener
  3. import json
  4. class AutoWebsiteUpdate:
  5. def __init__(self):
  6. pass
  7. def run(self):
  8. webhooks = webhook_listener.Listener(handlers={"POST": self.process_post_request}, port=8090)
  9. webhooks.start()
  10. while True:
  11. print("alive...")
  12. time.sleep(300)
  13. def process_post_request(self, request, *args, **kwargs):
  14. stringData = "Received request:\n"
  15. + "Method: {}\n".format(request.method)
  16. + "Headers: {}\n".format(request.headers)
  17. + "Args (url path): {}\n".format(args)
  18. + "Keyword Args (url parameters): {}\n".format(kwargs)
  19. + "Body: {}".format(
  20. request.body.read(int(request.header["Content-Length"]))
  21. if int(request.headers.get("Content-Length", 0)) > 0
  22. else""
  23. )
  24. writer = open(r'reveived_data.txt','w')
  25. writer.write(stringData)
  26. writer.close()
  27. return "received"
  28. if __name__ == '__main__':
  29. autoWebsiteUpdate = AutoWebsiteUpdate()
  30. autoWebsiteUpdate.run()