def addedbook(): nData = DbClass().adddata() nAuteur = DbClass().addauteur() GPIO.output(led, GPIO.HIGH) GPIO.output(buz, GPIO.HIGH) time.sleep(1) GPIO.output(led, GPIO.LOW) GPIO.output(buz, GPIO.LOW) return render_template('index.html', nData=nData)
def process(): msg = request.form['message'] print(msg) user_response = msg.lower() res = "" global flag global p global name global cur_physician if flag: for word in APPROVAL: if word in user_response: appointment_no = DbClass.read( dbclass.query1, cur_physician)[0]['appointment_no'] if appointment_no <= 4: time = str(appointment_no + 8) + ' am' res = "Appointment fixed at " + time + " tomorrow, thankyou!" send_mail(cur_physician, time, name) else: if appointment_no <= 8: time = str(appointment_no - 3) + ' pm' res = "Appointment fixed at " + time + ", tomorrow, thankyou!" send_mail(cur_physician, time, name) else: res = "Sorry! No appointments tomorrow" appointment_no += 1 DbClass.simple_update(dbclass.query3) DbClass.update(dbclass.query2, (appointment_no, cur_physician)) cur_physician = "" flag = False p = False name = "" else: if 'appointment' in user_response.split( ) or 'meet' in user_response.split(): if p: for word in user_response.split(): for physician in PHYSICIANS: if physician.lower() == word: appointment_no = DbClass.read( dbclass.query1, physician)[0]['appointment_no'] if appointment_no <= 4: time = str(appointment_no + 8) + ' am' res = "Appointment fixed at " + time + " tomorrow, thankyou!" send_mail(cur_physician, time, name) else: if appointment_no < 8: time = str(appointment_no - 3) + ' pm' res = "Appointment fixed at " + time + ", tomorrow, thankyou!" send_mail(cur_physician, time, name) else: res = "Sorry! No appointments tomorrow" appointment_no += 1 DbClass.update(dbclass.query2, (appointment_no, physician)) p = False name = "" else: res = "May I know your name?" p = True else: if user_response == 'thanks' or user_response == 'thank you': res = "You are welcome.." else: if 'bye' in user_response: res = "Bye! take care.." else: for word in user_response.split(): robo_res = None if word in GREETING_INPUTS: robo_res = random.choice( GREETING_RESPONSES ) + "!, May I know your name?" p = True if robo_res: res = robo_res else: if res is "" and p: if name: sent_tokens.append(user_response) TfidfVec = TfidfVectorizer( tokenizer=LemNormalize, stop_words='english') tfidf = TfidfVec.fit_transform(sent_tokens) vals = cosine_similarity(tfidf[-1], tfidf) idx = vals.argsort()[0][-2] flat = vals.flatten() flat.sort() req_tfidf = flat[-2] if req_tfidf == 0: res = "I am sorry! I can't understand you" else: robo_response = sent_tokens[idx] for resp in robo_response.split(): for physician in PHYSICIANS: if physician.lower() == resp: res = "Do you want me to fix an appointment with the %s?" % physician cur_physician = physician flag = True sent_tokens.remove(user_response) else: name = user_response res = "How can I help you?" print(res) return jsonify({'message': res})
from flask import Flask, render_template, request, jsonify import nltk import random import string from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.metrics.pairwise import cosine_similarity import dbclass from dbclass import DbClass import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText app = Flask(__name__) DbClass = DbClass() GREETING_INPUTS = ["hello", "hi", "greetings", "sup", "hey", "hey", "hai"] GREETING_RESPONSES = [ "hi", "hey", "hi there", "hello", "I am glad! You are talking to me" ] APPROVAL = ['yes', 'yeah', 'ok', 'okay'] PHYSICIANS = [ 'Paediatrician', 'Gynaecologist', 'Surgeon', 'Psychiatrist', 'Cardiologist', 'Dermatologist', 'Endocrinologist', 'Gastroenterologist', 'Nephrologist', 'Ophthalmologist', 'Otolaryngologist', 'ENT', 'Pulmonologist', 'Neurologist', 'Radiologist', 'Anaesthesiologist', 'Oncologist' ] flag = False p = False cur_physician = "" name = "" f = open('physicians.txt', 'r', errors='ignore')
from ledclass import LEDclass from dbclass import DbClass import time import datetime import sys print(sys.executable) import os print(os.getcwd()) print(sys.path) time.sleep(15) leds = LEDclass(13, 19, 26) data = DbClass() input = MCP3008(0, 0) why = input.readLight() left = input.readLeftButton() right = input.readRightButton() print(why, left, right) def datetimefromtime(timer): uren = int(timer[0:2]) minuten = int(timer[3:5]) result = datetime.datetime(datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day, uren, minuten, 0) return result
import psycopg2 from dbclass import DbClass if __name__ == '__main__': try: db = DbClass(dbn="courses", log=True) # db.connect() # command = ( """ CREATE TABLE evaluations ( course_id INTEGER NOT NULL, student_id INTEGER NOT NULL, eval_date DATE, eval_course_mod CHAR(10), eval_course_date DATE, eval_domain CHAR(10), eval_present_duration CHAR(10), eval_facility CHAR(10), eval_clarity CHAR(10), eval_relationship CHAR(10), eval_usable CHAR(10), eval_handout CHAR(10), eval_applicable CHAR(10), eval_organiz CHAR(10), eval_local CHAR(10), eval_expectancy CHAR(10), eval_comments CHAR(10), eval_strong_points CHAR(150),
def rentedbooks(): rented = DbClass().getrented() return render_template('rentedbooks.html',rented =rented)
def allbooks(): data = DbClass().getdata() return render_template('allbooks.html',data=data)
import psycopg2 from dbclass import DbClass if __name__ == '__main__': try: # db = DbClass(dbn="Bakos", log=True) # db.connect() # ssss command = "SELECT oid, * FROM pg_catalog.pg_am" db.execute(command) # fetch = db.cur.fetchall() i = 1 for row in fetch: print("Row number ", i, "- ", row) i += 1 # db.close() # except (Exception, psycopg2.DatabaseError) as error: print("Db error = ", error)