1
00:00:00,349 --> 00:00:03,589
Let's continue working with the standard modules.

2
00:00:03,599 --> 00:00:04,820
And the next one is going to be very,

3
00:00:04,829 --> 00:00:09,510
very important because not only is it a very useful module,

4
00:00:09,649 --> 00:00:13,149
but it's also relevant to the world of cybersecurity.

5
00:00:13,319 --> 00:00:16,930
And I'm talking about the date time module.

6
00:00:17,110 --> 00:00:21,069
This is a, this is a module that you can use to display things like your time,

7
00:00:21,079 --> 00:00:22,159
the current date,

8
00:00:22,299 --> 00:00:25,170
you can manipulate date and so on. So

9
00:00:25,479 --> 00:00:26,579
let me show you how to work with it.

10
00:00:26,590 --> 00:00:31,819
I'm going to remove all of this and simply say import and then date time.

11
00:00:32,500 --> 00:00:33,000
OK?

12
00:00:33,659 --> 00:00:39,200
Now let's assume we wanted to log the current date and time

13
00:00:39,560 --> 00:00:40,880
gonna come down in here

14
00:00:41,279 --> 00:00:43,509
and I'm gonna say current

15
00:00:43,810 --> 00:00:46,580
underscore time equals.

16
00:00:46,759 --> 00:00:47,299
OK?

17
00:00:47,650 --> 00:00:51,799
And now we'll have to call the module which is date time

18
00:00:52,840 --> 00:00:55,939
dot And now the method

19
00:00:56,209 --> 00:01:00,049
which will be used to actually display the current date and time.

20
00:01:00,400 --> 00:01:04,980
And it's also called date time dot Now,

21
00:01:05,559 --> 00:01:08,459
it's kind of interesting that in the module, date time,

22
00:01:08,510 --> 00:01:13,500
you do have a function called datetime dot Now, that is actually used.

23
00:01:13,510 --> 00:01:16,660
So all I have to do from this point right now is to simply say print

24
00:01:17,110 --> 00:01:18,459
and then in brackets,

25
00:01:18,989 --> 00:01:25,050
I can say the current date and time is space and then

26
00:01:25,730 --> 00:01:29,470
you can add my, uh, my comma right here

27
00:01:29,690 --> 00:01:31,379
and there's just a current

28
00:01:31,860 --> 00:01:33,029
underscore

29
00:01:33,319 --> 00:01:34,069
time.

30
00:01:35,440 --> 00:01:38,819
And let's see, I'm going to run the program and there you go.

31
00:01:38,980 --> 00:01:42,349
The current date and time is 27th of October 2024.

32
00:01:42,360 --> 00:01:46,839
And that is the time right there, as you can see.

33
00:01:47,190 --> 00:01:48,339
However,

34
00:01:48,879 --> 00:01:51,250
I want to introduce you to something else.

35
00:01:51,260 --> 00:01:54,839
See, given the fact that over here we have datetime

36
00:01:54,949 --> 00:01:57,819
and then the day time again,

37
00:01:58,860 --> 00:02:02,269
it's kind of redundant, right? Like, I mean, the code still works perfectly fine.

38
00:02:02,279 --> 00:02:03,940
Don't get me wrong. The code does work.

39
00:02:04,169 --> 00:02:07,239
But if you want to be very professional about this,

40
00:02:07,470 --> 00:02:09,389
one thing we could do is

41
00:02:09,600 --> 00:02:11,199
we could say that you know what

42
00:02:11,429 --> 00:02:19,600
from the datetime module, let's import specifically the date time method.

43
00:02:19,830 --> 00:02:23,000
So what I'm gonna do right now is over here,

44
00:02:23,289 --> 00:02:25,270
I'm going to say from

45
00:02:25,410 --> 00:02:27,070
datetime,

46
00:02:27,279 --> 00:02:29,429
import datetime.

47
00:02:29,820 --> 00:02:35,419
And now the beauty is that over here, we no longer have to say day time,

48
00:02:35,559 --> 00:02:37,350
but you can just remove all of this

49
00:02:37,809 --> 00:02:40,710
and just simply say day time dot Now

50
00:02:40,960 --> 00:02:42,309
because right now we've told Pyt

51
00:02:42,520 --> 00:02:45,490
that hey, from the module called day time,

52
00:02:45,600 --> 00:02:48,570
I want you to import specifically

53
00:02:48,759 --> 00:02:52,830
the class or the method called date time.

54
00:02:53,630 --> 00:02:55,330
And now if I run the program again,

55
00:02:55,460 --> 00:02:56,289
you can see

56
00:02:56,520 --> 00:02:58,809
it still works perfectly fine.

57
00:02:58,990 --> 00:03:01,199
It's just that this is a little bit more professional

58
00:03:01,289 --> 00:03:03,690
and a much better way of writing your code.

59
00:03:03,699 --> 00:03:04,160
Now,

60
00:03:04,169 --> 00:03:06,919
I want us to take this program a step further and

61
00:03:06,929 --> 00:03:12,410
actually combine the day time module with the random module.

62
00:03:12,860 --> 00:03:19,490
So we're basically going to generate random activities like uh login logout file,

63
00:03:19,520 --> 00:03:24,520
upload uh password change, you know, things that a user might do on a

64
00:03:24,800 --> 00:03:27,979
system, we're gonna generate them randomly and also

65
00:03:28,110 --> 00:03:31,300
generate them with some time stamps. OK? So

66
00:03:31,779 --> 00:03:33,500
I'm gonna go back in here

67
00:03:34,220 --> 00:03:38,960
and just after the daytime module, we're going to now import random.

68
00:03:39,710 --> 00:03:40,309
OK?

69
00:03:40,639 --> 00:03:46,210
Now let us indicate the different types of actions that we're going to randomize.

70
00:03:46,389 --> 00:03:48,570
So I'm going to say actions

71
00:03:49,100 --> 00:03:52,089
equals and now we can create our list

72
00:03:52,369 --> 00:03:56,529
and let's add a variety of them. Ok? Let's first of all, go with like login

73
00:03:57,020 --> 00:04:01,639
comma, let's go with log out as well. Ok?

74
00:04:01,649 --> 00:04:06,559
We have some suggestions in here like register reset password

75
00:04:07,149 --> 00:04:07,940
and

76
00:04:08,130 --> 00:04:10,250
I think I like this four,

77
00:04:10,520 --> 00:04:11,440
I think four is enough.

78
00:04:11,500 --> 00:04:15,570
So different actions like login logout, register reset password. So

79
00:04:15,690 --> 00:04:19,290
we're going to randomize these actions.

80
00:04:19,548 --> 00:04:20,570
Let me just add

81
00:04:21,238 --> 00:04:24,559
an underscore between reset and password whenever

82
00:04:24,570 --> 00:04:28,200
your strings have more than one word.

83
00:04:28,209 --> 00:04:30,440
If it's like two words, always use an on

84
00:04:30,570 --> 00:04:34,160
call to join them together, it's a much better way of writing out your strings.

85
00:04:34,350 --> 00:04:34,820
So

86
00:04:35,089 --> 00:04:37,220
what I'm gonna do right now is

87
00:04:37,390 --> 00:04:42,459
over here, I'm gonna keep the current time equals to datetime dot Now However,

88
00:04:42,470 --> 00:04:47,489
we also need to create a variable that will hold the randomized action.

89
00:04:47,500 --> 00:04:47,859
So

90
00:04:48,119 --> 00:04:52,100
I'm gonna come over here right now and say user underscore action

91
00:04:52,500 --> 00:04:56,859
equals and our random dot choice

92
00:04:57,269 --> 00:04:58,470
and then in brackets

93
00:04:58,779 --> 00:05:00,299
the actions

94
00:05:01,220 --> 00:05:03,519
and there you go. And all we have to do right now

95
00:05:03,899 --> 00:05:05,119
is just to print

96
00:05:06,160 --> 00:05:07,420
that the user performs

97
00:05:08,019 --> 00:05:09,899
action at a particular time.

98
00:05:10,200 --> 00:05:14,220
So we can do this. I'm gonna say print and now the F string

99
00:05:14,839 --> 00:05:18,660
and I will say the user

100
00:05:20,000 --> 00:05:21,540
uh performed.

101
00:05:23,500 --> 00:05:27,399
And now our color race is to represent the action so that we use the

102
00:05:27,589 --> 00:05:29,480
underscore action.

103
00:05:30,130 --> 00:05:34,609
And now I can say add and then the curly braces

104
00:05:34,880 --> 00:05:38,140
current underscore time,

105
00:05:40,269 --> 00:05:43,480
add the closing codes, close the brackets

106
00:05:44,059 --> 00:05:47,049
and that should be it. So

107
00:05:47,350 --> 00:05:51,630
let's go ahead right now and run the program and there you go,

108
00:05:51,920 --> 00:05:54,029
the user performed, register at so and

109
00:05:54,769 --> 00:05:56,209
so let's run it again.

110
00:05:56,329 --> 00:06:00,049
Performed, login this time around. OK? Perform reset password

111
00:06:00,359 --> 00:06:04,140
as you can see. So it is working. Now.

112
00:06:04,260 --> 00:06:08,260
What if, what if just like in the previous lesson, if we wanted to

113
00:06:08,540 --> 00:06:13,540
have more than one action being performed by the user? What are you going to do?

114
00:06:13,630 --> 00:06:18,230
Very simply, we're gonna come down here, change choice to choices.

115
00:06:18,380 --> 00:06:19,739
And then remember,

116
00:06:19,940 --> 00:06:24,260
we'll have to indicate how many actions we want to randomize.

117
00:06:24,269 --> 00:06:26,220
I'm gonna say K equals two.

118
00:06:26,700 --> 00:06:29,720
And now over here, I can say the user performed.

119
00:06:29,730 --> 00:06:31,839
Let's just keep the print text as it is,

120
00:06:31,970 --> 00:06:33,359
let's run the program again.

121
00:06:33,589 --> 00:06:35,420
And now you can see it says user perform

122
00:06:35,609 --> 00:06:37,029
password log in at this,

123
00:06:37,309 --> 00:06:40,959
run it again and now it's log in and now log out. So

124
00:06:41,290 --> 00:06:45,359
that's how you can work with the day time module

125
00:06:45,600 --> 00:06:48,019
in accordance with the random module to

126
00:06:48,029 --> 00:06:52,040
just generate random actions at different times.

127
00:06:52,049 --> 00:06:54,519
Thank you for watching the video. I will see you in the next class.

