Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
amalthomas-exe committed Jan 29, 2021
1 parent 27f7dd1 commit 1435ba4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
38 changes: 26 additions & 12 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import time
start = time.time()
import multiprocessing
from flask import Flask, render_template, request
from flask import Flask, render_template,request,url_for
from gevent.pywsgi import WSGIServer
import webview
import pickle
import random
from datetime import datetime
import sqlite3
import os
from multiprocessing import Process
import urllib.request
now = datetime.now().strftime("%H:%M")
Expand All @@ -19,7 +20,21 @@
reject = ["I'm sorry I cannot do that"]
thanks = ["thanks","thank","thnx"]
app = Flask(__name__)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
app.static_folder = 'static'
@app.context_processor
def override_url_for():
return dict(url_for=dated_url_for)

def dated_url_for(endpoint, **values):
if endpoint == 'static':
filename = values.get('filename', None)
if filename:
file_path = os.path.join(app.root_path,
endpoint, filename)
values['q'] = int(os.stat(file_path).st_mtime)
return url_for(endpoint, **values)


def check_for_connection():
try:
Expand All @@ -34,9 +49,9 @@ def home():
try:
global f
f=open("data\\user\\user-data.dat","rb")
global dict
dict = pickle.load(f)
return render_template("index.html",time = now,User = dict["first-name"])
global dict2
dict2 = pickle.load(f)
return render_template("index.html",time = now,User = dict2["first-name"])

except:
global f1
Expand Down Expand Up @@ -100,11 +115,11 @@ def success():
f1.close()
global f
f=open("data\\user\\user-data.dat","rb")
global dict
dict = pickle.load(f)
global dict2
dict2 = pickle.load(f)
print("Done")

return render_template("index.html",time = now,User = dict["first-name"])
return render_template("index.html",time = now,User = dict2["first-name"])


@app.route("/get")
Expand All @@ -117,7 +132,7 @@ def get_bot_response():
for i in lst:
if i.lower() in greetings and len(lst)<3:
lst.clear()
return f"{random.choice(['hi','Hey','Hello','Welcome','Yo'])} {dict['first-name']}"
return f"{random.choice(['hi','Hey','Hello','Welcome','Yo'])} {dict2['first-name']}"
if i.lower() in thanks:
lst.clear()
return random.choice(["You're Welcome 😊","Oh! that's my job 😊"])
Expand Down Expand Up @@ -146,9 +161,9 @@ def get_bot_response():

if bot_response!=[] and bot_response[-1]=="mail-with-id":
import yagmail
mailer = yagmail.SMTP(dict["email"],dict["password"])
mailer = yagmail.SMTP(dict2["email"],dict2["password"])
try:
mailer.send(mail_addr,"Message from "+dict["first-name"],userText)
mailer.send(mail_addr,"Message from "+dict2["first-name"],userText)
bot_response.clear()
lst.clear()
return random.choice(["Got it! The mail has been sent 👍","The message has been sent 👍","Mail sent 👍"])
Expand Down Expand Up @@ -330,7 +345,6 @@ def no_connection():

def run_server():
print("Server started")
app.jinja_env.cache = {}
http_server = WSGIServer(('', 5000), app)
http_server.serve_forever()

Expand All @@ -346,4 +360,4 @@ def on_close():
window.closing += on_close
end = time.time()
print(f"It took {end-start:.2f} seconds to complete")
webview.start()
webview.start()
4 changes: 2 additions & 2 deletions static/styles/new-user.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:root{
font-family: 'Roboto', sans-serif;
background-image: url("https://miro.medium.com/max/3200/1*Sdckr5tAt5peOaZJgsAQ1Q.png");
background-image:url("https://images.cdn4.stockunlimited.net/preview1300/robot-saying-hello_1340574.jpg");;
background-size:cover;
background-repeat: no-repeat;
background-position: left;
Expand Down Expand Up @@ -39,7 +39,7 @@
border-radius: 7px;
}
.label{
margin-left: 30px;
margin-left: 50px;
font-size:30px;
margin-top: 257px;
padding-top: 200px;
Expand Down

0 comments on commit 1435ba4

Please sign in to comment.