pranavamenu4aie2 commited on
Commit
9903fdf
1 Parent(s): c3c0dca

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +170 -0
app.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pyautogui as pt
2
+ from time import sleep
3
+ import pyperclip
4
+ import sklearn
5
+ import random
6
+ #import webbrowser
7
+ #from flask import Flask , render_template , request
8
+ import pickle
9
+ from playsound import playsound
10
+ from difflib import SequenceMatcher
11
+ import numpy as np
12
+ import subprocess
13
+ subprocess.Popen(["cmd", "/C", "start whatsapp://send?phone=+918075994774"], shell=True)
14
+
15
+
16
+ class pranav:
17
+ def play():
18
+ playsound("sound/IphoneWhatsappTone.mp3")
19
+ return "Hi there,this is Mr.Bot I generate auto replies for general messages."
20
+
21
+ # webbrowser.open('https://web.whatsapp.com')
22
+ model = pickle.load(open('model.pkl', 'rb'))
23
+ cv = pickle.load(open('vector.pkl', 'rb'))
24
+
25
+ greetings = {"Hi": "Hi", "Hello": "Hai", "Hi": "Hello", "Greetings!": "Hello", "Hello": "Greetings!", "Hi, How is it going?": "Good", "Hi, How is it going?": "Fine", "Hi, How is it going?": "Okay", "Hi, How is it going?": "Great", "Hi, How is it going?": "Could be better.", "Hi, How is it going?": "Not so great.", "How are you doing?": "Good.", "How are you doing?": "Very well, thanks.", "How are you doing?": "Fine, and you?", "Nice to meet you.": "Thank you.", "How do you do?": "I'm doing well.",
26
+ "How do you do?": "I'm doing well. How are you?", "Hi, nice to meet you.": "Thank you. You too.", "It is a pleasure to meet you.": "Thank you. You too.", "Top of the morning to you!": "Thank you kindly.", "Top of the morning to you!": "And the rest of the day to you.", "What's up?": "Not much.", "What's up?": "Not too much.", "What's up?": "Not much, how about you?", "What's up?": "Nothing much.", "What's up?": "The sky's up but I'm fine thanks. What about you?","Thank you.":"Welcome"}
27
+
28
+ LIST = ["Hello", "Hi", "Hi", "Hello", "Greetings!", "Hello", "Hello", "Greetings!", "Hi, How is it going?", "Good", "Hi, How is it going?", "Fine", "Hi, How is it going?", "Okay", "Hi, How is it going?", "Great", "Hi, How is it going?", "Could be better.", "Hi, How is it going?", "Not so great.", "How are you doing?", "Good.", "How are you doing?", "Very well, thanks.", "How are you doing?", "Fine, and you?", "Nice to meet you.", "Thank you.", "How do you do?", "I'm doing well.",
29
+ "How do you do?", "I'm doing well. How are you?", "Hi, nice to meet you.", "Thank you. You too.", "It is a pleasure to meet you.", "Thank you. You too.", "Top of the morning to you!", "Thank you kindly.", "Top of the morning to you!", "And the rest of the day to you.", "What's up?", "Not much.", "What's up?", "Not too much.", "What's up?", "Not much, how about you?", "What's up?", "Nothing much.", "What's up?", "The sky's up but I'm fine thanks. What about you?","Welcome"]
30
+
31
+ sleep(15)
32
+
33
+ position1 = pt.locateOnScreen("smiley_paperclip.png", confidence=0.6)
34
+ x = position1[0]
35
+ y = position1[1]
36
+
37
+ # position2 = pt.locateOnScreen("web_browser_logo.png", confidence=0.6)
38
+ # x = position2[0]
39
+ # y = position2[1]
40
+
41
+ # Gets message
42
+
43
+
44
+ def similar(a, b):
45
+ return SequenceMatcher(None, a, b).ratio()
46
+
47
+
48
+ def check(str1):
49
+ bool = False
50
+ for i in LIST:
51
+ i = i.lower()
52
+ str1 = str1.lower()
53
+ if similar(str1, i) > 0.8:
54
+ bool = True
55
+ break
56
+ return bool
57
+
58
+
59
+ res = [*set(LIST)]
60
+
61
+
62
+ def checkpk(str1):
63
+ for i in res:
64
+ j = i.lower()
65
+ str1 = str1.lower()
66
+ if similar(str1, j) > 0.75:
67
+ return i
68
+
69
+
70
+ def reply(str1):
71
+
72
+ return greetings[checkpk(str1)]
73
+
74
+
75
+ # def play():
76
+ # playsound("IphoneWhatsappTone.mp3")
77
+
78
+
79
+
80
+
81
+ def getmessage():
82
+ global x, y
83
+
84
+ position = pt.locateOnScreen("Smiley_paperclip.png", confidence=0.6)
85
+ x = position[0]
86
+ y = position[1]
87
+ pt.moveTo(x, y, duration=0.5)
88
+ pt.moveTo(x + 90, y - 60, duration=0.5)
89
+ # if pt.pixelMatchesColor(int(x + 90),int(y - 70),(46, 198, 80),tolerance=10):
90
+ pt.tripleClick()
91
+ pt.rightClick()
92
+ pt.moveRel(12, 15)
93
+ pt.click()
94
+ whatsapp_message = pyperclip.paste()
95
+ pt.click()
96
+ print("meassage received: " + whatsapp_message)
97
+
98
+ return whatsapp_message
99
+
100
+
101
+ # Post
102
+ def post_response(message):
103
+ global x, y
104
+
105
+ position = pt.locateOnScreen("Smiley_paperclip.png", confidence=0.6)
106
+ x = position[0]
107
+ y = position[1]
108
+ pt.moveTo(x + 200, y + 20, duration=0.5)
109
+ pt.click()
110
+ pt.typewrite(message, interval=0.01)
111
+
112
+ pt.typewrite("\n", interval=0.01)
113
+
114
+ # Processes Response
115
+
116
+
117
+ def process_response(message):
118
+ #random_no = random.randrange(3)
119
+ data = [message]
120
+ data = cv.transform(data).toarray()
121
+ pred = model.predict(data)
122
+
123
+ if pred == [1]:
124
+ return "Pranav don't spam"
125
+ else:
126
+ if check(message) == True:
127
+ return reply(message)
128
+ else:
129
+ return pranav.play()
130
+ # if random_no == 0:
131
+ # return "That's cool"
132
+ # elif random_no == 1:
133
+ # return "yeah"
134
+ # else:
135
+ # return "Hmmm"
136
+
137
+
138
+ # Check for new message
139
+ def check_for_new_message():
140
+ # global x, y
141
+ # position = pt.locateOnScreen("web_browser_logo.png", confidence=0.6)
142
+ # x = position[0]
143
+ # y = position[1]
144
+ pt.moveTo(x + 90, y - 60, duration=0.5)
145
+
146
+
147
+ while True:
148
+ # Continuously check for the green point and new messages
149
+ try:
150
+ position = pt.locateOnScreen("green_point.png", confidence=0.7)
151
+
152
+ if position is not None:
153
+ pt.moveTo(position)
154
+ pt.moveRel(-100, 0)
155
+ pt.click()
156
+ sleep(0.5)
157
+ # post_response()
158
+
159
+ except(Exception):
160
+ print("No new messages found")
161
+
162
+ if pt.pixelMatchesColor(int(x + 90), int(y - 60), (32, 44, 51), tolerance=10):
163
+ print("is grey")
164
+ processed_message = process_response(getmessage())
165
+ post_response(processed_message)
166
+ else:
167
+ print("No new messages")
168
+ # sleep(5)
169
+
170
+ check_for_new_message()