Jump to content

radarstorm

Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by radarstorm

  1. I find shell scripts arcane and difficult to understand, especially the one liners! I would use a delightful python script, for example: import os,sys,glob,time if len(sys.argv) != 3: print 'Usage %s: wildcard time_to_wait' raise SystemExit stub = sys.argv[1] wait = sys.argv[2] try: wait = int(wait) except ValueError: print 'Invalid wait time, use an integer number of seconds' raise SystemExit done = False while not done: now = time.time() modify_times = [(now-os.stat(filename).st_mtime) for filename in glob.glob(stub)] modify_times.sort() #ascending sort, so the first one is the most recent if modify_times[0] > wait: done = True else: #Don't kill the cpu by sitting in this loop forever, the absolute quickest that we could #exit this loop is wait-modify_times[0], so sleep for that long time.sleep(wait-modify_times[0]) It waits until all of the files matched by a wildcard (e.g file*) are older than a given number of seconds. You need to escape the wildcard so it doesn't get expanded by the os though, ./wait.py "file*" 300 for example
  2. Here's mine, using Ubuntu and Compiz's "Expo" plugin, which is much more useful than that unsightly cube IMO.
  3. Something like this: def currencyFormat(x): return '$%d.%02d' % (x/100,x%100) def salesHeader(): print "Brewster's Used Cars, Inc. Monthly Sales report" print print "Sales persons ID Sale amount" print "========================================" def salesDetails(): #accumulator variables salesTotal = 0 total = 0 salesFile = open("sales.dat") currentID = salesID = None for line in salesFile: salesID,salesAmount = line.strip().split() salesAmount = int(salesAmount) if salesID != currentID: if currentID != None: #Don't print this on the first iteration of the loop print "Total salesAmounts for sales agent: ",currencyFormat(salesTotal) print currentID = salesID salesTotal = 0 print salesID, '\t', currencyFormat(salesAmount) #update the accumulators salesTotal += salesAmount total += salesAmount #print the total for the last agent print " Total sales for this salesperson is: ",currencyFormat(salesTotal) print " Total of all the sales: ",currencyFormat(total) salesFile.close() salesHeader() salesDetails()
×
×
  • Create New...