Skip to content

Instantly share code, notes, and snippets.

@maraca
Created October 22, 2011 12:07
Show Gist options
  • Save maraca/1305918 to your computer and use it in GitHub Desktop.
Save maraca/1305918 to your computer and use it in GitHub Desktop.
Unique QR codes w/ hash of current timestamp
#!/usr/bin/python2.7
__author__ = "[email protected]"
import hashlib
import os
import qrcode
import time
def gen_qr(folder, create):
encoder = qrcode.Encoder()
data = str(gen_name())
path = "/home/qrcodes"
image = encoder.encode(
data,
version=15,
mode=encoder.mode.BINARY,
eclevel=encoder.eclevel.H)
# /home/qrcodes/subfolder/xxxx.png
if create:
os.mkdir("%s/%s" % (path, str(folder)))
image.save("%s/%s/%s.png" % (path, str(folder), data))
def gen_name():
now = time.time()
uniq = hashlib.md5()
uniq.update(str(now))
return uniq.hexdigest()
def main():
now = time.time()
counter = 0
directory = 0
create = True
while True:
gen_qr(directory, create)
create = False
if counter % 10000 == 0 and counter > 2:
print "Generated %d QR codes in %d seconds" % (
counter, time.time() - now)
# max inodes = 32K on ext4 so creating a sub-folder every 30K
if counter % 30000 == 0 and counter > 2:
directory += 1
create = True
counter += 1
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment