forked from SergiySW/NanoWalletBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_qr.py
57 lines (51 loc) · 1.52 KB
/
common_qr.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# RaiBlocks Telegram bot
# @RaiWalletBot https://t.me/RaiWalletBot
#
# Source code:
# https://github.com/SergiySW/RaiWalletBot
#
# Released under the BSD 3-Clause License
#
# QR code handler
import ConfigParser
config = ConfigParser.ConfigParser()
config.read('bot.cfg')
qr_folder_path = config.get('main', 'qr_folder_path')
import pyqrcode
import os.path
#@run_async
def qr_by_account(account):
account = 'xrb:{0}'.format(account)
path = '{1}{0}.png'.format(account, qr_folder_path)
if (not os.path.isfile(path)):
qr = pyqrcode.create(account, error='L', version=4, mode=None, encoding='iso-8859-1')
qr.png('{1}{0}.png'.format(account, qr_folder_path), scale=8)
import qrtools
from PIL import Image, ImageEnhance
def account_by_qr(qr_file):
qr = qrtools.QR()
qr.decode(qr_file)
# Try to increase contrast if not recognized
if ('xrb_' not in qr.data):
image = Image.open(qr_file)
contrast = ImageEnhance.Contrast(image)
image = contrast.enhance(7)
image.save('{0}'.format(qr_file.replace('.jpg', '_.jpg')), 'JPEG')
qr2 = qrtools.QR()
qr2.decode('{0}'.format(qr_file.replace('.jpg', '_.jpg')))
#print(qr2.data)
qr = qr2
returning = qr.data.replace('xrb:', '').replace('raiblocks://', '').replace('raiblocks:', '').split('?')
# parsing amount
if (len(returning) > 1):
if ('amount=' in returning[1]):
returning[1] = returning[1].replace('amount=', '')
# don't use empty
if (len(returning[1]) == 0):
returning.pop()
else:
returning.pop()
return returning