util.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 import datetime
5 import os
6 
7 
8 def filename_with_timestamp(filename, sep=None):
9  """Return filename with timestamp.
10 
11  @param filename: file path.
12  @type filename: str
13  @param spam: separator between timestamp and original filename.
14  @type spam: str
15 
16  >>> filname_with_timestamp("./spam/ham.txt")
17  ./spam/2015-11-14-17-42-00_ham.txt
18  """
19  head, tail = os.path.split(filename)
20  now = datetime.datetime.now()
21  if sep is None:
22  sep = '_'
23  format = '%Y-%m-%d-%H-%M-%S' # length = 19
24  try:
25  datetime.datetime.strptime(tail[:19], format)
26  return os.path.join(head, tail)
27  except ValueError:
28  return os.path.join(head, sep.join([now.strftime(format), tail]))
29 
30 
31 def google_drive_file_url(id, download=False):
32  cmd = 'uc' if download else 'open'
33  url = 'https://drive.google.com/{0}?id={1}'.format(cmd, id)
34  return url
def filename_with_timestamp(filename, sep=None)
Definition: util.py:8
def google_drive_file_url(id, download=False)
Definition: util.py:31


jsk_data
Author(s):
autogenerated on Tue Feb 6 2018 03:45:36