1
00:00:00,880 --> 00:00:02,980
Welcome to today's bonus example.

2
00:00:02,980 --> 00:00:07,990
We're going to create a daily journal app which behaves like this.

3
00:00:07,990 --> 00:00:10,600
So let me demonstrate you the output of the program.

4
00:00:12,520 --> 00:00:15,820
The program first asks the user to enter today's date.

5
00:00:15,820 --> 00:00:21,070
So let's enter 2022 and ten, maybe 20.

6
00:00:22,900 --> 00:00:29,890
You press enter the program, asks you again to rate your moods the mood you had today from 1 to 10.

7
00:00:31,240 --> 00:00:36,100
Let's answer eight, for example, and then you write the thoughts of the day.

8
00:00:38,630 --> 00:00:41,790
So let's write something like it was a good day in general.

9
00:00:41,810 --> 00:00:43,050
No big events happened.

10
00:00:43,070 --> 00:00:44,000
Press enter.

11
00:00:44,630 --> 00:00:45,320
That's it.

12
00:00:45,350 --> 00:00:51,950
Now, if you go to the Journal Directory, which I had created earlier, so you need to create this

13
00:00:51,950 --> 00:00:53,120
directory manually.

14
00:00:53,360 --> 00:00:57,440
And then inside this, a file was generated by Python.

15
00:00:57,590 --> 00:01:00,140
So that's the contents of our.

16
00:01:01,220 --> 00:01:02,140
Program.

17
00:01:02,720 --> 00:01:08,600
So every new day that you execute the program, it will create a new file.

18
00:01:09,800 --> 00:01:17,990
So ten days, ten files, and each file is going to contain the date of the day as a file name.

19
00:01:19,210 --> 00:01:20,600
Yeah, let's write the program.

20
00:01:22,130 --> 00:01:25,230
So, first of all, we want to ask the user to enter today's date.

21
00:01:25,250 --> 00:01:29,090
So we need an input function for that with the string.

22
00:01:32,200 --> 00:01:35,620
Next, we ask the user to rate their mood.

23
00:01:35,620 --> 00:01:37,630
So another input function.

24
00:01:38,380 --> 00:01:41,110
So we've got two variables data and mood.

25
00:01:48,770 --> 00:01:53,480
Then we ask the user again to just write down their thoughts.

26
00:01:53,480 --> 00:01:55,640
So yet another input function.

27
00:01:56,450 --> 00:02:01,850
I'm writing here, I'm having a backslash and to create a break line.

28
00:02:01,850 --> 00:02:09,380
You saw that when I entered the inputs here as a user, the input was written in the next line.

29
00:02:09,380 --> 00:02:12,830
So a break line was created by this backslash.

30
00:02:12,830 --> 00:02:19,310
N By the way, this output was executed from.

31
00:02:20,250 --> 00:02:24,480
A script which is somewhere here, but I don't want to show the script to you in the beginning.

32
00:02:25,380 --> 00:02:27,990
So now we want to recreate that program again.

33
00:02:29,250 --> 00:02:36,720
Once we get the inputs, then we want to create a file using that as a name for the file.

34
00:02:36,750 --> 00:02:40,110
So let's write with open.

35
00:02:42,180 --> 00:02:43,020
Date.

36
00:02:43,650 --> 00:02:47,940
So the file, the actual file path would be something like

37
00:02:51,030 --> 00:02:52,800
dot, dot, slash.

38
00:02:54,180 --> 00:02:54,940
Journal.

39
00:02:55,230 --> 00:02:57,360
Slash and then the date

40
00:03:00,420 --> 00:03:05,010
and close and curly quotes and this would be an F string.

41
00:03:05,010 --> 00:03:08,760
So let me close the string here and make it an F string.

42
00:03:09,180 --> 00:03:17,310
And these two dots, as you know, are when my python file is inside an inner directory.

43
00:03:17,310 --> 00:03:19,200
In my case, it's inside bonus.

44
00:03:19,200 --> 00:03:26,430
So bonus and journal are in the same directory, so the file has to go up one level with these dots

45
00:03:26,430 --> 00:03:31,710
and then points to journal and then date dot text.

46
00:03:33,480 --> 00:03:38,220
So this file will be created in right mode.

47
00:03:41,470 --> 00:03:44,380
And in the next line, which is indented.

48
00:03:46,060 --> 00:03:46,760
We say, fine.

49
00:03:46,780 --> 00:03:47,800
That's right.

50
00:03:48,880 --> 00:03:50,800
What do we write here?

51
00:03:52,240 --> 00:03:57,280
So the content would have the rates on top.

52
00:03:57,580 --> 00:04:01,330
So that means this would be the mood.

53
00:04:05,170 --> 00:04:08,340
Then we don't close the file we write.

54
00:04:10,350 --> 00:04:12,690
The journal in the file.

55
00:04:13,610 --> 00:04:15,740
All the text or whatever you call it.

56
00:04:16,160 --> 00:04:18,200
So the thoughts of the user.

57
00:04:19,899 --> 00:04:24,790
Let's rename it to false actually does make more sense.

58
00:04:28,130 --> 00:04:36,200
And yeah, I'll run the script now, so make sure that a journal directory exists and it reflects that.

59
00:04:37,110 --> 00:04:37,820
Path there.

60
00:04:37,950 --> 00:04:38,550
Journal.

61
00:04:38,550 --> 00:04:39,420
Journal.

62
00:04:39,450 --> 00:04:43,680
I'll delete the existing file and run the script.

63
00:04:45,330 --> 00:04:49,740
Today's date 2022 2010.

64
00:04:49,860 --> 00:04:50,610
Enter.

65
00:04:50,910 --> 00:04:51,740
How do you rate?

66
00:04:51,750 --> 00:04:52,920
Let's try seven.

67
00:04:55,050 --> 00:04:57,330
Nice day in general.

68
00:04:59,190 --> 00:05:00,300
It was fun.

69
00:05:00,690 --> 00:05:01,680
Press enter.

70
00:05:04,000 --> 00:05:05,920
And let's check journal.

71
00:05:06,430 --> 00:05:08,440
So that's the outputs.

72
00:05:08,710 --> 00:05:09,880
We're close.

73
00:05:09,910 --> 00:05:14,890
Seven is the rate and is not so well formatted.

74
00:05:14,890 --> 00:05:20,020
So we want to have like one two break lines between these two.

75
00:05:20,320 --> 00:05:26,710
So in that case, we want to go back to the Python file.

76
00:05:28,110 --> 00:05:33,990
And after Moody's, which is seven, seven, is a string.

77
00:05:34,350 --> 00:05:37,260
So it comes as a string from the input function.

78
00:05:38,430 --> 00:05:44,010
So basically, mood is a string.

79
00:05:44,190 --> 00:05:47,760
And if you do mood.

80
00:05:51,680 --> 00:05:54,110
Plus backslash.

81
00:05:54,110 --> 00:06:04,550
GN You get seven backslash N But this is the output in the command line, so if you use a print function.

82
00:06:07,080 --> 00:06:09,810
Backslash, and it's printed out as an actual brake line.

83
00:06:10,560 --> 00:06:16,560
So now we have a brick line here when you just call the expression like that, without printing in the

84
00:06:16,560 --> 00:06:20,820
python console, you always get the row, the row string like that.

85
00:06:23,950 --> 00:06:29,550
So we can use that expression or we can also do two times that.

86
00:06:29,560 --> 00:06:40,570
So we have to break lines one, two, so let's say plus two times backslash ends.

87
00:06:40,960 --> 00:06:46,210
So that is the equivalent of if you set plus backslash n.

88
00:06:48,450 --> 00:06:49,920
Plus another backslash.

89
00:06:49,920 --> 00:06:56,520
N And so you get the same behavior you see here and there.

90
00:06:56,520 --> 00:07:07,350
We have these break lines so that we can try the code again, this time with another date going to 21.

91
00:07:08,630 --> 00:07:10,510
Ten Press enter.

92
00:07:10,610 --> 00:07:11,880
How do you rate?

93
00:07:12,120 --> 00:07:13,790
Try nine this time.

94
00:07:15,800 --> 00:07:17,390
Great day.

95
00:07:17,720 --> 00:07:19,560
Press Enter Process Finished.

96
00:07:19,580 --> 00:07:21,980
A new file was generated as you see here.

97
00:07:23,270 --> 00:07:26,090
And there's the content as we expected.

98
00:07:27,980 --> 00:07:29,750
And that's our final code.

99
00:07:31,630 --> 00:07:40,240
So the key point to take here is that the with contacts manager keeps the file open and anything that

100
00:07:40,240 --> 00:07:48,160
is indented here is working on the open file so you can write and write and write text over over again.

101
00:07:48,280 --> 00:07:52,360
Everything will be appended to appended to the text file.

102
00:07:53,390 --> 00:07:54,640
So thanks for following this.

103
00:07:54,650 --> 00:07:55,520
I'll talk to you later.

