diff --git a/main.py b/main.py index ffd9e64..b48f27e 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,14 @@ import usocket as socket import ssl +with open('token') as f: + token = f.readline().strip('\n') -def main(): + +def send_msg(text, title=""): s = socket.socket() host = "ntfy.acorneroftheweb.com" - token = "" port = 443 ai = socket.getaddrinfo(host, port) @@ -24,9 +26,10 @@ Host: {host}\r Content-Type: application/json\r Authorization: Bearer {token} Accept: */*\r +Connection: close\r Content-Length: {content_length}\r \r\n""" - body = '{"topic": "d1", "message": "Hejsan", "title": "Dab"}' + body = '{"topic": "d1", "message": "' + text + '", "title": "' + title + '"}' body_bytes = body.encode('ascii') @@ -41,9 +44,13 @@ Content-Length: {content_length}\r print(payload) s.write(payload) - print(s.read(4096)) + print(s.read()) s.close() +def main(): + send_msg("Hello there") + + main()