-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
363 lines (234 loc) · 10.8 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# --S--P--Y--C--H--A--T____P--R--O--J--E--C--T--
# importing important packages and classes and lists
from steganography.steganography import Steganography
from spy_details import spy, friends
from spy_details import Spy, ChatMessage
from termcolor import colored
from datetime import datetime
import csv
# -------------------STATUS MESSAGES LIST-----------------------------
STATUS_MESSAGES = ['Winter is coming', 'HODOR?', 'Everything is better with some wine in belly', 'VALAR MORGHULIS!',
'You know nothing JON SNOW!!']
# ___________________________FUNCTIONS___________________________________
# --------------------FUNCTION TO LOAD CHATS----------------------------
def load_chats():
with open('chats.csv', 'rb') as chat_data:
csvreader = csv.reader(chat_data, delimiter=',')
for row in csvreader:
chat = ChatMessage(hidden_text=row[1],time=row[2],sent_by_me=row[3])
friends[int(row[0])].chats.append(chat)
# -------------FUNCTION TO READ MESSAGES FROM THE USER------------------
def read_from_user():
friend_choice = select_friend()
if not friends[friend_choice].chats:
print "No Chats Till NOW!!"
else:
print "\nNAME:%s\n" % colored(friends[friend_choice].name, 'red')
for chat in friends[friend_choice].chats:
if chat.sent_by_me == 'True':
print "Message:%s\nTime:%s\t\t(Sent Message)\n" % (chat.hidden_text, colored(chat.time, 'blue'))
else:
print "Message:%s\nTime:%s\t\t(Recieved Message)\n" % (chat.hidden_text, colored(chat.time, 'blue'))
# -------------------FUNCTION TO SEND A MESSAGE------------------------
def send_message():
friend_choice = select_friend()
temp = True
while (temp):
original_image = raw_input("What is the name of the image?")
check_image = original_image.split('.')
if check_image[1] != "jpg":
print "Please Enter An image with jpg format!!"
else:
output_path = 'output.jpg'
text = raw_input("What do you want to say?")
Steganography.encode(original_image, output_path, text)
sent_by_me = True
new_chat = ChatMessage(text, datetime.now(), sent_by_me)
friends[friend_choice].chats.append(new_chat)
with open('chats.csv','a') as chat_data:
writer = csv.writer(chat_data)
writer.writerow([int(friend_choice), text, datetime.now(), sent_by_me])
print "Message sent successfuly!!"
temp = False
# ------------------FUNCTION TO READ MESSAGE----------------------------
def read_message():
sender = select_friend()
temp = True
while temp:
output_path = raw_input("What is the name of the file?")
check_image = output_path.split('.')
if check_image[1] != "jpg":
print "Please enter an image with jpg format!!"
else:
secret_text = Steganography.decode(output_path)
sent_by_me = False
print secret_text
new_chat = ChatMessage(secret_text,datetime.now(), sent_by_me)
friends[sender].chats.append(new_chat)
with open('chats.csv', 'a') as chat_data:
writer = csv.writer(chat_data)
writer.writerow([int(sender), secret_text, datetime.now(), sent_by_me])
print "Your secret message has been saved!"
temp = False
# -------------------FUNCTION TO SELECT FRIEND----------------------------
def select_friend():
friend_number = 1
print "Your friends are:"
for friend in friends:
print "%d. %s aged %d with rating %.2f is online" % (friend_number, friend.name, friend.age, friend.rating)
friend_number = friend_number + 1
friend_choose = input("\nSelect a Friend:")
friend_index = friend_choose - 1
return friend_index
# ---------------------FUNCTION TO ADD STATUS------------------------------
def add_status(current_status_message):
updated_status_message = None
if current_status_message is not None:
print """Your current status message is "%s" \n""" % current_status_message
else:
print "You don't have any status message currently \n"
repeat1 = True
while (repeat1):
default = raw_input("Do you want to select from the older status (y/n)?")
if default.upper() == "N":
temp1 = True
while (temp1):
new_status_message = raw_input("What status message do you want to select?")
if len(new_status_message) > 0:
updated_status_message = new_status_message
STATUS_MESSAGES.append(updated_status_message)
temp1 = False
else:
print "Type something!! Try Again!"
repeat1 = False
elif default.upper() == "Y":
status_number = 1
for message in STATUS_MESSAGES:
print "%d.%s" % (status_number, message)
status_number = status_number + 1
temp1 = True
while (temp1):
message_selection = input("\nChoose from the above message ")
if len(STATUS_MESSAGES) >= message_selection:
updated_status_message = STATUS_MESSAGES[message_selection - 1]
print "Status Updated!!"
temp1 = False
else:
print "Choose a valid option!"
repeat1 = False
else:
print "Plz! Input Y or N..."
print "Status Message:%s\n" % updated_status_message
return updated_status_message
# ----------------------FUNCTION TO LOAD FRIENDS---------------------
def load_friends():
with open('friends.csv', 'rb') as friend_data:
csvreader = csv.reader(friend_data, delimiter=',')
for row in csvreader:
friend = Spy(name=row[0], salutation=row[1], age=int(row[2]), rating=float(row[3]))
friends.append(friend)
# -----------------------FUNCTION TO ADD FRIEND-------------------------
def add_friend():
friend = Spy('', '', 0, 0.0)
friend.name = raw_input("Enter your friend's name:")
friend.salutation = raw_input("Are they (Mr./Mrs./Miss):")
friend.age = input("How old are they:")
friend.rating = input("What are their Spy Rating:")
if len(friend.name) > 0 and friend.age > 12 and friend.age < 50 and friend.rating >= spy.rating:
new_friend = Spy(friend.name, friend.salutation, friend.age, friend.rating)
friends.append(new_friend)
with open('friends.csv', 'a') as friend_data:
writer = csv.writer(friend_data)
writer.writerow([friend.name, friend.salutation, int(friend.age), float(friend.rating), friend.is_online])
else:
print "Sorry! Invalid entry. We can't add spy with the details you provided"
return len(friends)
# -----------------------FUNCTION TO START CHAT--------------------------
def start_chat(spy):
current_status_message = None
spy.name = spy.salutation + " " + spy.name
if spy.age > 12 and spy.age < 50:
if spy.rating > 4.5 and spy.rating <= 5.0:
print "Great Ace!!"
elif spy.rating > 3.5:
print "You are one of the Good Ones."
elif spy.rating >= 2.5:
print "You can always do Better!"
else:
print "We can always use somebody to help in the office."
print "Authentication complete. Welcome %s Age: %d and Rating of: %.2f \nProud to have you onboard" % (spy.name, spy.age, spy.rating)
show_menu = True
while (show_menu):
print "\n------MENU------\n\t1.STATUS UPDATE\n\t2.ADD FRIEND\n\t3.SEND A SECRET MESSAGE\n\t4.READ A SECRET MESSAGE\n\t5.READ CHATS FROM A USER\n\t6.CLOSE THE APPLICATION\n"
choice = input("ENTER YOUR CHOICE:")
if choice == 1:
current_status_message = add_status(current_status_message)
elif choice == 2:
print "WITHOUT FRIENDS CHATTING IS NOT THE CHATTING!!\n"
number_of_friends = add_friend()
print 'You have %d friends' % number_of_friends
elif choice == 3:
if not friends:
print "To use this Functionality you should have friends First!!!"
else:
send_message()
elif choice == 4:
if not friends:
print "To use this Functionality you should have friends First!!!"
else:
read_message()
elif choice == 5:
if not friends:
print "To use this Functionality you should have friends First!!!"
else:
read_from_user()
elif choice == 6:
show_menu = False
else:
print "Invalid Choice,TRY AGAIN!!"
else:
print "You are not of the correct age to be a SPY!!"
# _______________MAIN PROJECT STARTS HERE!___________________
print "Welcome!!to SPY CHAT"
print "Let's get Started!"
i = 5
repeat2 = True
while(repeat2):
pwd = raw_input("Enter Password to continue:")
with open('password.csv','rb') as password:
csvreader = csv.reader(password, delimiter=',')
for row in csvreader:
temp = row[0]
if pwd == temp:
# asking user about if he wants to conitue with the same name and age as previously logged in
repeat = True
while(repeat):
question = "Do you want to continue as %s %s(Y/N)? " % (spy.salutation, spy.name)
existing = raw_input(question)
if existing.upper() == 'Y':
load_friends()
load_chats()
start_chat(spy)
repeat = False
elif existing.upper() == 'N':
spy = Spy('', '', 0, 0.0)
spy.name = raw_input("Welcome! to SpyChat You must tell me your name first:")
# to check whether user enetered something or not
if len(spy.name) > 0:
spy.salutation = raw_input("What should we call you(Mr./Mrs./Miss)?")
spy.age = input("What's your Age:")
spy.rating = input("What is your Spy Rating:")
start_chat(spy)
else:
print("Sorry!! A Spy need to have a Valid Name.Try Again Please!!")
repeat = False
else:
print "*Type Either Y/y or N/n*"
else:
i = i-1
print colored('Wrong Password!','red')
print "Try again %d attempts left\n" %i
if i == 0:
print colored('Access Denied!','red')
print "Closing the Application..."
repeat2 = False