You've already forked flask-mongo-api-boilerplate
mirror of
https://github.com/LukePeters/flask-mongo-api-boilerplate.git
synced 2026-05-06 02:11:18 +09:00
First push to GitHub
This commit is contained in:
43
api/main/tools/__init__.py
Normal file
43
api/main/tools/__init__.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import random
|
||||
import time
|
||||
|
||||
def nowEpoch():
|
||||
return int(time.time()) * 1000
|
||||
|
||||
def JsonResp(data, status):
|
||||
from flask import Response
|
||||
import json
|
||||
return Response(json.dumps(data), mimetype="application/json", status=status)
|
||||
|
||||
def randID():
|
||||
randId = randString(3) + randString(3) + randString(3) + randString(3) + randString(3) + randString(3)
|
||||
return randId
|
||||
|
||||
def randString(length):
|
||||
randString = ""
|
||||
for _ in range(length):
|
||||
randString += random.choice("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890")
|
||||
|
||||
return randString
|
||||
|
||||
def randStringCaps(length):
|
||||
randString = ""
|
||||
for _ in range(length):
|
||||
randString += random.choice("ABCDEFGHJKLMNPQRSTUVWXYZ23456789")
|
||||
|
||||
return randString
|
||||
|
||||
def randStringNumbersOnly(length):
|
||||
randString = ""
|
||||
for _ in range(length):
|
||||
randString += random.choice("23456789")
|
||||
|
||||
return randString
|
||||
|
||||
def validEmail(email):
|
||||
import re
|
||||
|
||||
if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) != None:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
Reference in New Issue
Block a user