-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathreader.py
More file actions
36 lines (32 loc) · 866 Bytes
/
reader.py
File metadata and controls
36 lines (32 loc) · 866 Bytes
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
import zbarlight
import os
import sys
import PIL
print 'Taking picture..'
try:
f = 1
qr_count = len(os.listdir('qr_codes'))
os.system('sudo fswebcam -d /dev/video'+sys.argv[1]+' -q qr_codes/qr_'+str(qr_count)+'.jpg')
print 'Picture taken..'
except:
f = 0
print 'Picture couldn\'t be taken..'
print
if(f):
print 'Scanning image..'
f = open('qr_codes/qr_'+str(qr_count)+'.jpg','rb')
qr = PIL.Image.open(f);
qr.load()
codes = zbarlight.scan_codes('qrcode',qr)
if(codes==None):
os.remove('qr_codes/qr_'+str(qr_count)+'.jpg')
print 'No QR code found'
else:
print 'QR code(s):'
print codes
f = open('qr_code_messages.txt','a')
for i in range(len(codes)):
f.write(codes[i])
if(i!=len(codes)-1):
f.write('^')
f.write('~')