Skip to content

Commit 8c6c47c

Browse files
committed
add apiTokens
1 parent 82484f8 commit 8c6c47c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

api.py

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def get(self):
6262
-- using NEST Schema
6363
SELECT
6464
count(main.MAG_AUTO_I) COUNT,
65-
avg(main.MAG_AUTO_I) AVERAGE,
6665
main.HPIX_1024
6766
FROM DR1_MAIN main
6867
WHERE

pubapi.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import ea_tasks
1313
import pandas as pd
1414
import numpy as np
15+
import backup
16+
1517

1618
def create_token_table(delete=False):
1719
with open('config/mysqlconfig.yaml', 'r') as cfile:
@@ -26,26 +28,27 @@ def create_token_table(delete=False):
2628
con.select_db('des')
2729
cur = con.cursor()
2830
if delete:
29-
cur.execute("DROP TABLE IF EXISTS Tokens")
31+
cur.execute("DROP TABLE IF EXISTS apiTokens")
3032
cur.execute("""
31-
CREATE TABLE IF NOT EXISTS Tokens(
33+
CREATE TABLE IF NOT EXISTS apiTokens(
3234
token varchar(50),
3335
time datetime,
36+
user varchar(100),
3437
)""")
3538
con.commit()
3639
con.close()
3740

3841

39-
def create_token():
42+
def create_token(user='test'):
4043
token = hashlib.sha1(os.urandom(64)).hexdigest()
4144
now = datetime.datetime.now()
4245
with open('config/mysqlconfig.yaml', 'r') as cfile:
4346
conf = yaml.load(cfile)['mysql']
4447
con = mydb.connect(**conf)
45-
tup = tuple([token, now.strftime('%Y-%m-%d %H:%M:%S')])
48+
tup = tuple([token, now.strftime('%Y-%m-%d %H:%M:%S'), user])
4649
with con:
4750
cur = con.cursor()
48-
cur.execute("INSERT INTO Tokens VALUES {0}".format(tup))
51+
cur.execute("INSERT INTO apiTokens VALUES {0}".format(tup))
4952
con.close()
5053

5154

@@ -96,7 +99,7 @@ def post(self):
9699
con = mydb.connect(**conf)
97100
try:
98101
cur = con.cursor()
99-
cur.execute("SELECT * from Tokens where token = '{0}'".format(token))
102+
cur.execute("SELECT * from apiTokens where token = '{0}'".format(token))
100103
cc = cur.fetchone()
101104
now = datetime.datetime.now()
102105
dt = (now-cc[1]).total_seconds()
@@ -194,7 +197,7 @@ def post(self):
194197
con = mydb.connect(**conf)
195198
try:
196199
cur = con.cursor()
197-
cur.execute("SELECT * from Tokens where token = '{0}'".format(token))
200+
cur.execute("SELECT * from apiTokens where token = '{0}'".format(token))
198201
cc = cur.fetchone()
199202
now = datetime.datetime.now()
200203
dt = (now-cc[1]).total_seconds()
@@ -264,7 +267,7 @@ def post(self):
264267
con = mydb.connect(**conf)
265268
try:
266269
cur = con.cursor()
267-
cur.execute("SELECT * from Tokens where token = '{0}'".format(token))
270+
cur.execute("SELECT * from apiTokens where token = '{0}'".format(token))
268271
cc = cur.fetchone()
269272
now = datetime.datetime.now()
270273
dt = (now-cc[1]).total_seconds()

0 commit comments

Comments
 (0)