File: timestampapp.py

package info (click to toggle)
starpy 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 360 kB
  • sloc: python: 2,899; makefile: 17
file content (48 lines) | stat: -rw-r--r-- 1,384 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/env python
"""Provide a trivial date-and-time service"""
from twisted.internet import reactor
from starpy import fastagi
import utilapplication
import logging, time

log = logging.getLogger( 'dateandtime' )

def testFunction( agi ):
	"""Give time for some time a bit in the future"""
	log.debug( 'testFunction' )
	df = agi.streamFile( 'at-tone-time-exactly' )
	def onFailed( reason ):
		log.error( "Failure: %s", reason.getTraceback())
		return None
	def cleanup( result ):
		agi.finish()
		return result
	def onSaid( resultLine ):
		"""Having introduced, actually read the time"""
		t = time.time()
		t2 = t+7.0
		df = agi.sayDateTime( t2, format='HMS' )
		def onDateFinished( resultLine ):
			# now need to sleep until .05 seconds before the time 
			df = agi.wait( t2-.05-time.time() )
			def onDoBeep( result ):
				df = agi.streamFile( 'beep' )
				return df
			def waitTwo( result ):
				return agi.streamFile( 'thank-you-for-calling' )
			return df.addCallback( onDoBeep ).addCallback( waitTwo )
		return df.addCallback( onDateFinished )
	return df.addCallback( 
		onSaid 
	).addErrback( 
		onFailed 
	).addCallbacks(
		cleanup, cleanup,
	)

if __name__ == "__main__":
	logging.basicConfig()
	fastagi.log.setLevel( logging.INFO )
	APPLICATION = utilapplication.UtilApplication()
	reactor.callWhenRunning( APPLICATION.agiSpecifier.run, testFunction )
	reactor.run()