ref: 20e217c955b231d402ddd0a32a14d38b34f728b9
converter/local/uploader.py
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 |
import requests import msgpack import re import os import hashlib import config def upload(): with open('metadata.yml', 'r') as file: metadata = file.read() timetablesIds = [filename.split('.')[0] for filename in os.listdir('.') if re.match('^.*\\.db\\.gz$', filename)] timetables = {} for tId in timetablesIds: with open('{}.db.gz'.format(tId), 'rb') as f: timetables[tId] = {'t': '', 'sha': ''} t = f.read() timetables[tId]['t'] = config.storage.format(tId) timetables[tId]['sha'] = hashlib.sha256(t).hexdigest() signature = config.key.sign(bytes(metadata, 'utf-8')) data = msgpack.packb({'metadata': metadata, 'timetables': timetables, 'signature': signature.signature}, use_bin_type=True) session = requests.Session() response = session.post(config.receiver, data) print(response) print(response.text) |