-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
204 lines (183 loc) · 7.91 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
#importing details from spy_details.py
from spy_details import Spy,spy, friends, chatmessage
#importing libraries
from steganography.steganography import Steganography
from datetime import datetime
from termcolor import colored, cprint
#a function for adding a friend
def add_friend():
new_friend = Spy('', '', 0, 0.0)
new_friend.name = raw_input("please add your friends name : ")
new_friend.salutation = raw_input("are they mr or miss : ")
new_friend.age = int(raw_input("age: "))
new_friend.rating = float(raw_input("rating: "))
if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating:
friends.append(new_friend)
else:
print("sorry! invalid entry. we can't add a spy with the details you provided. please try again later. ")
return len(friends)
#function for selecting a friend
def select_a_friend():
number = 0
for friend in friends:
print('%s aged %d with rating %.2f is online') % (friend.name, int(friend.age), float(friend.rating))
number = number + 1
select_friend = raw_input("choose from your friendlist. ")
select_friend_postion = int(select_friend) - 1
if select_friend_postion > number:
print("invalid index entered")
start_chat(spy.name,spy.age,spy.rating)
else:
return select_friend_postion
#function for sending a message
def send_a_message():
select_friend = select_a_friend()
original_image = raw_input("what is the name ofthe image")
output_path = original_image
text = raw_input("what message do u want to send ? ")
if len(text) <= 0:
print("u cannot send empty message!!!!")
elif len(text) > 100:
print("you exceed the message limit .. please try again later!!!!")
del friends[select_friend]
else:
Steganography.encode(original_image, output_path, text)
chats = chatmessage(text, True)
friends[select_friend].chat.append(chats)
print("your secret message is ready.")
#function for reading a message
def read_a_message():
sender = select_a_friend()
output_path = raw_input("what is the name of the image.")
secret_text = Steganography.decode(output_path)
chat = chatmessage(secret_text, False)
friends[sender].chat.append(chat)
if secret_text.upper() == "SOS" or secret_text.upper() == "SAVE ME" or secret_text.upper() == "HELP":
print("you will receive help soon...")
print("your secret message is saved.")
#function for reading chat
def read_chat():
read_for = select_a_friend()
for chats in friends[read_for].chat:
if chats.sent_by_me:
text1 = colored(chats.time.strftime("%a, %d %b %Y %H:%M:%S +0000"), 'blue', attrs=['reverse', 'blink'])
print(text1)
print colored(' you said : ', 'green', 'on_red'), chats.message
else:
text1 = colored(chats.time.strftime("%a, %d %b %Y %H:%M:%S +0000"), 'blue', attrs=['reverse', 'blink'])
print(text1)
print colored(friends[read_for].name, 'green', 'on_red'), chats.message
#program starts
print("welcome to spy chat application.")
question = "continue as " + spy.salutation + " " + spy.name + "(Y/N)?"
existing = raw_input(question)
status_messages = ['busy', 'stirred', 'despacito']
#function for adding status
def add_status_message(current_status_message):
if current_status_message != None:
print("your current status message is : ") + current_status_message + '\n'
else:
print("you don't have any status message currently \n")
default = raw_input("do you want to select from your older status (Y/N)?")
if default.upper() == "N":
new_status_message = raw_input("what status you want to set?")
if len(new_status_message) > 0:
update_status_message = new_status_message
status_messages.append(update_status_message)
elif default.upper() == "Y":
item_position = 1
for message in status_messages:
print(str(item_position) + "." + message)
item_position = int(item_position) + 1
message_selection = raw_input("choose from above messages : ")
message_selection = int(message_selection)
if len(status_messages) >= message_selection:
updated_message = status_messages[message_selection - 1]
return updated_message
#function to start chat
def start_chat(spy_name, spy_age, spy_rating):
current_status_message = None
show_menu = True
while show_menu:
menu_choices = "what do u want to do \n1. add a status \n2. add a friend \n3. send a message \n4. read the secret message \n5.chat history \n6. close application "
menu_choice = raw_input(menu_choices)
if len(menu_choice) > 0:
menu_choice = int(menu_choice)
if menu_choice == 1:
print("you choose to update status.")
current_status_message = add_status_message(current_status_message)
elif menu_choice == 2:
print("you choose to add a friend. please provide us your friends details. ")
number_of_friends = add_friend()
print 'You have %d friends' % (number_of_friends)
elif menu_choice == 3:
print("you choose to send a message.")
send_a_message()
elif menu_choice == 4:
print("you choose to read a message. ")
read_a_message()
elif menu_choice == 5:
read_chat()
elif menu_choice == 6:
show_menu = False
exit(0)
else:
print("you choose an invalid entry. please try again later.")
else:
print("please choose an option.")
#some functions for asking spy details
def ask_name():
spy_name = raw_input("please enter your name: ")
if len(spy_name) == 0:
while len(spy_name) == 0:
print("error! please enter your name.")
spy_name = raw_input("please enter your name")
return spy_name
else:
return spy_name
def ask_salutation(name):
fullname = None
result = True
while result:
spy_salutation = raw_input("should i call you miss or mr. : ")
if len(spy_salutation) > 0 and spy_salutation.upper() == "MR" or spy_salutation.upper() == "MISS":
fullname = spy_salutation + " " + name
result = False
else:
print("invalid details .. try again later")
return fullname
def ask_age():
spy_age = raw_input("what is your age :")
if len(spy_age) == 0:
print("please enter your age")
spy_age = raw_input("what is your age :")
elif int(spy_age) < 12 or int(spy_age) > 50:
print("your age is not valid to become a spy.")
exit(0)
else:
return int(spy_age)
def ask_rating():
spy_rating = float(raw_input("you are rated as : "))
if spy_rating > 4.0:
return "%.1f you are one of the best spy." % (spy_rating)
elif spy_rating <= 4.0 and spy_rating >= 3.0:
return "%.1f you are one of the good ones." % (spy_rating)
elif spy_rating <= 2.0 and spy_rating > 3.0:
return "%.1f you can always work hard." % (spy_rating)
else:
return "%.1f we can always need someone in office." % (spy_rating)
#for display user details
def display(name, age, rating):
return ("Welcome %s. Your age is %s. And You are rated as : %s ") % (name, str(age), str(rating))
#checking if user wants to continue with default user or not
if (existing.upper() == "Y"):
print("authentication complete. welcome %s %s .") % (spy.salutation, spy.name)
start_chat(spy.name, spy.age, spy.rating)
else:
def start():
ask_salutation(ask_name())
ask_age()
ask_rating()
output = display(ask_salutation(ask_name()), ask_age(), ask_rating())
print(output)
start_chat(spy.name, spy.age, spy.rating)