Skip to content

Instantly share code, notes, and snippets.

@83tb
Created May 7, 2012 20:37
Show Gist options
  • Save 83tb/2630237 to your computer and use it in GitHub Desktop.
Save 83tb/2630237 to your computer and use it in GitHub Desktop.
Simple code generator function in Python. Optionally you can add custom string at the beginning.
import uuid # from http://zesty.ca/python/uuid.html
import sys
import base64
def fetch_code(custom_string="CODE_'):
"""
takes an optional argument, a string to be put at the beginning of a code,
so the code will look like that:
CODE_8mANDJ
KEY_9coOeC
default is CODE_
usage:
fetch_code()
fetch_code(custom_string="KEY_")
"""
b64uid = '00000000'
uid = uuid.uuid4()
b64uid = base64.b64encode(uid.bytes,'-_')
code = b64uid[0:6]
return custom_string+code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment