More dynamic

This commit is contained in:
thepenguin 2023-03-16 12:47:45 +01:00
parent c5e4915f5f
commit d4def45508
No known key found for this signature in database
GPG Key ID: F258C8C10D060D5E

15
main.py
View File

@ -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()