Last active
August 29, 2015 13:56
-
-
Save peketamin/8961591 to your computer and use it in GitHub Desktop.
[Python] filename with timestamp for auto versioning on HTML cache.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def current_date(format='%Y-%m-%d %H:%M:%S'): | |
import datetime | |
return datetime.date.today().strftime(format) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_versioned_filename(base_dir, filename): | |
# ref:http://stackoverflow.com/questions/82831/how-do-i-check-if-a-file-exists-using-python | |
import os | |
try: | |
filepath = os.path.join(base_dir, filename) | |
mtime = os.stat(filepath).st_mtime | |
except OSError: | |
return None | |
else: | |
return "%s?%s" % (filename, mtime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def kansuuji(number): | |
number_map = { | |
'1': u'一', | |
'2': u'二', | |
'3': u'三', | |
'4': u'四', | |
'5': u'五', | |
'6': u'六', | |
'7': u'七', | |
'8': u'八', | |
'9': u'九', | |
'0': u'〇', | |
} | |
number_string = str(number) | |
retval = u'' | |
for c in number_string: | |
retval += number_map.get(c, u'') | |
return retval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment