Electronic stock management. -- not updated anymore
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
 

71 lines
1.7 KiB

import re
from unidecode import unidecode
from models import Apitoken
import random
import string
import os
_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
def slugify(text, delim=u'_'):
"""
Generate a slug in ASCII-only form
:param text: Text to slugify
:param delim: Delimiter to join
:return: str slug
"""
result = []
for word in _punct_re.split(text.lower()):
result.extend(unidecode(word).split())
return delim.join(result)
def gen_random_str(size=10):
"""
Generate random string
:param size: Size of string
:return: Random string
"""
return ''.join(random.choice(string.ascii_uppercase +
string.ascii_lowercase +
string.digits) for _ in range(size))
def path_or_none(fbase, ftype, fname):
"""
Return path or none
:param fbase: Base directory
:param ftype: Type directory
:param fname: Filename
:return: Full path or None
"""
if not fbase or not ftype or not fname:
return None
fpath = os.path.join(fbase, ftype, fname)
return fpath if os.path.isfile(fpath) else None
def generate_uniques_apitoken():
"""
Generate an unique API Token
:return: Dict of token and secret pair
"""
while 1:
tmp_token = gen_random_str(20)
tmp_secret = gen_random_str(20)
blip = Apitoken.query.filter_by(token=tmp_token,
secret=tmp_secret).first()
if blip:
continue
else:
return {"token": tmp_token, "secret": tmp_secret}
return None
def f7(seq):
seen = set()
seen_add = seen.add
return [x for x in seq if not (x in seen or seen_add(x))]