Create QR Code
This commit is contained in:
parent
3e7f1f4b14
commit
1ae44a1f46
77
sbeam.py
77
sbeam.py
|
@ -12,18 +12,68 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
import pyqrcode
|
||||||
|
|
||||||
|
import socket
|
||||||
|
import struct
|
||||||
|
import base64
|
||||||
|
|
||||||
|
# from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||||
|
import http.server
|
||||||
|
import socketserver
|
||||||
|
|
||||||
|
|
||||||
|
def get_primary_ip():
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
try:
|
||||||
|
# doesn't even have to be reachable
|
||||||
|
s.connect(('10.255.255.255', 1))
|
||||||
|
IP = s.getsockname()[0]
|
||||||
|
except Exception as exc:
|
||||||
|
print(exc)
|
||||||
|
IP = '127.0.0.1'
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
return IP
|
||||||
|
|
||||||
|
|
||||||
|
def show_qrcode():
|
||||||
|
primary_ip = get_primary_ip()
|
||||||
|
octets = [1]
|
||||||
|
octets.extend([int(_) for _ in primary_ip.split('.')[::-1]])
|
||||||
|
url = 'http://superbe.am/q?' + base64.b64encode(
|
||||||
|
struct.pack('BBBBB', *octets)
|
||||||
|
).decode('utf-8')
|
||||||
|
qrcode = pyqrcode.create(url)
|
||||||
|
print('\033[1;37;37m████████' + '██'*(len(qrcode.code[0])))
|
||||||
|
for row in qrcode.code:
|
||||||
|
print('\033[1;37;37m████', end='')
|
||||||
|
for block in row:
|
||||||
|
if block == 1:
|
||||||
|
print('\033[1;30;30m ', end='')
|
||||||
|
else:
|
||||||
|
print('\033[1;37;37m██', end='')
|
||||||
|
print('\033[1;37;37m████')
|
||||||
|
print('\033[1;37;37m████████' + '██'*(len(qrcode.code[0])))
|
||||||
|
|
||||||
|
|
||||||
|
def serve_files():
|
||||||
|
show_qrcode()
|
||||||
|
Handler = http.server.SimpleHTTPRequestHandler
|
||||||
|
with socketserver.TCPServer(('', 8081), Handler) as httpd:
|
||||||
|
httpd.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
def get_superlist():
|
def get_superlist():
|
||||||
with requests.get('http://192.168.178.50:8080/superlist',
|
with requests.get('http://192.168.178.50:8080/superlist',
|
||||||
headers={'User-Agent': 'sbeam'}) as response:
|
headers={'User-Agent': 'sbeam'}) as response:
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
return response.text.split('\n')
|
return response.text.split('\n')
|
||||||
|
|
||||||
|
|
||||||
def save_stream(filename):
|
def save_stream(filename):
|
||||||
with requests.get('http://192.168.178.50:8080/getstream', stream=True,
|
with requests.get('http://192.168.178.50:8080/getstream', stream=True,
|
||||||
headers={'User-Agent': 'sbeam'}) as response:
|
headers={'User-Agent': 'sbeam'}) as response:
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
with open(filename, 'wb') as handle:
|
with open(filename, 'wb') as handle:
|
||||||
# length = response.headers.get('Content-length')
|
# length = response.headers.get('Content-length')
|
||||||
|
@ -46,14 +96,15 @@ def split_stream(data, directory, superlist):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
to_download = 0
|
serve_files()
|
||||||
superlist = get_superlist()
|
# to_download = 0
|
||||||
try:
|
# superlist = get_superlist()
|
||||||
for item in superlist:
|
# try:
|
||||||
to_download += int(item.split('||')[1])
|
# for item in superlist:
|
||||||
except IndexError:
|
# to_download += int(item.split('||')[1])
|
||||||
print(f'Download stream contains {len(superlist) - 1} items.')
|
# except IndexError:
|
||||||
finally:
|
# print(f'Download stream contains {len(superlist) - 1} items.')
|
||||||
print(f'Target download size is {to_download} bytes.')
|
# finally:
|
||||||
save_stream('data.gz')
|
# print(f'Target download size is {to_download} bytes.')
|
||||||
split_stream('data.gz', 'received', superlist)
|
# save_stream('data.gz')
|
||||||
|
# split_stream('data.gz', 'received', superlist)
|
||||||
|
|
Loading…
Reference in New Issue