util.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 import datetime
00005 import os
00006 
00007 
00008 def filename_with_timestamp(filename, sep=None):
00009     """Return filename with timestamp.
00010 
00011     @param filename: file path.
00012     @type filename: str
00013     @param spam: separator between timestamp and original filename.
00014     @type spam: str
00015 
00016         >>> filname_with_timestamp("./spam/ham.txt")
00017         ./spam/2015-11-14-17-42-00_ham.txt
00018     """
00019     head, tail = os.path.split(filename)
00020     now = datetime.datetime.now()
00021     if sep is None:
00022         sep = '_'
00023     format = '%Y-%m-%d-%H-%M-%S'  # length = 19
00024     try:
00025         datetime.datetime.strptime(tail[:19], format)
00026         return os.path.join(head, tail)
00027     except ValueError:
00028         return os.path.join(head, sep.join([now.strftime(format), tail]))
00029 
00030 
00031 def google_drive_file_url(id, download=False):
00032     cmd = 'uc' if download else 'open'
00033     url = 'https://drive.google.com/{0}?id={1}'.format(cmd, id)
00034     return url


jsk_data
Author(s):
autogenerated on Fri Sep 8 2017 03:39:16