@@ -0,0 +1,2528 @@
+from flask.ext.api import FlaskAPI%0Afrom flask import redirect%0Afrom flask import request%0Afrom flask import url_for%0Aimport re%0Aimport subprocess%0A%0A%0Aapp = FlaskAPI(__name__)%0A%0A%0Adef _tab_list_str_to_dict(tab_str, request):%0A    matches = re.search(%0A        r'%5E%5C%5B(?P%3Cwindow_id%3E%5Cd+):(?P%3Ctab_id%3E%5Cd+)%5C%5D(?P%3Ctab_title%3E.+)$', tab_str%0A    )%0A    if matches is None:%0A        return %7B%7D%0A    tab = %7B%0A        'id': matches.group('tab_id'),%0A        'title': matches.group('tab_title'),%0A        'window': matches.group('window_id'),%0A    %7D%0A    tab%5B'tab_view_url'%5D = '%25stabs/%25s' %25 (request.url_root, tab%5B'id'%5D)%0A    tab%5B'title'%5D = tab%5B'title'%5D.strip()%0A    return tab%0A%0A%0Adef _tab_info_str_to_dict(tab_str, request):%0A    tab_lines = tab_str.rstrip().split('%5Cn')%0A    tab = %7B%7D%0A%0A    for line in tab_lines:%0A        matches = re.search(%0A            r'%5E(?P%3Ckey%3E%5Cw+):(?P%3Cvalue%3E.+)$', line%0A        )%0A        key = unicode(matches.group('key').lower(), 'utf-8')%0A        value = unicode(matches.group('value'), 'utf-8')%0A        tab%5Bkey%5D = value%0A%0A    tab%5B'id'%5D = int(tab%5B'id'%5D)%0A    tab%5B'title'%5D = tab%5B'title'%5D.strip()%0A    tab%5B'tab_view_url'%5D = '%25stabs/%25s' %25 (request.url_root, tab%5B'id'%5D)%0A%0A    return tab%0A%0A%0A@app.route('/tabs')%0Adef tab_list():%0A    tabs = subprocess.check_output(%0A        %5B'chrome-cli', 'list', 'tabs'%5D%0A    ).rstrip().split('%5Cn')%0A    tabs = %5B_tab_list_str_to_dict(unicode(tab, 'utf-8'), request) for tab in tabs%5D%0A    return tabs%0A%0A%0A@app.route('/tabs/%3Cint:id%3E', methods=%5B'GET', 'PUT', 'DELETE'%5D)%0Adef tab_detail(id):%0A    tab = _tab_info_str_to_dict(%0A        subprocess.check_output(%5B'chrome-cli', 'info', '-t', str(id)%5D),%0A        request%0A    )%0A%0A    if request.method == 'DELETE':%0A        subprocess.check_call(%5B'chrome-cli', 'close', '-t', str(id)%5D)%0A        return %7B'message': 'Tab closed successfully'%7D%0A%0A    if request.method == 'PUT':%0A        url = request.data.get('url')%0A        args = %5B'chrome-cli', 'open', str(url), '-t', str(id)%5D%0A        subprocess.check_call(args)%0A        return redirect(url_for('tab_detail', id=tab%5B'id'%5D))%0A%0A    return tab%0A%0A%0A@app.route('/tabs/current', methods=%5B'GET', 'PUT', 'DELETE'%5D)%0Adef tab_current():%0A    if request.method == 'DELETE':%0A        subprocess.check_call(%5B'chrome-cli', 'close', '-t', str(id)%5D)%0A        return %7B'message': 'Tab closed successfully'%7D%0A%0A    current_tab = _tab_info_str_to_dict(%0A        subprocess.check_output(%5B'chrome-cli', 'info'%5D),%0A        request%0A    )%0A    return redirect(url_for('tab_detail', id=current_tab%5B'id'%5D))%0A%0Aif __name__ == '__main__':%0A    app.run(host='0.0.0.0', port=5000, debug=True)%0A

Add basic API.