def atHour(otype=Parameter("type"), hour=Parameter("hour")):
    cur = conn.cursor()
    sql = "SELECT * FROM Stats WHERE TYPE = '" + str(
        otype) + "' AND TIME LIKE '" + hour + "%';"
    cur.execute(sql)
    rows = cur.fetchall()
    return str(len(rows))
 def __build_str(self, key, val=None):
     if key in self.request.parameter.keys():
         return Parameter(name=key, default=self.request.parameter[key], required=False)
     elif val is None:
         return None
     else:
         return Parameter(name=key, default=val, required=False)
 def __build_param(self, key, val=Parameter()):
     name = val.name if val.name is not None and val.name != "" else key
     if val._required and name not in self.request.parameter:
         raise HttpError(400, "Missing Parameter", f"Parameter[{name}] is required.")
     if name in self.request.parameter:
         v = self.request.parameter[name]
         return Parameter(name=name, default=v, required=val._required)
     else:
         return val
Exemple #4
0
 def __build_param(self, key, val=Parameter()):
     name = val.name if val.name is not None and val.name != "" else key
     if not isinstance(name, unicode):
         """
         " Python 2.7, change str => unicode, or it will fail to reconize the key that is unicode;
         """
         name = name.decode("utf-8")
     if val._required and name not in self.request.parameter:
         raise HttpError(400, "Parameter[%s] is required." % name)
     if name in self.request.parameter:
         v = self.request.parameter[name]
         return Parameter(name=name, default=v, required=val._required)
     else:
         return val
    def __build_list(self, key, target_type=list, val=[]):
        if key in self.request.parameters.keys():
            ori_list = self.request.parameters[key]
        else:
            ori_list = val

        if target_type == List[int]:
            try:
                return [int(p) for p in ori_list]
            except:
                raise HttpError(400, None, f"One of the parameter[{key}] is not int. ")
        elif target_type == List[float]:
            try:
                return [float(p) for p in ori_list]
            except:
                raise HttpError(400, None, f"One of the parameter[{key}] is not float. ")
        elif target_type == List[bool]:
            return [p.lower() not in ("0", "false", "") for p in ori_list]
        elif target_type in (List[dict], List[Dict]):
            try:
                return [json.loads(p) for p in ori_list]
            except:
                raise HttpError(400, None, f"One of the parameter[{key}] is not JSON string. ")
        elif target_type == List[Parameter]:
            return [Parameter(name=key, default=p, required=False) for p in ori_list]
        else:
            return ori_list
def carAvg(type=Parameter("type")):
    cur = conn.cursor()
    sql = "SELECT * FROM Stats WHERE TYPE = '" + str(type) + "';"
    cur.execute(sql)
    rows = cur.fetchall()
    count = len(rows)
    time = int(math.ceil(float(calcTime())))
    return str(int(math.ceil(count / time)))
Exemple #7
0
def my_upload(img=MultipartFile("img"), txt=Parameter("中文text", required=False, default="DEFAULT"), req=Request()):
    for k, v in req.parameter.items():
        print("%s (%s)====> %s " % (k, str(type(k)), v))
    print(txt)

    root = os.path.dirname(os.path.abspath(__file__))
    img.save_to_file(root + "/imgs/" + img.filename)
    return f"<!DOCTYPE html><html><body>upload ok! {txt} </body></html>"
Exemple #8
0
 def __prepare_args(self):
     args = _get_args_(self.__controller)
     arg_vals = []
     for arg in args:
         if arg not in self.request.parameter.keys():
             raise HttpError(400, "Parameter[%s] is required]" % arg)
         param = Parameter(name=arg,
                           default=self.request.parameter[arg],
                           required=True)
         arg_vals.append(param)
     return arg_vals
def specified(otype=Parameter("type")):
    cur = conn.cursor()
    sql = "SELECT * FROM Stats WHERE TYPE = '" + str(otype) + "';"
    cur.execute(sql)
    rows = cur.fetchall()
    atHour = [0] * 23

    for i, row in enumerate(rows):
        hour = row[1][0:2]
        atHour[int(hour)] += 1

    return str(atHour)
Exemple #10
0
def my_ctrl4(user_name,
             password=Parameter(name="passwd", required=True),
             remember_me=True,
             locations=[],
             json_param={},
             lcs=Parameters(name="locals", required=True),
             content_type=Header("Content-Type", default="application/json"),
             connection=Header("Connection"),
             ua=Header("User-Agent"),
             headers=Headers()
             ):
    return f"""<!DOCTYPE html>
def count_ctrl(type=Parameter("type")):
    cur = conn.cursor()
    sql = "SELECT count(*) FROM Stats WHERE TYPE = '" + str(type) + "';"
    cur.execute(sql)
    rows = cur.fetchall()
    return str(rows[0][0])
def res_ctrl(path=Parameter("file", default="KEIJACK")):
    return readFile('/res/' + path)
Exemple #13
0
def normal_form_post(txt=Parameter("中文txt", required=False, default="DEFAULT"), req=Request()):
    for k, v in req.parameter.items():
        print("%s ====> %s " % (k, v))
    return f"<!DOCTYPE html><html><body>hi, {txt}</body></html>"
Exemple #14
0
def my_ctrl2(name, name2=Parameter("name", default="KEIJACK")):
    """name and name2 is the same"""
    return f"<!DOCTYPE html><html><body>hello, {name}, {name2}</body></html>"