Skip to content

Instantly share code, notes, and snippets.

@Gricha
Forked from 83tb/code_generator.py
Created August 25, 2014 09:49
Show Gist options
  • Save Gricha/9baed08833237d8a67b0 to your computer and use it in GitHub Desktop.
Save Gricha/9baed08833237d8a67b0 to your computer and use it in GitHub Desktop.
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