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 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():
|
||||
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
|
||||
return response.text.split('\n')
|
||||
|
||||
|
||||
def save_stream(filename):
|
||||
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
|
||||
with open(filename, 'wb') as handle:
|
||||
# length = response.headers.get('Content-length')
|
||||
|
@ -46,14 +96,15 @@ def split_stream(data, directory, superlist):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
to_download = 0
|
||||
superlist = get_superlist()
|
||||
try:
|
||||
for item in superlist:
|
||||
to_download += int(item.split('||')[1])
|
||||
except IndexError:
|
||||
print(f'Download stream contains {len(superlist) - 1} items.')
|
||||
finally:
|
||||
print(f'Target download size is {to_download} bytes.')
|
||||
save_stream('data.gz')
|
||||
split_stream('data.gz', 'received', superlist)
|
||||
serve_files()
|
||||
# to_download = 0
|
||||
# superlist = get_superlist()
|
||||
# try:
|
||||
# for item in superlist:
|
||||
# to_download += int(item.split('||')[1])
|
||||
# except IndexError:
|
||||
# print(f'Download stream contains {len(superlist) - 1} items.')
|
||||
# finally:
|
||||
# print(f'Target download size is {to_download} bytes.')
|
||||
# save_stream('data.gz')
|
||||
# split_stream('data.gz', 'received', superlist)
|
||||
|
|
Loading…
Reference in New Issue