import string, random
import re

def string_gen(size, chars = string.ascii_letters + string.digits + string.digits): # add digits twice to increase occurrence of numbers in string
    return ''.join(random.choice(chars) for _ in range(size))

def get_form_token(source):
    try:
        match = re.search('id="edit-page-node-form-form-token" value="(.{32})"', source)
        form_token = match.group(1)
        if form_token:
            return form_token
        else:
            raise Exception()
    except:
        print("Form token could not be found, exiting")
        exit()