This will be a small blurb compared to the rest but this is rather essential. This isn’t the best way to generate tokens and in no way do I recommend you use this in a practical case. Here is the code, however (place it just below the app = … line):
def generate_token(number): from time import time charlist = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+/=" num = str(number+time()).split(".") info = [num[i:i+2] for i in range(0, len(num), 2)] token = "" for i in info: index = int(i)+int(i) token = "%s%s" % (token, str(charlist[index])) return token
Basically what this does is add the current time to the number provided (and since time() returns a decimal we only want the whole number). Then we split the number into multiple pairs and add both digits in the pairs, and that is our place in the token list/charlist. It’s pretty simplistic but it does our job just fine.