Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/local/bin/python 

2# encoding: utf-8 

3""" 

4*Append a datetime stamp to the end of a filename to ensure uniqueness* 

5 

6:Author: 

7 David Young 

8""" 

9from builtins import str 

10import sys 

11import os 

12os.environ['TERM'] = 'vt100' 

13from fundamentals import tools 

14 

15 

16def append_now_datestamp_to_filename(log, filename, longTime=False): 

17 """ 

18 *append the current datestamp to the end of the filename (before the extension).* 

19 

20 **Key Arguments** 

21 

22 - ``log`` -- logger 

23 - ``filename`` -- the filename 

24 - ``longTime`` -- use a longer time-stmap. Default *False* 

25 

26 Return: 

27 - ``dsFilename`` -- datestamped filename 

28 

29 **Usage** 

30 

31 ```python 

32 # APPEND TIMESTAMP TO THE FILENAME 

33 from fundamentals.download import append_now_datestamp_to_filename 

34 filename = append_now_datestamp_to_filename( 

35 log=log, 

36 filename="some_filename.html", 

37 longTime=True 

38 ) 

39 

40 # OUTPUT 

41 # 'some_filename_20160316t154123749472.html' 

42 ``` 

43 """ 

44 from fundamentals.download import get_now_datetime_filestamp 

45 

46 try: 

47 #log.debug("appending date stamp to the filename : "+filename) 

48 sliced = filename.split('.') 

49 dsFilename = sliced[0] + '_' + \ 

50 get_now_datetime_filestamp(longTime=longTime) 

51 if len(sliced) == 2: 

52 dsFilename += '.' + sliced[1] 

53 else: 

54 dsFilename += ".xhtml" 

55 except Exception as e: 

56 log.error("could not append date stamp to the filename : " + 

57 filename + " : " + str(e) + "\n") 

58 

59 return dsFilename