zo a révisé ce gist . Aller à la révision
1 file changed, 24 insertions
webhooks_cgi.py(fichier créé)
| @@ -0,0 +1,24 @@ | |||
| 1 | + | import json | |
| 2 | + | import os | |
| 3 | + | import sys | |
| 4 | + | ||
| 5 | + | import cgitb | |
| 6 | + | cgitb.enable() | |
| 7 | + | ||
| 8 | + | class Webhooks: | |
| 9 | + | def __init__(self, fp, headers): | |
| 10 | + | self.fp = fp | |
| 11 | + | self.headers = headers | |
| 12 | + | ||
| 13 | + | def read_json(self): | |
| 14 | + | try: | |
| 15 | + | nbytes = int(self.headers.get("content-length")) | |
| 16 | + | except (TypeError, ValueError): | |
| 17 | + | nbytes = 0 | |
| 18 | + | data = self.fp.read(nbytes).decode("utf-8") | |
| 19 | + | return json.loads(data) | |
| 20 | + | ||
| 21 | + | if __name__ == "__main__": | |
| 22 | + | webhooks = Webhooks(sys.stdin.buffer, os.environ) | |
| 23 | + | message = webhooks.read_json() | |
| 24 | + | print(message) | |
Plus récent
Plus ancien