-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomp.py
More file actions
48 lines (41 loc) · 971 Bytes
/
Copy pathcomp.py
File metadata and controls
48 lines (41 loc) · 971 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import base64
import sys
import brotli
def compress(data):
return brotli.compress(data, quality=0, mode=brotli.MODE_TEXT)
# get data from arg
file = sys.argv[1]
if len(sys.argv) > 2:
url = "http://[::]:8000/#"
else:
url = "https://qrforth.com/#"
# load data from file
with open(file, "r") as f:
html = f.read()
# convert to bytes
data = html.encode('utf-8')
# print
# print("UTF-8 Encoded => ")
# print(data)
# compress
data = compress(data)
# print
# print("Compressed => ")
# print(data)
# encode to base64
data = base64.b64encode(data)
# print
# print("Base64 Encoded => ")
# print(data)
# convert to string
data = data.decode('utf-8')
# print
# print("String => ")
# print(data)
# count number of bytes in string
# print("Number of bytes in Input: " + str(len(html)))
print("Output bytes: " + str(len(data)))
# print("URL => " + "http://[::]:8000/#" + data)
# save final url to file
with open("url.txt", "w") as f:
f.write(url + data)