-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_diary.py
64 lines (56 loc) · 1.59 KB
/
my_diary.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
import sys
import time
import datetime
from sys import argv
script, filename = argv
while True:
print " "
print "We're going to edit %r." % filename
print '''If you don't want that,write "no" .'''
print "If you do want that, hit 'yes'."
print 'If you do want just read your %r write "read".' % filename
print 'If you do want find note from some day write "find"'
choice = raw_input()
target = open(filename,'r+')
reads = target.read()
target.close()
if choice == "no":
sys.exit()
elif choice == "find":
print'Now write this date like year(2020)-mounth(01)-day(01)'
note = raw_input()
result_date = reads.find(note)
inf = reads[result_date:-1]
end = inf.find("-"*19)
if result_date != -1 and end != -1:
inf_1 = inf[12:end]
print inf_1
elif result_date != -1 and end == -1:
print inf [12:-1]
elif result_date == -1:
print "No data"
elif choice == "read":
diary = open(filename,'r')
print diary.read()
diary.close()
elif choice == "yes":
target = open(filename,'w+')
print "You can write something in your diary"
print "Write:"
line = raw_input()
d_len = len(line)
print "I'm going to write these to the file."
if len(reads) == 0:
title = ("-"*10+'My Diary'+"-"*10 +"\n")
target.write(title)
target.write(reads)
named_time = time.localtime()
time_string = time.strftime("%H:%M", named_time)
date = str(datetime.date.today())
result = reads.find(date)
if result == -1:
if len(reads) != 0:
target.write("\n" + "-"*19 + "\n")
target.write(date +':'+"\n")
target.write("-"*10+time_string+"-"*10 +"\n"+line+"\n")
target.close()