Skip to content

Commit 7383b11

Browse files
Merge pull request prathimacode-hub#352 from AmitGupta700/main
Current Time Stamps
2 parents 32aa805 + be6ccc4 commit 7383b11

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed
15.2 KB
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## Description:
2+
- My project works on displaying Current Time Stamps
3+
- To create GUI Calendar Using Python, we will need to import two Python modules one for creating GUI and another to get year data.
4+
- **Pendulum**, Pendulum is one of the libraries in python which provides easily manages complex date manipulations better than native DateTime instances. It also manages timezones.
5+
- And for the speaking purpose, we will use **pyttsx3**.
6+
7+
## Procedure:
8+
```python
9+
import pendulum
10+
import pyttsx3
11+
```
12+
- First after importing modules.
13+
- After that we will make a function **speak()** in which we will set the rate of speaking and the type of voice.
14+
- Then we will take input from user for which year you want to display the calendar.
15+
- After that in code section we will first use **pendulum.now()** which will tell the current date and time of that zone.
16+
- After displaying it, a bot voice will ask you to enter a location which is evaluated in try and except block.
17+
18+
## Sample Output:
19+
![LGM](https://github.com/AmitGupta700/Awesome_Python_Scripts/blob/main/AutomationScripts/Current%20Time%20Stamps/Images/Output.png)
20+
21+
## For any query please contact:
22+
<a href="https://www.linkedin.com/in/amit-gupta-681206191/">LinkedIn</a>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#Code for time in different timezones
2+
3+
#importing modules
4+
import pendulum
5+
import pyttsx3 #for speaking purpose
6+
7+
#function for speaking
8+
def speak(text):
9+
engine = pyttsx3.init()
10+
engine.setProperty("rate", 170) #rate of speaking
11+
voices = engine.getProperty("voices")
12+
engine.setProperty("voice", voices[1].id) #for female voice
13+
engine.say(text)
14+
engine.runAndWait()
15+
16+
# Code
17+
18+
speak("Hello! I will convert time in desired timezones.")
19+
20+
#current details
21+
d1 = pendulum.now()
22+
23+
#splitting for getting date and time only
24+
dt1 = str(d1).split(".")
25+
26+
speak("Here's your current timezone with current date and time")
27+
print(f"Current timezone : {d1.timezone_name}") #for displaying timezone
28+
print(f"Current date and time: {dt1[0]}") #as we splited time and timezon
29+
30+
speak("Now enter the zone you wish to see the time!")
31+
i = input("Enter here: ")
32+
33+
#details for inputed timezone
34+
try:
35+
d2 = pendulum.now(i)
36+
dt2 = str(d2).split(".")
37+
speak("Here's desired details")
38+
print(f" Current date and time for {d2.timezone_name} : {dt2[0]}")
39+
except Exception as e:
40+
speak("Looks like you have entered incorrect timezone!")
41+
speak("Please check it and try again!")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import pendulum
2+
import pyttsx3

0 commit comments

Comments
 (0)