Coverage for sample_project/templatetags/sample_project.py: 47%

17 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-16 07:42 +0000

1import pathlib 

2from datetime import UTC, date, datetime, time, timedelta 

3 

4from django import template 

5 

6register = template.Library() 

7 

8 

9@register.simple_tag 

10def password(): 

11 passwordfile = pathlib.Path("/tmp/password.txt") 

12 if passwordfile.exists(): 

13 return passwordfile.read_text() 

14 return None 

15 

16 

17@register.simple_tag 

18def teardown(): 

19 init_date = datetime.combine(date.today(), time(0, 30, 0), tzinfo=UTC) 

20 # create timetsamps for today 

21 timestamps = [ 

22 init_date, 

23 init_date.replace(hour=6), 

24 init_date.replace(hour=12), 

25 init_date.replace(hour=18), 

26 ] 

27 # create timestamps for tomorrow 

28 timestamps += list(map(lambda x: x + timedelta(hours=24), timestamps)) 

29 # filter timestamps that are after now 

30 timestamps = list(filter(lambda x: x > datetime.now(UTC), timestamps)) 

31 return timestamps[0]