-
Notifications
You must be signed in to change notification settings - Fork 14
/
util.py
38 lines (25 loc) · 843 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
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.DEBUG)
def strip_embracing_quotes(text: str):
if text.startswith('"') and text.endswith('"'):
return text[1:-1]
return text
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 ensure_dir(file: str):
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, 'w') as f:
f.write(text)
if __name__ == "__main__":
logger.info('hello world')