def send_message(): friend_choice = friends[select_a_friend()].name original_image = raw_input("What is the name of the image?") #output.jpg is a output image, with output name output_path = 'output.jpg' text = raw_input("What do you want to say?") # encoding the message Steganography.encode(original_image, output_path, text) # the message will be stored in chat new_chat = ChatMessage(spy_name=spy_1.name, friend_name=friend_choice, time=datetime.now().strftime("%d %B %Y"), message=text) #append new_chat in chats list. chats.append(new_chat) print("your secret message is ready.") with open('chats.csv', 'a') as chats_data: writer = csv.writer(chats_data) writer.writerow([ new_chat.spy_name, new_chat.friend_name, new_chat.time, new_chat.message ])
def read_chat_history(): read_for = select_a_friend() print '\n' for chat in friends[read_for].chats: if chat.sent_by_me: # The date and time is printed in blue print( colored( str(chat.time.strftime("%d %B %Y %A %H:%M")) + ",", 'blue')), # The message is printed in red print(colored("You said:", 'red')), # black is by default print str(chat.message) else: # The date and time is printed in blue print( colored( str(chat.time.strftime("%d %B %Y %A %H:%M")) + ",", 'blue')), # The message is printed in red print(colored(str(friends[read_for].name) + " said:", 'red')), # Black color is by default print str(chat.message)
def read_chat_history(): #read_for stores the value returned by select_a_friend() read_for = select_a_friend() print '\n' #iterating through friends chats list for chat in friends[read_for].chats: if chat.sent_by_me: #when True # The date and time is printed in blue print( colored( str(chat.time.strftime("%d %B %Y %A %H:%M")) + ",", 'blue')), # The message is printed in red print(colored("You said:", 'red')), # black is by default print str(chat.message) else: #when False # The date and time is printed in blue print( colored( str(chat.time.strftime("%d %B %Y %A %H:%M")) + ",", 'blue')), # The message is printed in red print(colored(str(friends[read_for].name) + " said:", 'red')), # Black color is by default print str(chat.message)
def read_message(): sender = select_a_friend() # Selecting Friend to read message while True: try: output_path = raw_input("What is the name of the file? : ") secret_text = Steganography.decode(output_path) print secret_text break except TypeError: print( colored( "Nothing to decode from the image as it contains no secret message.", 'red')) # Number of words spoken by spy words = secret_text.split() friends[sender].words += len(words) # Deleting friend who talk too much if len(words) > 100: friends.remove(friends[sender]) print "Your friend is removed for speaking too much" new_chat = ChatMessage(secret_text, False) friends[sender].chats.append(new_chat)
def read_message(): sender = select_a_friend() output_path = raw_input("What is the name of the file?") #decode secret text. secret_text = Steganography.decode(output_path) print(secret_text) words = secret_text.split() for i in words: if i == "SOS" or i == "sos" or i == "save" or i == "help" or i == "Emergency" or i == "danger": # Maintain the average number of words spoken by a spy every time a message is received from a particular spy. #friends[sender].count += len(words) # Emergency alert # Help your friend by sending him a helping message print(colored(i + ": IT'S EMMERGENCY!!", "red")) print ("Don't panic !!") print ("I am coming to rescue.\n\n") # add the chat to sender chat = ChatMessage(spy_name=spy_1.name, friend_name=sender, time=datetime.now().strftime("%d %B %Y"), message=secret_text) friends[sender].chats.append(chat) print("Your secret message has been saved.") # writing chats in chats.csv with open("chats.csv", 'a') as chat_record: writer = csv.writer(chat_record) writer.writerow([chat.spy_name, chat.friend_name, chat.time, chat.message])
def send_message_help(): # Select the friend who had sent the emergency message friend_choice = select_a_friend() # Send the helping message text to the friend in emergency text = "help yourself, i don't know you..!!!" # The message will be added in the chat new_chat = ChatMessage(text, True) # Add the message to the one who said. friends[friend_choice].chats.append(new_chat)
def send_message_help(): # Select the friend who had sent the emergency message friend_choice = select_a_friend() # Send the helping message text to the friend in emergency text = "I am coming to save you. Do not worry " # The message will be added in the chat new_chat = ChatMessage(text, True) # Add the message to the one who said. friends[friend_choice].chats.append(new_chat)
def read_chat(): read_for = select_a_friend() # Reading chat history of a friend for chat in friends[read_for].chats: if chat.sent_by_me: print( colored( str('[%s] %s %s' % (chat.time.strftime("%d %B %Y"), 'You said:', chat.message)), 'blue')) else: print '[%s] %s said: %s' % (chat.time.strftime("%d %B %Y"), friends[read_for].name, chat.message)
def send_message(): # Use of Steganography friend_choice = select_a_friend() original_image = raw_input("What is the name of the image? : ") pattern = '^[a-zA-Z]+\.jpg$' if re.match(pattern, original_image) != None: output_image = raw_input("Provide output image file name?") while True: text = raw_input("Enter your message here?") if len(text) > 0: Steganography.encode(original_image, output_image, text) break else: print "Invalid name. try .jpg images only." new_chats = ChatMessage(text, True) friends[friend_choice].chats.append(new_chats) print "Your message is ready"
def send_a_message(): # Select a friend to whom you want to communicate with friend_choice = select_a_friend() # Select the image in which you want to write a secret message original_image = raw_input("What is the name of the image?: ") # the output path of the image where the message is stored output_path = "output.jpg" # write the secret message text = raw_input("Enter your secret message: ") # The library steganography that helps to encode the message Steganography.encode(original_image, output_path, text) # The text message wil be stored in chat messages new_chat = ChatMessage(text, True) # Along with the name of the friend we add the message friends[friend_choice].chats.append(new_chat) # After the encoding is done the message is ready. print(colored("Your secret message image is ready!", "green"))
def send_a_message(): # Select a friend to whom you want to send and receive msgs with friend_choice = select_a_friend() # Select the image in which you want to write a secret message while True: original_image = raw_input("What is the name of the image?:- ") if len(original_image) >0: # the output path of the image where the message is stored while True: output_path = raw_input("Provide the name of the output image :- ") if len(output_path) > 0: #write the secret message while True: text = raw_input("Enter your secret message:- ") if len(text) > 0: # The library steganography that helps to encode the message Steganography.encode(original_image, output_path, text) # The text message wil be stored in chat messages new_chat = ChatMessage(text, True) # Along with the name of the friend we add the message friends[friend_choice].chats.append(new_chat) # After the encoding is done the message is ready. print(colored("Your secret message image is ready!", "cyan")) #returning back to menu choice return new_chat else: print(colored('Secret message cannot be blank!', 'red')) else: print(colored('Output image cannot be blank!', 'red')) else: print(colored('Input Image cannot be blank!','red'))
def start_chat(name, age, rating): current_status_messesge = None print("your current status is " + str(current_status_messesge)) #it is a function to loads all the friends stored in friends.csv def load_friends(): with open('friends.csv', 'rU') as friends_data: reader = csv.reader(friends_data) for row in reader: try: friends.append( Spy(name=row[0], salutation=row[1], age=row[2], rating=row[3])) except IndexError: pass continue # load_chats() is used for loads all the chats of spies stored in chats.csv def load_chats(): with open("chats.csv", 'rU') as chat_data: reader = csv.reader(chat_data) for row in reader: try: chats.append( ChatMessage(spy_name=row[0], friend_name=row[1], time=row[2], message=row[3])) except IndexError: pass continue #functions called, so the chats and list of friends are loaded before its usage load_friends() load_chats() continue_option = "Y" while (continue_option == 'Y' or continue_option == 'y'): menu_option = int( raw_input( "What would you like to do \n 1. Add a status update \n 2. Add a friend \n 3. Send a message \n 4. Read a secret message \n 5. Read chats from a user \n 6. Close the application" )) # displaying menu for user. while (menu_option <= 6): if menu_option == 1: print("You choose update the status ") current_status_messesge = str( status_message(current_status_messesge)) # calls the add_status_message from the add_status file print colored( "Your selected status is:" + current_status_messesge, "red") # Displays the status chosen or entered by the spy break elif menu_option == 2: print("Adding a friend.") # add a new friend number_of_friends = add_friend() print('You have %d friends' % number_of_friends ) # prints the number of friends break elif menu_option == 3: print("Sending a message.") send_message() break elif menu_option == 4: print("Read a secret message.") read_message() break elif menu_option == 5: print("Reading chat from user") print "select a friend whose chat you want to see" choice = select_a_friend() readchat(choice) break elif menu_option == 6: print("Exit.") exit() continue_option = raw_input( "Would you like to perform another operation (Y/N)") print("Thank you")
def read_a_message(): # Select a friend to communicate with sender = select_a_friend() output_path = raw_input("What is the name of the image file?: ") # Error handling if a secret message is present or not try: secret_text = Steganography.decode(output_path) print "The secret message you read is", print (colored(secret_text, 'red')) words = secret_text.split() # Convert all the words into uppercase new = (secret_text.upper()).split() # Maintain the average number of words spoken by a spy every time a message is received from a particular spy. friends[sender].count += len(words) # Emergency words are present if "SOS" in new or "SAVE" in new or "HELP" in new or "AID" in new or "ACCIDENT" in new or "RESCUE" in "ALERT" in new or "ALARM" in new or "CRISIS" in new: # Emergency alert print(colored("!", 'grey', 'on_yellow')), print(colored("!", 'grey', 'on_yellow')), print(colored("!", 'grey', 'on_yellow')) # Help your friend by sending him a helping message print (colored("The friend that sent this message needs an emergency.", 'green')) print (colored("PLease help your friend by sending a helping message.", 'green')) print (colored("Select that friend to send him a helping message.", 'red')) # Calling the send message help function send_message_help() # The message is sent successfully print(colored("You have sent a message to help your friend.", 'magenta')) # Adding the chat with the sender new_chat = ChatMessage(secret_text, False) friends[sender].chats.append(new_chat) # When there was no case of emergency else: # Adding the chat with the sender new_chat = ChatMessage(secret_text, False) friends[sender].chats.append(new_chat) print(colored("Your secret message has been saved!", 'yellow')) # Print the avg words spoken by your friend print "Average words said by", print(colored(friends[sender].name, "blue")), print "is", print(colored(friends[sender].count, "red")) # Delete a spy from your list of spies if they are speaking too much if len(words) > 100: print(colored(friends[sender].name, 'blue')), print(colored("removed from friends list.What a chatter box!.What a drag!!!", "yellow")) # Removes that chatterbox friend friends.remove(friends[sender]) # When the image contains no secret message # 'TypeError' handling except TypeError: print(colored("Nothing to decode from the image as it contains no secret message.", 'red'))