-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil.py
39 lines (24 loc) · 885 Bytes
/
util.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
import logging
import os
from datetime import datetime
logging.basicConfig(format='%(asctime)s %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
logger.setLevel(level=logging.INFO)
def current_time():
return datetime.now().astimezone().strftime('%Y-%m-%d %H:%M:%S %z')
def current_date():
return datetime.now().astimezone().strftime('%Y-%m-%d')
def current_date_year():
return datetime.now().astimezone().strftime('%Y')
def current_date_month():
return datetime.now().astimezone().strftime('%m')
def current_date_day():
return datetime.now().astimezone().strftime('%d')
def ensure_dir(file):
directory = os.path.abspath(os.path.dirname(file))
if not os.path.exists(directory):
os.makedirs(directory)
def write_text(file: str, text: str):
ensure_dir(file)
with open(file, mode='w') as f:
f.write(text)