
import cherrypy
import itertools

class BookingReferenceService(object):
    def __init__(self, starting_point):
        self.counter = itertools.count(starting_point)
    
    def booking_reference(self):
        next_number = self.counter.next()
        return str(hex(next_number))[2:]
        
    booking_reference.exposed = True
    
if __name__ == "__main__":
    """ 
    Use this code to start a booking reference service on http://localhost:8080/booking_reference
    
    If you have to restart the service, you can continue counting from the previous reference
    by passing it on the command line
    """
    import sys
    if len(sys.argv) > 1:
        starting_point = int(sys.argv[1], 16) + 1
    else:
        starting_point = 123456789
    
    cherrypy.quickstart(BookingReferenceService(starting_point))
@@ -334,16 +334,261 @@
 ue%0A    %0A
+def main(args):%0A    if args:%0A        starting_point = int(args%5B0%5D, 16) + 1%0A    else:%0A        starting_point = 123456789%0A%0A    cherrypy.config.update(%7B%22server.socket_port%22 : 8082%7D)%0A    cherrypy.quickstart(BookingReferenceService(starting_point))%0A%0A
 if __nam
@@ -614,17 +614,24 @@
     
-%22%22%22 %0A    
+help_text = %22%22%22%0A
 Use 
@@ -639,12 +639,15 @@
 his 
-code
+program
  to 
@@ -679,19 +679,100 @@
  service
- on
+:%0A%0A    python booking_reference_service.py%0A%0AThe service will start on this url:%0A%0A   
  http://
@@ -784,17 +784,17 @@
 host:808
-0
+2
 /booking
@@ -804,25 +804,17 @@
 ference%0A
-    %0A    
+%0A
 If you h
@@ -875,17 +875,17 @@
 from the
- 
+%0A
 previous
@@ -894,20 +894,16 @@
 eference
-%0A   
  by pass
@@ -932,95 +932,152 @@
 line
-%0A    %22%22%22%0A    import sys%0A    if len(sys.argv) %3E 1:%0A        starting_point = int(
+:%0A%0A    python booking_reference_service.py 75bcd15%0A    %22%22%22%0A    import sys%0A    if %22-help%22 in sys.argv or %22--help%22 in sys.argv or %22-h%22 in 
 sys.argv
 %5B1%5D,
@@ -1076,131 +1076,66 @@
 argv
-%5B1%5D, 16) + 1%0A    else:%0A        starting_point = 123456789
+:%0A        print help_text%0A    else:
 %0A    
-%0A
     
-cherrypy.quickstart(BookingReferenceService(starting_point)
+main(sys.argv%5B1:%5D
 )

improve help text for booking reference service