Blame


1 5c2e310e 2021-01-22 op #!/usr/bin/env python3
2 5c2e310e 2021-01-22 op
3 5c2e310e 2021-01-22 op # GeminiGet, aka gg
4 5c2e310e 2021-01-22 op # USAGE: ./gg path [port]
5 5c2e310e 2021-01-22 op
6 5c2e310e 2021-01-22 op import os
7 5c2e310e 2021-01-22 op import socket
8 5c2e310e 2021-01-22 op import ssl
9 5c2e310e 2021-01-22 op import urllib.parse
10 5c2e310e 2021-01-22 op import sys
11 5c2e310e 2021-01-22 op
12 5c2e310e 2021-01-22 op hostname = 'localhost'
13 5c2e310e 2021-01-22 op path = sys.argv[1]
14 5c2e310e 2021-01-22 op
15 5c2e310e 2021-01-22 op port = 1965
16 5c2e310e 2021-01-22 op if len(sys.argv) > 2:
17 5c2e310e 2021-01-22 op port = int(sys.argv[2])
18 5c2e310e 2021-01-22 op
19 5c2e310e 2021-01-22 op s = socket.create_connection((hostname, port))
20 5c2e310e 2021-01-22 op context = ssl.SSLContext()
21 5c2e310e 2021-01-22 op context.check_hostname = False
22 5c2e310e 2021-01-22 op context.verify_mode = ssl.CERT_NONE
23 5c2e310e 2021-01-22 op s = context.wrap_socket(s, server_hostname = hostname)
24 5c2e310e 2021-01-22 op s.sendall(("gemini://" + hostname + ":" + str(port) + path + "\r\n").encode('UTF-8'))
25 5c2e310e 2021-01-22 op
26 5c2e310e 2021-01-22 op try:
27 5c2e310e 2021-01-22 op fp = s.makefile("rb")
28 5c2e310e 2021-01-22 op for line in fp.read().splitlines():
29 5c2e310e 2021-01-22 op print(line.decode('UTF-8'))
30 5c2e310e 2021-01-22 op except:
31 5c2e310e 2021-01-22 op pass