Skip to content

Instantly share code, notes, and snippets.

@Cam1337
Created May 22, 2010 03:15
Show Gist options
  • Save Cam1337/409721 to your computer and use it in GitHub Desktop.
Save Cam1337/409721 to your computer and use it in GitHub Desktop.
from time import strftime as strf
from commands import getoutput as gout
from os import listdir, path
def timedate(x):
"""
strftime simplified
"""
x="".join(x.lower().split()[0])
if x=="date":return strf("%m/%d/%y")
elif x=="time":return strf("%I:%M:%S %p")
elif x=="day":return strf("%A")
elif x=="month":return strf("%B")
def owc(File, Mode, toWrite, newline):
"""
owc = open, write, close
"""
File=TotalDir(File, True)
ptf, fname = path.split(File)
dircont=listdir(ptf)
if fname not in dircont:
open(File, 'w').close()
fw=open(File, Mode)
if newline:
fw.write(toWrite+"\n")
else:
fw.write(toWrite)
fw.close()
def isInDir(File, Dir, cs):
"""
check if the file is in the given directory
"""
Dir=TotalDir(Dir)
if cs:
DirList = listdir(Dir)
File=File
else:
DirList = [i.lower() for i in listdir(Dir)]
File=File.lower()
if File in DirList:
return True
else:
return False
def TotalDir(Dir):
"""
time saver
"""
return path.expanduser(Dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment