-
Notifications
You must be signed in to change notification settings - Fork 1
/
base.py
54 lines (41 loc) · 1.34 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import string
import random
import datetime
from sqlalchemy import *
from alchemy import *
from config import *
def create_id():
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
def getCode(id):
return CodesTable.query.get(id)
def saveCode(code, lang, clientIp):
id = create_id()
while getCode(id):
id = create_id()
code = CodesTable(id=id, code=code, lang=lang, ip=clientIp, date=str(datetime.date.today()).replace('-', '.'), views=0)
db.session.add(code)
db.session.commit()
return id
def getAllCode(lang=None):
if not lang:
return CodesTable.query.all()
return CodesTable.query.filter_by(lang=lang).all()
def addView(id):
query = CodesTable.query.get(id)
query.views += 1
db.session.commit()
def saveSimilarity(id, id2, percent):
pkid = create_id()
while getSavedSimilarities(pkid):
pkid = create_id(pkid)
similarity = SimilaritiesTable(id=id, id2=id2, pkid=pkid, percent=percent)
db.session.add(similarity)
db.session.commit()
def getSavedSimilarities(id):
n = SimilaritiesTable.query.where(SimilaritiesTable.id == id)
if n == None:
return None
else:
return n.all()
def getAllSimilarities():
return SimilaritiesTable.query.all()