Exemplo n.º 1
0
def process_query(query):
    '''Used to process the user query
    '''
    #used to store the results of the first query
    query1_results = []
    #used to store the results of the second query
    query2_results = []
    #stores all the results from both queries
    final = []

    if len(query) != 0:
        try:
            result = db.find(query[0])
            query1_results.extend(result['info'])
        except Exception:
            pass

    #ignores 2nd query if same as first
    if len(query) >= 2 and query[1] != query[0]:
        try:
            result = db.find(query[1])
            query2_results.extend(result['info'])
        except Exception:
            pass

    #checks both postings list for similar docID
    for q1 in query1_results[:]:
        for q2 in query2_results[:]:
            if q2['docID'] == q1['docID']:
                #adds tf,tf-idf,custom_score of both results and appends to final list
                final.append({
                    'docID':
                    q1['docID'],
                    'tf':
                    q1['tf'] + q2['tf'],
                    'tf-idf':
                    q1['tf-idf'] + q2['tf-idf'],
                    'custom_score':
                    q1['custom_score'] + q2['custom_score']
                })
                #removes that entry from both lists since it was appended to final list
                query2_results.remove(q2)
                query1_results.remove(q1)

    #adds remaining results to the final list of results
    final.extend(query1_results)
    final.extend(query2_results)

    return final
Exemplo n.º 2
0
def dht11_temp_humi(equip,mode):
    '''
    获取温湿度api接口
    equip: 设备上贴着的传感器序列号
    mode: 支持once / always两种参数,once只进行一个温湿度数据读取,always自动周期性读取,并保存至数据库中。
    ctime: int 在always模式下生效,单位秒,默认60s
    '''
    result = db.find(equip)
    if result == None:
        return (False, 'not found this equip')
    (ipaddr, port) = result
    if mode == 'host' or mode == 'host_remote' or mode == 'docker_remote':
        ipaddr = os.getenv('HFV_HOST')
    elif mode == 'docker':
        ipaddr = equip
        port = 3000
    else:
        return (False, 'no this mode')

    cmd = 'python3 send.py ' + ipaddr + ' ' + str(port) + ' temp'
    (status, output) = subprocess.getstatusoutput(cmd)
    if status == 0:
        (temp, humi) = output.split('&')
        return (temp, humi)
    else:
        return (False, output)
Exemplo n.º 3
0
def getNewInvestments(venmo_id):

    documents = db.find(new_investments_str, {"user_id" : venmo_id })

    return jsonify(**{
        "List": documents 
        })
Exemplo n.º 4
0
def snip(uid):
    try:
        data = find(uid)
    except InvalidId:
        return "404"

    if not data:
        return "404"

    try:
        syntax = request.args.keys()[0]
    except IndexError:
        syntax = None

    if syntax:
        try:
            lexer = pygments.lexers.get_lexer_by_name(syntax)
        except:
            lexer = pygments.lexers.TextLexer()
        formatter = HtmlFormatter(full=True, style="borland", lineanchors="n", linenos="inline", encoding="utf-8")
        return highlight(data["content"], lexer, formatter)
    else:
        response = make_response(data["content"])
        response.headers["Content-Type"] = "text/plain"
        return response
Exemplo n.º 5
0
def snip(uid):
    try:
        data = find(uid)
    except InvalidId:
        return '404'

    if not data:
        return '404'

    try:
        syntax = request.args.keys()[0]
    except IndexError:
        syntax = None

    if syntax:
        try:
            lexer = pygments.lexers.get_lexer_by_name(syntax)
        except:
            lexer = pygments.lexers.TextLexer()
        formatter = HtmlFormatter(full=True,
                style=STYLE, linenos='inline',
                encoding='utf-8')
        return highlight(data['content'], lexer, formatter)
    else:
        response = make_response(data['content'])
        response.headers['Content-Type'] = 'text/plain';
        return response
Exemplo n.º 6
0
def GetCurrentMonth(user):
    currnow = datetime.datetime.now()
    curryear = currnow.year
    currmonth = currnow.month - 1
    data = db.find(curryear, currmonth, user)
    endmonth = datetime.date(curryear,currmonth + 2,1) - datetime.timedelta(days=1)
    diffdays =  (endmonth - datetime.date.today()).days
    amtspent = data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7]
    amtsaved = data[0] - data[1] - data[2] - data[3] - data[4] - data[5] - data[6] - data[7]
    amtleftperday = amtsaved / diffdays
    pos = ""
    over = ""
    if amtsaved < 0:
        pos = "-"
        amtleftperday = 0
        over = "\n\nOVERSPEND!!!!"
    amtsaved = abs(amtsaved)
    output = "<b><u>Current month status: </u></b>\
        \n<b>Budget: ${L1:.2f} </b>\
        \nFood: ${L2:.2f} \
        \nTransport: ${L3:.2f} \
        \nBills: ${L4:.2f} \
        \nShopping: ${L5:.2f} \
        \nFun: ${L6:.2f} \
        \nGifts: ${L7:.2f} \
        \nOthers: ${L8:.2f} \
        <b><u>{over}</u></b> \
        \n\nAmount spent: ${L9:.2f} \
        \nAmount saved: {P}${L10:.2f} \
        \n\nDays left to end of month: <b><u>{D}</u></b> \
        \nAmount left to spend per day: <b><u>${A:.2f}</u></b>"
    return output.format(L1 = data[0], L2 = data[1], L3 = data[2], L4 = data[3], L5 = data[4], L6 = data[5], L7 = data[6], L8 = data[7], L9 = amtspent, L10 = amtsaved, P = pos, D = diffdays, A = amtleftperday, over = over)
Exemplo n.º 7
0
def GetData(yearNum, month, user):
    yearNum = int(yearNum)
    month = int(month)
    monthCat = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "whole of"]
    output = "<b><u>Status for {m} {y}: </u></b>\
        \n<b>Budget: ${L1:.2f} </b>\
        \nFood: ${L2:.2f} \
        \nTransport: ${L3:.2f} \
        \nBills: ${L4:.2f} \
        \nShopping: ${L5:.2f} \
        \nFun: ${L6:.2f} \
        \nGifts: ${L7:.2f} \
        \nOthers: ${L8:.2f} \
        \n\nAmount spent: ${L9:.2f} \
        \nAmount saved: {P}${L10:.2f}"
    if month == 13:
        return GetAllData(yearNum, monthCat, user)
    elif not db.check_data(yearNum, month, 1, user):
        return "There is no data for " + str(monthCat[month]) + " " + str(yearNum)
    else:
        data = db.find(yearNum, month, user)
        amtspent = data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7]
        amtsaved = data[0] - data[1] - data[2] - data[3] - data[4] - data[5] - data[6] - data[7]
        pos = ""
        if amtsaved < 0:
            pos = "-"
        amtsaved = abs(amtsaved)
        return output.format(m = monthCat[month], y = yearNum, L1 = data[0], L2 = data[1], L3 = data[2], L4 = data[3], L5 = data[4], L6 = data[5], L7 = data[6], L8 = data[7], L9 = amtspent, L10 = amtsaved, P = pos)
Exemplo n.º 8
0
def getCurrentInvestments(venmo_id):

    documents = db.find(bought_investments_str, {"user_id" : venmo_id , "is_redeemed" : False})


    return jsonify(**{
        "List": documents 
        })
Exemplo n.º 9
0
def get_destination(message, frm):
    hashtag = re.findall('#([a-zA-Z0-9]+)', message)[-1]
    print "Hastag: %s" % hashtag
    if hashtag in special_commands.keys():
        print "special_command found: %s" % hashtag
        special_commands[hashtag](frm)
        raise CustomCommandExecuted()
    return db.find(tag=hashtag)
Exemplo n.º 10
0
def get_destination(message, frm):
    hashtag = re.findall('#([a-zA-Z0-9]+)', message)[-1]
    app.logger.info("Hastag: %s", hashtag)
    if hashtag in special_commands.keys():
        app.logger.info("special_command found: %s", hashtag)
        special_commands[hashtag](frm)
        raise CustomCommandExecuted()
    return db.find(tag=hashtag)
Exemplo n.º 11
0
 def test_find():
     query = db.makeRecord("20 ROOT ROOT 2000 24")
     for i in db._attribute:
         indexname = i + '_' + name + '.json'
         res = db.find(query[i], indexname)
         if not res == None:
             lines = db.retrieve(res[0].keys[res[1]], database)
             print ('Records found in ' + indexname)
             db.printRecords(lines)
Exemplo n.º 12
0
def ticketGen():
    ticket = 0
    while ticket == 0:
        ticket = random.randint(1, 999999999)

        outcome = find(ticket)
        if len(outcome) != 2:
            ticket = 0
        else:
            break

    return ticket
Exemplo n.º 13
0
def search():
    form = Search()
    name = form.name.data
    if form.validate_on_submit():
        rows = find(name)
        try:
            result = rows[0]
        except:
            return render_template('search.html',
                                   error="No match found",
                                   form=form)
        return render_template('search.html', result=result)
    return render_template('search.html', form=form)
Exemplo n.º 14
0
def GetAllData(yearNum, monthCat, user):
    data = db.find(yearNum, 12, user)
    amtspent = data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7]
    amtsaved = data[0] - data[1] - data[2] - data[3] - data[4] - data[5] - data[6] - data[7]
    pos = ""
    if amtsaved < 0:
        pos = "-"
    amtsaved = abs(amtsaved)
    fulloutput = "<b><u>Full status for {y}: </u></b>\
        \n<b>Budget: ${T1:.2f} </b>\
        \n<b>Total amount spent: ${T2:.2f} </b>\
        \n<b>Total amount saved: {P}${T3:.2f} </b>\
        \n".format(y = yearNum, T1 = data[0], T2 = amtspent, T3 = amtsaved, P = pos)
    for x in range(12):
        if not db.check_data(yearNum, x, 1, user):
            curroutput = "\n\n<u>{M}: </u>\
                No data available".format(M = monthCat[x])
        else:
            data = db.find(yearNum, x, user)
            amtspent = data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7]
            amtsaved = data[0] - data[1] - data[2] - data[3] - data[4] - data[5] - data[6] - data[7]
            pos = ""
            if amtsaved < 0:
                pos = "-"
            amtsaved = abs(amtsaved)
            curroutput = "\n\n<u>{M}: </u>\
                \n<b>Budget: ${L1:.2f} </b>\
                \n<b><i>Amount spent: ${L9:.2f} </i></b>\
                \n<b><i>Amount saved: {P}${L10:.2f} </i></b>\
                \nFood: ${L2:.2f} \
                \nTransport: ${L3:.2f} \
                \nBills: ${L4:.2f} \
                \nShopping: ${L5:.2f} \
                \nFun: ${L6:.2f} \
                \nGifts: ${L7:.2f} \
                \nOthers: ${L8:.2f}".format(M = monthCat[x], L1 = data[0], L2 = data[1], L3 = data[2], L4 = data[3], L5 = data[4], L6 = data[5], L7 = data[6], L8 = data[7], L9 = amtspent, L10 = amtsaved, P = pos)
        fulloutput += curroutput
    return fulloutput
Exemplo n.º 15
0
def setCurrentInvestment():
    venmo_id = request.form['venmo_name']
    investment_id = request.form['investment_id']
    amount = float(request.form['amount']) 

    account_info = db.find_one(account_collection_str, {"user_id" : str(venmo_id)})
    current_chequing = float(account_info['chequing_balance'])
    new_investments_collection = db.get_collection(new_investments_str)

    investment  = new_investments_collection.find_one({'investment_id': investment_id})
                                                
    # post as long as value is 0
    if amount < 0 or current_chequing < amount or investment['is_purchased'] == True:
        return jsonify(**{
            "success": False
            })

    else:        
        addBoughtInvestment(venmo_id, 
                            investment_id, 
                            amount,
                            )
        new_chequing_balance = current_chequing - amount
        account_info = db.get_collection(account_collection_str)
        account_info.update({"user_id" : venmo_id},
                {"$set": {"chequing_balance" : new_chequing_balance}})


        new_investment_list = db.find(new_investments_str, {"user_id" : venmo_id, "is_purchased": False })
        current_investment_list = db.find(bought_investments_str, {"user_id" : venmo_id })

    
    return jsonify(**{
        "chequing_balance": new_chequing_balance,
        "new_investments" : new_investment_list,
        "my_investments"  : current_investment_list,
        })
Exemplo n.º 16
0
def getProduto(id):

    cur = conn.cursor()

    data = db.find(id, cur)

    if data != None:

        produto = {
            "id": data[0],
            "descricao": data[1],
            "quantidade": data[2],
            "preco": data[3]
        }
        return jsonify(produto)

    return jsonify({"message": "Item não existe."})
Exemplo n.º 17
0
def switch(equip, mode):
    result = db.find(equip)
    if result == None:
        return (False, 'not found this equip')
    (ipaddr, port) = result
    if mode == 'host':
        cmd = 'python3 send.py ' + ipaddr + ' ' + str(port) + ' True'
        (status, output) = subprocess.getstatusoutput(cmd)
        if status == 0:
            return output
        else:
            return (False, output)
    elif mode == 'docker':
        print('failed')
        return (False, 'mode error')
    else:
        return (False, 'no this mode')
Exemplo n.º 18
0
def putProduto(id):

    dados = request.get_json(force=True)

    if dados['descricao'] != '':

        dados['id'] = id

        cur = conn.cursor()

        if db.update(dados, cur):

            db.applyCommit(conn)

            return jsonify(db.find(id, cur))
        #end if
    #end if
    return jsonify({"message": "Erro. Operação inválida."})
Exemplo n.º 19
0
def handle_text(message):
    print("text received")
    try:
        if "%" in message.text:
            print("group")
            names = [str(message.from_user.id) + "/" + el[2] for el in db.find(message.from_user.id, message.text.strip())]
            print(names)
            urls = saver.download(names)
        else:
            urls = saver.download({f"{message.from_user.id}/{message.text}.jpg"})

        for url in urls:
            bot.send_photo(message.chat.id, url)
    except Exception as E:
        print(E)
        bot.send_message(message.chat.id, "Sorry. No such a meme...\n" + str(E))
        if str(E) == "MySQL Connection not available." or "MySQL Connection not available." in str(E):
            print("exiting")
            db.back()
Exemplo n.º 20
0
def switch(equip, mode, method):
    result = db.find(equip)
    if result is None:
        return (False, 'not found this equip')
    (ipaddr, port) = result
    if mode == 'host' or mode == 'host_remote' or mode == 'docker_remote':
        ipaddr = os.getenv('HFV_HOST')
    elif mode == 'docker':
        ipaddr = equip
        port = 3000
    else:
        return (False, 'no this mode')

    cmd = 'python3 send.py ' + ipaddr + ' ' + str(port) + ' ' + method
    (status, output) = subprocess.getstatusoutput(cmd)
    if status == 0:
        return output
    else:
        return (False, output)
Exemplo n.º 21
0
    def getData(self, method):
        result = db.find(self.equip)
        if result == None:
            return False
        (ipaddr, port) = result
        if self.mode == 'host' or self.mode == 'host_remote' or self.mode == 'docker_remote':
            ipaddr = os.getenv('HFV_HOST')
        elif self.mode == 'docker':
            ipaddr = self.equip
            port = 3000
        else:
            return False

        cmd = 'python3 send.py ' + ipaddr + ' ' + str(port) + ' ' + method
        (status, output) = subprocess.getstatusoutput(cmd)
        if status == 0:
            return output
        else:
            return False
Exemplo n.º 22
0
    def getData(self):
        result = db.find(self.equip)
        if result is None:
            return (False, 'not found this equip')
        (ipaddr, port) = result
        if self.mode == 'host' or self.mode == 'host_remote' or self.mode == 'docker_remote':
            ipaddr = os.getenv('HFV_HOST')
        elif self.mode == 'docker':
            ipaddr = self.equip
            port = 3000
        else:
            return (False, 'no this mode')

        cmd = 'python3 send.py ' + ipaddr + ' ' + str(port) + ' temp'
        (status, output) = subprocess.getstatusoutput(cmd)
        if status == 0:
            return output
        else:
            return False
Exemplo n.º 23
0
def dht11_temp_humi(equip, mode):
    '''
    获取温湿度api接口
    '''
    result = db.find(equip)
    if result is None:
        return (False, 'not found this equip')
    (ipaddr, port) = result
    if mode == 'host' or mode == 'host_remote' or mode == 'docker_remote':
        ipaddr = os.getenv('HFV_HOST')
    elif mode == 'docker':
        ipaddr = equip
        port = 3000
    else:
        return (False, 'no this mode')

    cmd = 'python3 send.py ' + ipaddr + ' ' + str(port) + ' temp'
    (status, output) = subprocess.getstatusoutput(cmd)
    if status == 0:
        (temp, humi) = output.split('&')
        return (temp, humi)
    else:
        return (False, output)
Exemplo n.º 24
0
def get_index():
    urls = db.find({});
    return dict(urls=urls)
Exemplo n.º 25
0
    def doGet(self,
              table,
              select="*",
              where=None,
              order=None,
              limit=None,
              sfields=None,
              stext=None,
              res=True,
              nolimit=False,
              timeField="create_time"):

        if not order:
            order = "id desc"

        db = self.getDB(table)
        cond = {"select": select, "order": order}

        wheres = []

        if not nolimit:
            if not limit:
                limit = self.limitArgv()
            if limit:
                cond["limit"] = limit

        if sfields:
            if not stext:
                stext = self.get_argument("s", default=None)
            if stext:
                scond = self.searchCond(sfields, stext)
                wheres.append(scond)
                #if where :
                #	where = "%s and (%s)" % (where, scond)
                #else :
                #	where = scond

        _id = self.get_argument("id", default=None)
        if not nolimit and _id:
            wheres.append("id=%s" % (_id))
            #if where :
            #	where = "id=%s and (%s)" % (_id, where)
            #else :
            #	where = "id=%s" % (_id)

        stime = self.get_argument("stime", default=None)
        if stime:
            wheres.append("%s>='%s'" % (timeField, stime))

        etime = self.get_argument("etime", default=None)
        if etime:
            wheres.append("%s<='%s'" % (timeField, etime))

        if where:
            wheres.append(where)
            where = None

        sz = len(wheres)
        if sz:
            if sz > 1:
                where = "(" + ")and(".join(wheres) + ")"
            else:
                where = wheres[0]

        if where:
            cond["where"] = where

        #D(wheres)
        #D(where)

        results = db.find(cond, isRaise=False)
        if res:
            self.response(results)
        else:
            return results
Exemplo n.º 26
0
 def treefind(value):
     res = db.find(value, indexname)
     if not res == None:
         lines = db.retrieve(res[0].keys[res[1]], database)
         print ('Records found in ' + indexname)
         db.printRecords(lines)
Exemplo n.º 27
0
import db
import extract
import vark_wiki as vark
from nltk import distance


examples = db.find('research')

total_tried = 0
total_successful = 0

for example in examples:

	url = example['pdf']

	print "testing: ", url

	text = extract.get_text(url)

	print "... got text"

	acronyms = list(vark.get_acronyms(text))

	print "... got acronym"
	print acronyms

	tried = 0
	successful = 0

	for acronym, expansion in example['definitions'].iteritems():
		if len(expansion) >= 1:
Exemplo n.º 28
0
async def get_location(lat: str, long: str):
    res = db.find(lat, long)
    return res