Skip to content

Instantly share code, notes, and snippets.

@MitchRatquest
Created September 12, 2016 19:26
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 MitchRatquest/0d5dbde393cd35a44f9fd426b1ba2047 to your computer and use it in GitHub Desktop.
Save MitchRatquest/0d5dbde393cd35a44f9fd426b1ba2047 to your computer and use it in GitHub Desktop.
generic scanner
import os, datetime, time
yam = [] #init var
timestamp = str(datetime.datetime.now().strftime('%I.%M.%S_%p')) + '.txt' #only once, filename ultimately
daystamp = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d') #name of folder to put files for today in
cwd = os.getcwd() #current working directory
opj = os.path.join #more magic - OS PATH JOIN = opj, for windows and linux compatibility
folderWithTodaysDate = opj(cwd, daystamp) # folder to place all todays scans in
if os.path.exists(folderWithTodaysDate) == True: #If file w/ today's date exists, then continue the script.
pass
else: #else create the directory with read/write/exe permissions.
os.makedirs(folderWithTodaysDate, 0o666) #read/write permissions for creating files inside python created folder. For Win & Linux.
while True:
yam.append(raw_input()) #stream input to append
if(yam[-1]) == 'deleteprevious':
del(yam[-2])
del(yam[-1])#delete control word
if(yam[-1]) == 'imfinished':
del(yam[-1]) #dont print the imfinished bit
quit()
createFileInDateDirectory = str(opj(folderWithTodaysDate, timestamp)) #current file in progress, based on timestamp above
with open(createFileInDateDirectory, 'a') as final: #append that file every time you scan in case of system failure somewhere (batteries die)
final.write(yam[-1] + '\n') #write the latest input
final.close() #close it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment