aboutsummaryrefslogtreecommitdiff
path: root/test/gg.py
blob: bd2de8b0c80891dbcad7a3f6eb89c3e11415da26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3

# GeminiGet, aka gg
# USAGE: ./gg path [port]

import os
import socket
import ssl
import urllib.parse
import sys

hostname = 'localhost'
path = sys.argv[1]

port = 1965
if len(sys.argv) > 2:
    port = int(sys.argv[2])

s = socket.create_connection((hostname, port))
context = ssl.SSLContext()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
s = context.wrap_socket(s, server_hostname = hostname)
s.sendall(("gemini://" + hostname + ":" + str(port) + path + "\r\n").encode('UTF-8'))

fp = s.makefile("rb")
for line in fp.read().splitlines():
    print(line.decode('UTF-8'))