Exemplo n.º 1
0
def api_pics_get(mashId):
  status = 200
  resObj = {
    "path": "/api/mash/%s" %mashId,
    "method": "GET",
    "msg": "",
  }

  myDbTool = db_tool()
  sqlRes = myDbTool.execute_select("SELECT * FROM mashes WHERE id = %s;" %int(mashId) )
  if len(sqlRes) == 0:
    status = 404
    resObj["msg"] = "mash not found" 
    resObj["status"] = status
    return jsonify(resObj), status
  
  resObj["mash"] = sqlRes[0]

  myPics = pics()
  picAry = myPics.call_mash_pics(mashId)

  srtPicAry = sorted(picAry, key=lambda k: k['ratioNmb'], reverse=True) #UIUIUIUIUIUIUIUIUI
  resObj["data"] = srtPicAry
  
  if "admin" in session:
     resObj["admin"] = True
  else:
    resObj["admin"] = False
  
  resObj["status"] = status
  return jsonify(resObj), status
Exemplo n.º 2
0
def api_mashes_delete(mashId):
  status = 200
  resObj = {
    "path": "/api/mash/%s" %mashId,
    "method": "DELETE",
    "msg": "",
  }

  myDbTool = db_tool()
  myPics = pics()
  #sqlRes = myDbTool.execute_delete("DELETE FROM pics WHERE mash = %s ;" %int(mashId) )
  sqlRes = myDbTool.execute_select("SELECT id FROM pics WHERE mash = %s ;" %int(mashId) )
  for row in sqlRes:
    picId = row["id"]
    myPics.remove_pic(picId)

  sqlRes = myDbTool.execute_delete("DELETE FROM mashes WHERE id = %s ;" %int(mashId) )
  if sqlRes == 0:
    status = 404
    resObj["msg"] = "mash not found" 
    resObj["status"] = status
    return jsonify(resObj), status

  resObj["status"] = status
  return jsonify(resObj), status
Exemplo n.º 3
0
def api_auth_do():
  status = 200
  resObj = {
    "path": "/api/auth",
    "method": "POST",
    "msg": ""
  }

  objIn = request.get_json()
  if "pwd" not in objIn:
    status = 500
    resObj["msg"] = "pwd input required" 
    resObj["status"] = status
    return jsonify(resObj), status

  pwdIn = objIn["pwd"]

  myDbTool = db_tool()
  res = myDbTool.check_admin_auth(pwdIn)

  if res:
    session["admin"] = True
  else:
    status = 401
    resObj["status"] = status
    resObj["msg"] = "Wrong password" 
  
  # if "pwd" in session:
  #   resObj["admin"] = True
  # else:
  #   resObj["admin"] = False

  return jsonify(resObj), status
Exemplo n.º 4
0
def api_mashes_get():
  status = 200
  resObj = {
    "path": "/api/mashes",
    "method": "DELETE",
    "msg": "Hello from the API",
  }

  myDbTool = db_tool()
  mashObj = []
  sqlRes = myDbTool.execute_select("SELECT * FROM mashes ORDER BY name;")
  for row in sqlRes:
    mashObj.append(row)

  resObj["data"] = mashObj
  resObj["status"] = status

  return jsonify(resObj), 200
Exemplo n.º 5
0
def api_mashes_reset(mashId):
  status = 200
  resObj = {
    "path": "/api/mash/%s" %mashId,
    "method": "PATCH",
    "msg": "",
  }

  print(mashId)
  myDbTool = db_tool()
  sqlRes = myDbTool.execute_update("UPDATE pics SET won = 0, loss = 0, wonrate = 0, lossrate = 0 WHERE mash = %s ;" %int(mashId) )
 
  if sqlRes == 0:
    status = 404
    resObj["msg"] = "mash not found or no images available" 
    resObj["status"] = status
    return jsonify(resObj), status

  resObj["status"] = status
  return jsonify(resObj), status
Exemplo n.º 6
0
def api_mashes_add():
  status = 200
  resObj = {
    "path": "/api/mash",
    "method": "POST",
    "msg": "",
  }

  objIn = request.get_json()
  
  myDbTool = db_tool()
  sqlRes = myDbTool.execute_insert("mashes", objIn)
  if sqlRes == 0:
    status = 500
    resObj["msg"] = "something went wrong" 
    resObj["status"] = status
    return jsonify(resObj), status

  resObj["status"] = status
  return jsonify(resObj), status
Exemplo n.º 7
0
def api_mashes_change():
  status = 200
  resObj = {
    "path": "/api/mash",
    "method": "PUT",
    "msg": "",
  }

  objIn = request.get_json()
  if "id" not in objIn:
    status = 404
    resObj["msg"] = "id is missing" 
    resObj["status"] = status
    return jsonify(resObj), status
  else:
    curId = objIn["id"]
    del objIn["id"]
  
  keyAry = []
  valAry = []
  updateAry = []
  for key, val in objIn.items():
    keyAry.append(key)
    valAry.append(val)
    updateAry.append(" %s = '%s' " %(key, val) )

  updateStr = ", ".join(updateAry) 

  myDbTool = db_tool()
  sqlRes = myDbTool.execute_update("UPDATE mashes SET %s WHERE id = %s ;" %(updateStr, curId))
  if sqlRes == 0:
    status = 500
    resObj["msg"] = "something went wrong" 
    resObj["status"] = status
    return jsonify(resObj), status

  resObj["status"] = status
  return jsonify(resObj), status
Exemplo n.º 8
0
def api_reset_pwd():
  status = 200
  resObj = {
    "path": "/api/app/pwd",
    "method": "POST",
    "msg": ""
  }

  objIn = request.get_json()
  neededVals = ["curPwd", "newPwd"]
  for val in neededVals:
    if val not in objIn:
      status = 500
      resObj["msg"] = val+" para is missing" 
      resObj["status"] = status
      return jsonify(resObj), status

  curPwd = objIn["curPwd"]
  newPwd = objIn["newPwd"]

  myDbTool = db_tool()
  res = myDbTool.check_admin_auth(curPwd)
  if not res:
    status = 401
    resObj["msg"] = "Wrong admin pwd" 
    resObj["status"] = status
    return jsonify(resObj), status

  try:
    myDbTool.set_admin_pwd(newPwd)
  except:
    status = 500
    resObj["msg"] = "Something went wrong" 
    resObj["status"] = status
    return jsonify(resObj), status


  return jsonify(resObj), status