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 usocket as socket
|
||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
|
with open('token') as f:
|
||||||
|
token = f.readline().strip('\n')
|
||||||
|
|
||||||
def main():
|
|
||||||
|
def send_msg(text, title=""):
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
|
|
||||||
host = "ntfy.acorneroftheweb.com"
|
host = "ntfy.acorneroftheweb.com"
|
||||||
token = ""
|
|
||||||
port = 443
|
port = 443
|
||||||
|
|
||||||
ai = socket.getaddrinfo(host, port)
|
ai = socket.getaddrinfo(host, port)
|
||||||
@ -24,9 +26,10 @@ Host: {host}\r
|
|||||||
Content-Type: application/json\r
|
Content-Type: application/json\r
|
||||||
Authorization: Bearer {token}
|
Authorization: Bearer {token}
|
||||||
Accept: */*\r
|
Accept: */*\r
|
||||||
|
Connection: close\r
|
||||||
Content-Length: {content_length}\r
|
Content-Length: {content_length}\r
|
||||||
\r\n"""
|
\r\n"""
|
||||||
body = '{"topic": "d1", "message": "Hejsan", "title": "Dab"}'
|
body = '{"topic": "d1", "message": "' + text + '", "title": "' + title + '"}'
|
||||||
|
|
||||||
|
|
||||||
body_bytes = body.encode('ascii')
|
body_bytes = body.encode('ascii')
|
||||||
@ -41,9 +44,13 @@ Content-Length: {content_length}\r
|
|||||||
print(payload)
|
print(payload)
|
||||||
|
|
||||||
s.write(payload)
|
s.write(payload)
|
||||||
print(s.read(4096))
|
print(s.read())
|
||||||
|
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
send_msg("Hello there")
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user