Exemple #1
0
def uploader():
	if request.method == 'POST':
		lis=[]
		f = request.files['file']
		ls=f.filename
		ls=str(ls).split(".")
		global name
		name=ls[0]
		print name
		ls=ls[1]
		if(ls=="csv"):
			lines = f.readlines()
			x=0
			for row in lines:
				if x==0:
					x=x+1
					continue
				else:
					row=row.rstrip()
					row=str(row).split(",")
					lis.append(row)
					if(x%100==0):
						# sending data to be inserted in batch
						model.insert(name,lis)
						lis=[]
					elif len(lines)-1==x:
						model.insert(name,lis)
					x=x+1
			return "csv file uploaded successfully"
		else:
			return "not csv"
Exemple #2
0
def run_add():
    firstname = input('first name:')
    lastname = input('last name:')
    email = input('email:')

    model.insert(firstname, lastname, email)

    run_list()
Exemple #3
0
 def insert_kid(self):
     if self.validate_input():
         model.insert(self.fullname.text, self.parentname.text, self.kgarten.text, self.month.text)
         print("Child added")
         self.fullname.text, self.parentname.text, self.kgarten.text, self.month.text = "", "", "", ""
     else:
         error_pop = ErrorPopup()
         error_pop.ids.error.text = "Failed to insert kid in database.try again"
         error_pop.title = "Insert Error"
         error_pop.open()
Exemple #4
0
    def post(self):
        """
		posts the reviews 
		"""
        cn = request.form['cn']
        ins = request.form['ins']
        rat = request.form['rat']
        re = request.form['re']
        ty = request.form['ty']
        model.insert(cn, ins, rat, re, ty)
        return "Record Inserted Successfully!!"
Exemple #5
0
def handle_command(c):
    print(c[0])
    print(c)
    if c[0] == b'COMMAND':
        return NULL
    elif c[0] == b'SET':
        key = c[1]
        val = c[2]
        model.insert(key, val, epochs=13)
        return NULL
    elif c[0] == b'GET':
        key = c[1]
        v = model.get(key)
        return b'$%b\r\n%b\r\n' % (str(len(v)).encode("ascii"), v)
    elif c[0] == b'INCR':
        key = c[1]
        v = model.get(key)
        i = int(v.decode("ascii"))
        model.insert(key, str(i + 1).encode("ascii"), epochs=10)
        return NULL
    elif c[0] == b'DECR':
        key = c[1]
        v = model.get(key)
        i = int(v.decode("ascii"))
        model.insert(key, str(i - 1).encode("ascii"), epochs=10)
        return NULL
    elif c[0] == b'INCRBY':
        key = c[1]
        v = model.get(key)
        i = int(v.decode("ascii"))
        model.insert(key, str(i + int(c[2].decode("ascii"))).encode("ascii"), epochs=10)
        return NULL
    else:
        return b'-ERROR: Unsupported command\r\n'
Exemple #6
0
    def bind_key(self, event):
        '''
        key event
        '''
        if model.is_over(self.matrix):
            if askquestion("GAME OVER",
                           "GAME OVER!\nDo you want to init it?") == 'yes':
                self.matrix = my_init()
                self.btn_show_matrix(self.matrix)
                return
            else:
                self.root.destroy()
        else:
            if event.keysym.lower() == "q":
                self.root.destroy()
            elif event.keysym == "Left":
                self.matrix = model.move_left(self.matrix)
            elif event.keysym == "Right":
                self.matrix = model.move_right(self.matrix)
            elif event.keysym == "Up":
                self.matrix = model.move_up(self.matrix)
            elif event.keysym == "Down":
                self.matrix = model.move_down(self.matrix)
            elif event.keysym.lower() == "b":
                if len(matrix_stack) == 1:
                    showinfo('info', 'Cannot back anymore...')
                else:
                    matrix_stack_forward.append(self.matrix)
                    matrix_stack.pop()
                    self.matrix = matrix_stack[-1]
            elif event.keysym.lower() == "f":
                if len(matrix_stack_forward) == 0:
                    showinfo('info', 'Cannot forward anymore...')
                else:
                    self.matrix = matrix_stack_forward[-1]
                    matrix_stack_forward.pop()
                    matrix_stack.append(self.matrix)

            if event.keysym in ["q", "Left", "Right", "Up", "Down"]:
                try:
                    self.matrix = model.insert(self.matrix)
                    matrix_stack.append(self.matrix)
                    del matrix_stack_forward[0:]
                except:
                    pass
            try:
                self.btn_show_matrix(self.matrix)
            except:
                pass

        if model.is_win(self.matrix):
            if askquestion(
                    "WIN",
                    "You win the game!\nDo you want to init it?") == 'yes':
                self.matrix = my_init()
                self.btn_show_matrix(self.matrix)
                return
            else:
                self.root.destroy()
Exemple #7
0
    def insert_student(self):
        if self.validate_input():
            model.insert(self.first_name.text, self.last_name.text, self.student_id.text.upper(),
                         self.phone_number.text,
                         self.parent_address.text, self.validate_check())

            print "Student inserted"

            self.first_name.text, self.last_name.text, self.student_id.text, \
                self.phone_number.text, self.parent_address.text =\
                "", "", "", "", ""

        else:
            error_pop = ErrorPopup()
            error_pop.ids.error.text = "Failed to insert student in database.try again"
            error_pop.title = "Insert Error"
            error_pop.open()
Exemple #8
0
    def POST(self):
        form = web.input()

        image = web.input(product_image={})

        filedir = 'static/img'
        filepath = image.product_image.filename.replace('\\', '/')
        filename = filepath.split('/')[-1]

        fout = open(filedir + '/' + filename, 'w')
        fout.write(image.product_image.file.read())
        fout.close()
        product_image = filename

        model.insert(form['product'], form['description'], form['stock'],
                     form['purchase_cost'], form['sale_cost'], product_image)
        raise web.seeother('/')
Exemple #9
0
    def bind_key(self, event):
        '''
        key event
        '''
        if model.is_over(self.matrix):
            if askquestion("GAME OVER","GAME OVER!\nDo you want to init it?") == 'yes':
                self.matrix = my_init()
                self.btn_show_matrix(self.matrix)
                return
            else:
                self.root.destroy()
        else:
            if event.keysym.lower() == "q":
                self.root.destroy()
            elif event.keysym == "Left":
                self.matrix = model.move_left(self.matrix)
            elif event.keysym == "Right":
                self.matrix = model.move_right(self.matrix)
            elif event.keysym == "Up":
                self.matrix = model.move_up(self.matrix)
            elif event.keysym == "Down":
                self.matrix = model.move_down(self.matrix)
            elif event.keysym.lower() == "b":
                if len(matrix_stack) == 1:
                    showinfo('info', 'Cannot back anymore...')
                else:
                    matrix_stack_forward.append(self.matrix)
                    matrix_stack.pop()
                    self.matrix = matrix_stack[-1]
            elif event.keysym.lower() == "f":
                if len(matrix_stack_forward) == 0:
                    showinfo('info', 'Cannot forward anymore...')
                else:
                    self.matrix = matrix_stack_forward[-1]
                    matrix_stack_forward.pop()
                    matrix_stack.append(self.matrix)
                       
            if event.keysym in ["q", "Left", "Right", "Up", "Down"]:
                try:
                    self.matrix = model.insert(self.matrix)
                    matrix_stack.append(self.matrix)
                    del matrix_stack_forward[0:]
                except:
                    pass
            try:
                self.btn_show_matrix(self.matrix)
            except:
                pass

        if model.is_win(self.matrix):
            if askquestion("WIN","You win the game!\nDo you want to init it?") == 'yes':
                self.matrix = my_init()
                self.btn_show_matrix(self.matrix)
                return
            else:
                self.root.destroy()
def check_drupal_version(url, api, headers, ip):
    turl = urlparse(url)
    if turl.scheme == "":
        url = "http://{}".format(url)
    try:
        req = requests.get(url, timeout=REQUEST_TIMEOUT, headers=headers)
        version = None
        if req.status_code < 400:
            app.logger.info("wappalyzer request to: {}".format(url))
            req = requests.get(api, params={"url": url}, headers=headers)
            app.logger.info("wappalyzer reponded with status code: {}".format(
                req.status_code))
            if req.status_code == 200:
                version = wapp(req.json())
                # return url, version, req.status_code
        model.insert(ip, url, version, req.status_code)
        return url, version, req.status_code
    except Exception as e:
        app.logger.error(e)
        return url, None, "Invalid url."
Exemple #11
0
    def bind_key(self, event):
        '''

        key event

        '''
        global play_flag

        if play_flag:
            if event.keysym.lower() not in ["q", "s"]:
                return

        if model.is_over(self.matrix):
            if askquestion("GAME OVER",
                           "GAME OVER!\nDo you want to init it?") == 'yes':
                self.reset_game()
                return
            else:
                self.root.destroy()
        else:
            if event.keysym.lower() == "q":
                self.root.destroy()
            elif event.keysym.lower() == "s":
                self.reset_game()
                return
            elif event.keysym == "Left":
                self.matrix = model.move_left(self.matrix)
            elif event.keysym == "Right":
                self.matrix = model.move_right(self.matrix)
            elif event.keysym == "Up":
                self.matrix = model.move_up(self.matrix)
            elif event.keysym == "Down":
                self.matrix = model.move_down(self.matrix)
            elif event.keysym.lower() == "b":
                self.backward()
            elif event.keysym.lower() == "f":
                self.forward()

            if event.keysym.lower() in ["q", "left", "right", "up", "down"]:
                try:
                    self.matrix = model.insert(self.matrix)
                    matrix_stack.append(list([self.matrix, model.g_score]))
                    del matrix_stack_forward[0:]
                except:
                    pass
            try:
                self.label_top_list[1]['text'] = model.g_score
                self.btn_show_matrix(self.matrix)
            except:
                pass
        if check_is_win_flag:
            self.is_win()
Exemple #12
0
    def POST(self):
        form = web.input()
        imagen = web.input(imagen={})
        filedir = 'static/img'
        filepath =imagen.imagen.filename.replace('\\','/')
        filename = filepath.split('/')[-1]

        fout = open(filedir + '/' + filename,'w')
        fout.write(imagen.imagen.file.read())
        fout.close()
        imagen=filename 

        model.insert(
            form['producto'],
            form['descripcion'],
            form['existencias'],
            form['p_compra'],
            form['p_venta'],
            imagen
            )
        raise web.seeother('/')
        return render.index()
Exemple #13
0
def insert_into_table(table_num):
    table = tables[table_num]
    table_columns = columnins[table]
    values = []
    try:
        for i in range(len(table_columns)):
            answer = input(table_columns[i] + ' = ')
            values.append(answer)
    except Exception as error:
        print(error)
        return
    print("INSERT INTO " + table + " VALUES(" + ', '.join(values) + ')')
    res = model.insert(table, table_columns, values)
    return res
Exemple #14
0
def hello_world():
    p1 = None
    p2 = None
    try:
        p1 = request.args.get('keyword')
        p3 = literal_eval(p1)
    except:
        return "hello_world"
    try:
        p2 = request.args.get('number')
    except:
        pass
    for x in p3:
        l2 = [x]
        if p2 is not None:
            l1 = search.twit(l2, int(p2))
        else:
            l1 = search.twit(l2, 10)
        ret = model.insert(l1)
    response = app.response_class(response=json.dumps(ret),
                                  status=200,
                                  mimetype='application/json')
    return response
def main(args):
    r"""
  >>> import model, control, rest
  >>> rest.load_props()
  >>> from bs4 import BeautifulSoup as BS
  >>> docs = [{"id":"1","name":"Mike","email":"[email protected]"}]
  >>> model.find = lambda bookmark=None: {"docs":docs}
  >>> res = control.main({"__ow_method":"get"})
  >>> html = BS(res["body"], "lxml")
  >>> print(html.find("tbody"))
  <tbody>
  <tr>
  <td scope="row">
  <input name="id" type="radio" value="1"/>
  </td>
  <td>Mike</td>
  <td>[email protected]</td>
  <td></td>
  </tr>
  </tbody>
  >>> res = control.main({"__ow_method":"get", "op":"new"})
  >>> inp = BS(res["body"], "lxml").find_all("input")
  >>> print(*inp, sep="\n")
  <input class="form-control" id="photo" name="photo" type="file"/>
  <input class="form-control" id="name" name="name" type="text" value=""/>
  <input class="form-control" id="email" name="email" type="email" value=""/>
  >>> res = control.main({"__ow_method":"get", "op":"edit", "id":"1"})
  >>> inp = BS(res["body"], "lxml").find_all("input")
  >>> print(*inp, sep="\n")
  <input name="id" type="hidden" value="1"/>
  <input class="form-control" id="photo" name="photo" type="file"/>
  <input class="form-control" id="name" name="name" type="text" value="Mike"/>
  <input class="form-control" id="email" name="email" type="email" value="[email protected]"/>
  >>> model.insert = control.inspect
  >>> ctype = "multipart/form-data; boundary=------------------------ff26122a2a4ed25b"
  >>> body = "LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS1mZjI2MTIyYTJhNGVkMjViDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7IG5hbWU9Im5hbWUiDQoNCmhlbGxvDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLWZmMjYxMjJhMmE0ZWQyNWINCkNvbnRlbnQtRGlzcG9zaXRpb246IGZvcm0tZGF0YTsgbmFtZT0iZW1haWwiDQoNCmhAbC5vDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLWZmMjYxMjJhMmE0ZWQyNWItLQ0K"
  >>> args = {"__ow_method":"post", "__ow_body":body, "__ow_headers": {"content-type": ctype} }
  >>> _ = control.main(args)
  >>> print(control.spy)
  {'name': 'hello', 'email': '[email protected]'}
  >>> model.update = control.inspect
  >>> ctype = "multipart/form-data; boundary=------------------------7a256bc140953925"
  >>> body = "LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS03YTI1NmJjMTQwOTUzOTI1DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7IG5hbWU9Im5hbWUiDQoNCm1pa2UNCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tN2EyNTZiYzE0MDk1MzkyNQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJlbWFpbCINCg0KbUBzLmMNCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tN2EyNTZiYzE0MDk1MzkyNQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJpZCINCg0KMTIzDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTdhMjU2YmMxNDA5NTM5MjUtLQ0K"
  >>> args = {"__ow_method":"post", "__ow_body":body, "__ow_headers": {"content-type": ctype} }
  >>> x = control.main(args)
  >>> print(control.spy)
  {'id': '123', 'name': 'mike', 'email': '[email protected]'}
    """
    # extract photo
    if "__ow_path" in args:
        path = args["__ow_path"]
        if len(path) > 1:
            doc = model.find(path[1:])["docs"][0]
            return {
                "body": doc["photo"],
                "headers": {
                    "Content-Type": doc["photo_mime"]
                }
            }
    # post data
    if "__ow_body" in args:
        fields, files = form_parse(args)
        filled = fill(fields, files)
        if "id" in fields:
            model.update(filled)
        else:
            model.insert(filled)

    # handle other ops
    op = ""
    if args["__ow_method"] == "get":
        op = args.get("op")
    if op == "new":
        body = view.form(fill({}, {}))
        return {"body": view.wrap(body)}
    if op == "edit" and "id" in args:
        res = model.find(args["id"])
        rec = res["docs"][0]
        body = view.form(rec)
        return {"body": view.wrap(body)}
    if op == "delete" and "id" in args:
        model.delete(args["id"])

    # paginated rendering
    curr = args.get("bookmark")
    query = model.find(bookmark=curr)
    data = query["docs"]
    next = ""
    if len(data) == model.find_limit:
        next = query.get("bookmark")
    body = view.table(data, next, model.last_error)
    if model.last_error:
        model.last_error = None
    return {"body": view.wrap(body)}
Exemple #16
0
    def bind_key(self, event):
        '''
        key event
        '''
        global play_flag

        if play_flag:
            if event.keysym.lower() not in ["q", "s"]:
                return

        if model.is_over(self.matrix):
            if askquestion("GAME OVER",
                           "GAME OVER!\nDo you want to init it?") == 'yes':
                self.reset_game()
                return
            else:
                self.root.destroy()
        else:
            if event.keysym.lower() == "q":
                self.root.destroy()
            elif event.keysym.lower() == "s":
                self.reset_game()
                return
            elif event.keysym == "Left":
                self.matrix = model.move_left(self.matrix)
            elif event.keysym == "Right":
                self.matrix = model.move_right(self.matrix)
            elif event.keysym == "Up":
                self.matrix = model.move_up(self.matrix)
            elif event.keysym == "Down":
                self.matrix = model.move_down(self.matrix)
            elif event.keysym.lower() == "b":
                if len(matrix_stack) == 1:
                    showinfo('info', 'Cannot back anymore...')
                else:
                    matrix_stack_forward.append([self.matrix, model.g_score])
                    matrix_stack.pop()
                    self.matrix = matrix_stack[-1][0]
                    model.g_score = matrix_stack[-1][1]
            elif event.keysym.lower() == "f":
                if len(matrix_stack_forward) == 0:
                    showinfo('info', 'Cannot forward anymore...')
                else:
                    self.matrix = matrix_stack_forward[-1][0]
                    model.g_score = matrix_stack_forward[-1][1]
                    matrix_stack_forward.pop()
                    matrix_stack.append([self.matrix, model.g_score])

            if event.keysym.lower() in ["q", "left", "right", "up", "down"]:
                try:
                    self.matrix = model.insert(self.matrix)
                    matrix_stack.append(list([self.matrix, model.g_score]))
                    del matrix_stack_forward[0:]
                except:
                    pass
            try:
                self.label_top_list[1]['text'] = model.g_score
                # print(model.g_score)
                self.btn_show_matrix(self.matrix)
            except:
                pass

        if model.is_win(self.matrix):
            if askquestion(
                    "WIN",
                    "You win the game!\nDo you want to init it?") == 'yes':
                self.matrix = my_init()
                self.btn_show_matrix(self.matrix)
                return
            else:
                self.root.destroy()
Exemple #17
0
def insert(table):
    data = view.multiple_input(table, 'Enter new fields values:')
    model.insert(table, data)
    display_secondary_menu(table, 'Insertion was made successfully')
def main(args):
    r"""
  >>> import model
  >>> import control
  >>> from bs4 import BeautifulSoup as BS
  >>> docs = [{"id":"1","name":"Mike","email":"[email protected]"}]
  >>> model.find = lambda x=None: {"docs":docs}
  >>> res = control.main({})
  >>> html = BS(res["body"], "lxml")
  >>> print(html.find("tbody"))
  <tbody>
  <tr>
  <td scope="row">
  <input name="id" type="radio" value="1"/>
  </td>
  <td>Mike</td>
  <td>[email protected]</td>
  </tr>
  </tbody>
  >>> res = control.main({"op":"new"})
  >>> inp = BS(res["body"], "lxml").find_all("input")
  >>> print(*inp, sep="\n")
  <input name="op" type="hidden" value="save"/>
  <input class="form-control" id="name" name="name" type="text" value=""/>
  <input class="form-control" id="email" name="email" type="email" value=""/>
  >>> res = control.main({"op":"edit", "id":"1"})
  >>> inp = BS(res["body"], "lxml").find_all("input")
  >>> print(*inp, sep="\n")
  <input name="id" type="hidden" value="1"/>
  <input name="op" type="hidden" value="save"/>
  <input class="form-control" id="name" name="name" type="text" value="Mike"/>
  <input class="form-control" id="email" name="email" type="email" value="[email protected]"/>
  >>> model.insert = control.inspect
  >>> args = {"op":"save", "name":"Miri","email":"[email protected]"}
  >>> x = control.main(args)
  >>> print(control.spy)
  {'name': 'Miri', 'email': '[email protected]'}
  >>> model.update = control.inspect
  >>> args = {"op":"save", "id": "1", "name":"Mike","email":"[email protected]"}
  >>> x = control.main(args)
  >>> print(control.spy)
  {'id': '1', 'name': 'Mike', 'email': '[email protected]'}
    """
    op = args.get("op")
    if op == "new":
        body = view.form(fill({}))
        return {"body": view.wrap(body)}
    if op == "edit" and "id" in args:
        res = model.find(args["id"])
        rec = res["docs"][0]
        body = view.form(rec)
        return {"body": view.wrap(body)}
    if op == "save":
        if "id" in args:
            model.update(fill(args))
        else:
            model.insert(fill(args))
    if op == "delete" and "id" in args:
        model.delete(args["id"])
    data = model.find()["docs"]
    body = view.table(data)
    return {"body": view.wrap(body)}
Exemple #19
0
def insert(tname):
    data = reader.multiple_input(tname, 'Enter new fields values:')
    model.insert(tname, data)
    show_table_menu(tname, 'Insertion was made successfully')