Skip to content

Instantly share code, notes, and snippets.

@beatak
Created January 3, 2014 01:39
Show Gist options
  • Save beatak/8231012 to your computer and use it in GitHub Desktop.
Save beatak/8231012 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import time
import subprocess
import shutil
import os
from logger import Logger
from config import Config
l = Logger(Config)
s_sleep = 5.0
COMMAND = 'ls -t /Users/tmizohata/.tetherball/queue/ | head -1'
def cb_consume ():
l.debug( 'cb_consume' )
time.sleep( s_sleep )
try:
str_last = subprocess.check_output( COMMAND, shell=True )
ms_now = int( time.time() * 1000 )
if str_last != '':
ms_last = int( str_last.strip() )
else:
ms_last = ms_now - 5001
if (ms_now - ms_last) > (s_sleep * 1000):
shutil.rmtree( Config.PATH_TETHERBALL_QUEUE )
l.debug( 'EXECUTED' )
os.mkdir( Config.PATH_TETHERBALL_QUEUE )
else:
cb_consume()
except Exception, e:
l.debug( 'Failed: %s' % e)
if __name__ == "__main__":
cb_consume()
#! /usr/bin/env python
import time
import os.path
from logger import Logger
from config import Config
if __name__ == "__main__":
t_now = int( time.time() * 1000 )
try:
open( os.path.join( Config.PATH_TETHERBALL_QUEUE, str( t_now )), 'w').close()
except Exception, e:
l = Logger(Config)
l.debug( 'Failed to write: %s' % e )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment