Skip to content

Instantly share code, notes, and snippets.

@peketamin
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peketamin/8961591 to your computer and use it in GitHub Desktop.
Save peketamin/8961591 to your computer and use it in GitHub Desktop.
[Python] filename with timestamp for auto versioning on HTML cache.
def current_date(format='%Y-%m-%d %H:%M:%S'):
import datetime
return datetime.date.today().strftime(format)
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)
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