Untitled
unknown
plain_text
2 years ago
3.7 kB
5
Indexable
from datetime import datetime
#Twit message
def twit_msg():
twit=input('Please enter your twit :')
today = datetime.now().strftime('%d-%m-%Y %H:%M:%S')
print(f'{name} , your twit is published')
file1 = open("twitter.txt", "a")
file1.writelines(today + '|' + name + '|' + twit)
file1.write('\n')
file1.close()
while True:
repeat=input('Do you want to twit again ? (Y/N) :')
if repeat=='Y':
twit1 = input('Please enter your twit :')
file1 = open("twitter.txt", "a") # append mode
file1.write(today + '|' + name + '|' + twit1)
file1.write('\n')
file1.close()
print(f'{name} , your twit is published')
else:
break
def find_mytwit():
with open(r'twitter.txt', 'r') as fp:
# read all lines in a list
lines = fp.readlines()
count = 0
for line in lines:
#fp.seek(20)
# check if string present on a current line
if line.find(name) != -1:
count += 1
print(count, line)
print('There are', count, 'twit found for', name)
#Find All twit
def find_alltwit():
count=0
twit_file = open('twitter.txt', 'r')
twit_list = twit_file.readlines()
for line in twit_list:
count += 1
print(line)
print(name,'There are total', count, 'twit found')
#Find the twit for particular date
def find_alltwit_date():
date = input('Please enter the date :')
with open(r'twitter.txt', 'r') as fp:
# read all lines in a list
lines = fp.readlines()
count = 0
for line in lines:
# check if string present on a current line
if line.find(date) != -1:
count += 1
print(count, line)
print('There are', count, 'twit found for', date)
def modify_twit():
search_text = input('Please enter the name to modify :')
replace_text = input('Please enter the name to replace :')
if search_text==1:
with open(r'twitter.txt', 'r') as file:
data = file.read()
data = data.replace(search_text, replace_text)
with open(r'twitter.txt', 'w') as file:
file.write(data)
print("Twit has modify successfully")
else:
print('Twit not found to modify')
def delete_twit():
delete_twit = input('Please enter your name to delete the Twit :')
with open("twitter.txt", "r+") as f:
new_f = f.readlines()
f.seek(0)
for line in new_f:
if delete_twit not in line:
f.write(line)
f.truncate()
print(delete_twit,' Your Twit deleted successfully....')
print('Welcome to Twitter App:The App to share your thoughts!')
print('1]Twit messages\n2]Find my twits\n3]Find all twits\n4]Find twits for particular date\n5]Modify the twit for particulr user\n6]Delete particulr twit from twitter')
name=input('Please enter your name :')
while True:
select_option = input('Please select the option or press 7 to exit:')
if select_option == '1':
twit_msg()
print('Thank you for using Twitter,Have a great day!')
elif select_option == '2':
find_mytwit()
elif select_option == '3':
find_alltwit()
elif select_option == '4':
find_alltwit_date()
elif select_option == '5':
modify_twit()
elif select_option == '6':
delete_twit()
else:
print('Good day...')
break
Editor is loading...