-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (40 loc) · 1.3 KB
/
main.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
'''
Add your next birthday on the about me
section on your Discord profile.
'''
from datetime import datetime
try:
import pyperclip
except ImportError:
class pyperclip:
@staticmethod
def copy(text: str) -> None:
print('Add the following to your about me:' + '\n' + text)
raise ImportError("pyperclip not found")
def get_datetime_object_from_input() -> datetime:
'''Get a datetime object from user input.'''
print('Next birthday format: YYYY-MM-DD')
inp = input('> ')
try:
datetime_object = datetime.strptime(inp, '%Y-%m-%d')
except ValueError:
print('Invalid format')
return get_datetime_object_from_input()
else:
return datetime_object
def get_discord_formatting(datetime_object: datetime) -> str:
'''Get the discord formatting from a datetime object.'''
timestamp = int(datetime_object.timestamp())
return f'<t:{timestamp}:R>'
def main() -> None:
'''Main function.'''
datetime_object = get_datetime_object_from_input()
discord_formatting = get_discord_formatting(datetime_object)
try:
pyperclip.copy(f'**Birthday**: {discord_formatting}')
except ImportError:
pass
else:
print('It\'s been copied to your clipboard')
if __name__ == '__main__':
main()