Make requests
This commit is contained in:
parent
1abc943669
commit
6e302e6e63
29
main.py
29
main.py
|
@ -1,4 +1,6 @@
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
import socket
|
||||||
|
import ssl
|
||||||
|
|
||||||
# See https://tildegit.org/solderpunk/gemini-demo-1/src/branch/master/gemini-demo.py
|
# See https://tildegit.org/solderpunk/gemini-demo-1/src/branch/master/gemini-demo.py
|
||||||
|
|
||||||
|
@ -11,9 +13,9 @@ class Application():
|
||||||
self.current_URL = "about:home"
|
self.current_URL = "about:home"
|
||||||
|
|
||||||
def updateContent(self):
|
def updateContent(self):
|
||||||
text = self.nav_bar.getURL()
|
text = makeRequest("rdelaage.ovh", "gemini://rdelaage.ovh")
|
||||||
self.content.setContent(text)
|
self.content.setContent(text)
|
||||||
self.current_URL = text
|
self.current_URL = self.nav_bar.getURL()
|
||||||
|
|
||||||
class NavBar():
|
class NavBar():
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
|
@ -41,4 +43,27 @@ class Content():
|
||||||
def setContent(self, new_content):
|
def setContent(self, new_content):
|
||||||
self.line["text"] = new_content
|
self.line["text"] = new_content
|
||||||
|
|
||||||
|
def makeRequest(hostname, url):
|
||||||
|
try:
|
||||||
|
s = socket.create_connection((hostname, 1965))
|
||||||
|
context = ssl.SSLContext()
|
||||||
|
context.check_hostname = False
|
||||||
|
context.verify_mode = ssl.CERT_NONE
|
||||||
|
s = context.wrap_socket(s, server_hostname = hostname)
|
||||||
|
s.sendall((url + '\r\n').encode("UTF-8"))
|
||||||
|
fp = s.makefile("rb")
|
||||||
|
header = fp.readline().decode("UTF-8").strip()
|
||||||
|
status, mime = header.split()
|
||||||
|
|
||||||
|
print("STATUS : " + status)
|
||||||
|
print("MIME : " + mime)
|
||||||
|
|
||||||
|
body = fp.read().decode("UTF-8")
|
||||||
|
|
||||||
|
return body
|
||||||
|
|
||||||
|
except Exception as err:
|
||||||
|
print(err)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
app = Application()
|
app = Application()
|
||||||
|
|
Reference in New Issue