More dynamic
This commit is contained in:
parent
c5e4915f5f
commit
d4def45508
15
main.py
15
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()
|
||||
|
Loading…
Reference in New Issue
Block a user