2016-08-27 16:29:56 +08:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2016-08-28 16:50:37 +08:00
|
|
|
import draw, ECC, data, structure
|
2016-08-27 16:29:56 +08:00
|
|
|
|
|
|
|
# ecl: Error Correction Level(L,M,Q,H)
|
|
|
|
def get_qrcode(ecl, str):
|
|
|
|
try:
|
2016-08-28 16:50:37 +08:00
|
|
|
# Data Coding
|
|
|
|
ver, data_codewords = data.encode(ecl, str)
|
|
|
|
|
|
|
|
# Error Correction Coding
|
|
|
|
ecc = ECC.encode(ver, ecl, data_codewords)
|
|
|
|
|
|
|
|
# Structure final bits
|
|
|
|
final_bits = structure.structure_final_bits(ver, ecl, data_codewords, ecc)
|
|
|
|
|
|
|
|
# Get the QR Matrix
|
|
|
|
|
|
|
|
|
2016-08-27 16:29:56 +08:00
|
|
|
except UnicodeEncodeError:
|
|
|
|
print('Error input!!')
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# test:
|
2016-08-28 16:50:37 +08:00
|
|
|
str = 'HELLO WORLD'
|
2016-08-27 16:29:56 +08:00
|
|
|
str2 = '💩'
|
2016-08-28 16:50:37 +08:00
|
|
|
get_qrcode('M',str)
|