File size: 799 Bytes
6e54bce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys

from datetime import datetime
import logging

from settings import LOG_LEVEL, LOG_DATE_FORMAT, LOG_FORMAT, DATE_FORMAT, TIMESTAMP_FILE

log = logging.getLogger(__name__)
logging.basicConfig(stream=sys.stdout, level=LOG_LEVEL, format=LOG_FORMAT, datefmt=LOG_DATE_FORMAT)


def elapsed_time(start):
    return datetime.now() - start


def timestamp_now():
    return datetime.now().strftime(DATE_FORMAT)


def write_timestamp(timestamp=None):
    if not timestamp:
        timestamp = timestamp_now()
    with open(file=TIMESTAMP_FILE, mode='w') as f:
        f.write(timestamp)
    log.info(f"New timestamp written: {timestamp}")
    return timestamp


def read_timestamp():
    with open(file=TIMESTAMP_FILE, mode='r') as f:
        timestamp = f.read()
    return timestamp.strip('\n')