What's throws an error in this code:

3 views
Skip to first unread message

נתי שטרן

unread,
Nov 24, 2020, 4:16:24 AM11/24/20
to desertpy


#from orm import Database
import urllib3
#db = Database('db1.sqlite')  # indicating a database file.
from os import listdir
from os.path import isfile, join
from pony.orm import *
db = Database()
class Line(db.Entity):
     text = Required(str)
     number = Required(int)
     results = Set('Result')
  

class Result(db.Entity):
     filePath = Required(str)
     line = Required(Line)
     searches=Set('Search')

class Search(db.Entity):
     myID = Required(str)

     query = Required(str)
     results = Set('Result')



   
db.bind(provider='sqlite', filename='mydb.sqlite', create_db=True)

db.generate_mapping(create_tables=True)



from bottle import route, run, template

import glob

onlyfiles=glob.glob("C:\*.txt")

q11=glob.glob("C:\*.cobol")

def q(query):
    quer2y=query
    import time
#onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

    for a in q11:
        openfile=open(a)
        ln=0
        addr=a
        TIMER=time.ctime()
        for line in openfile:
            ln=ln+1
            quo=''
            quer2y=urllib3.parse.quote(quer2y)
                if quer2y in line:
                    with db_session:
                        l=Line(text=line,number=ln)
                        r=Result(filePath=addr,line=l)
                        s=Search(myID=TIMER,query=quer2y,results=r)
                        commit()
    a=""
    with db_session:                    
        query11 = select(c for c in Search if c.query==quer2y and c.myID==TIMER)
        for s in query11:
            a=a+"at: "+s.myID+"<br>"+str(s.results.filePath)+"<br>"+str(s.results.line.number)+"<br>"+str(s.results.line.text)
    return a

@route('/')
def a():
    return '<script>var x=prompt("query");window.location.replace("search/"+x);</script>'
@route('/search/<query>')
def index(query):
    return template('<b>{{query}}</b>'+q(query), query=query)

run(host='0.0.0.0', port=81)

        

Reply all
Reply to author
Forward
0 new messages