Renew ROC api key

Change-Id: Ieaf4ffd83a3cf6ea47071578fd48bbfd5da308be
diff --git a/person_detection/app.py b/person_detection/app.py
index b1e9b2d..0ed28eb 100644
--- a/person_detection/app.py
+++ b/person_detection/app.py
@@ -12,7 +12,7 @@
 
 import config
 from person_detection import Camera
-import roc
+from roc import Roc
 
 
 app = flask.Flask(__name__)
@@ -20,7 +20,6 @@
 
 @app.route('/')
 def index():
-    global cameras
     """Video streaming home page."""
     log.info("{} - connected".format(flask.request.remote_addr))
     return flask.render_template('index.html', devices=config.cameras)
@@ -69,6 +68,12 @@
     args.add_argument("--key",
             help = "ROC api key",
             type = str)
+    args.add_argument("--user",
+            help = "ROC username",
+            type = str)
+    args.add_argument("--password",
+            help = "ROC password",
+            type = str)
     args.add_argument("--mbrlow",
             help = "Low range of MBR",
             default = 7000000,
@@ -86,9 +91,26 @@
 
 
 if __name__ == '__main__':
-    log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.DEBUG, stream=sys.stdout)
+    log.basicConfig(
+            format='%(asctime)s %(levelname)-8s %(message)s',
+            level=log.DEBUG,
+            datefmt='%Y-%m-%d %H:%M:%S',
+            stream=sys.stdout)
     log.debug("Starting person detection app")
+
     args = build_argparser().parse_args()
+
     if not args.noroc:
-        roc.set_mbr(args.key, args.devicegroup, args.mbrlow)
+        key = args.key
+        if key is None:
+            if args.user is not None and args.password is not None:
+                roc = Roc(args.user, args.password)
+                key = roc.get_key()
+            else:
+                log.error("Either key or user/password required")
+                sys.exit()
+
+        log.info("Device group:{} mbr:{}(low)".format(args.devicegroup, args.mbrlow))
+        roc.set_mbr(args.devicegroup, args.mbrlow)
+
     app.run(host='0.0.0.0', debug=True)