-
-
Save afourney/82e6c6f28b67d1ef5a50d537b1b87ac6 to your computer and use it in GitHub Desktop.
Bottle server that proxies the Pebble boot config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
''' | |
A basic bottle app skeleton | |
''' | |
import bottle | |
import json | |
import requests | |
import base64 | |
import urllib2 | |
class StripPathMiddleware(object): | |
''' | |
Get that slash out of the request | |
''' | |
def __init__(self, a): | |
self.a = a | |
def __call__(self, e, h): | |
e['PATH_INFO'] = e['PATH_INFO'].rstrip('/') | |
return self.a(e, h) | |
app = application = StripPathMiddleware(bottle.app()) | |
#@bottle.route('/boot/<redirect>/<path:re:.*>', method='GET') | |
#def boot(redirect,path): | |
@bottle.route('/boot/<path:re:.*>', method='GET') | |
def boot(path): | |
url = "https://boot.getpebble.com/api/config/" + path + '?' + bottle.request.query_string | |
store_uri = 'https://santoku.adamfourney.com' | |
#store_uri = urllib.unquote(redirect) | |
data = urllib2.urlopen(url).read() | |
bottle.response.headers['Content-Type'] = 'application/json' | |
try: | |
data = json.loads(data) | |
data["config"]["webviews"]["support/faq"] = store_uri + "/faq" | |
data["config"]["webviews"]["appstore/application"] = store_uri + "/application/$$id$$?pebble_color=$$pebble_color$$&hardware=$$hardware$$&uid=$$user_id$$&mid=$$phone_id$$&pid=$$pebble_id$$&$$extras$$" | |
data["config"]["webviews"]["appstore/application_changelog"] = store_uri + "/changelog/$$id$$?pebble_color=$$pebble_color$$&hardware=$$hardware$$&uid=$$user_id$$&mid=$$phone_id$$&pid=$$pebble_id$$&$$extras$$" | |
data["config"]["webviews"]["appstore/developer_apps"] = store_uri + "/developer/$$id$$?pebble_color=$$pebble_color$$&hardware=$$hardware$$&uid=$$user_id$$&mid=$$phone_id$$&pid=$$pebble_id$$&$$extras$$" | |
data["config"]["webviews"]["appstore/watchfaces"] = store_uri + "/watchfaces?pebble_color=$$pebble_color$$&hardware=$$hardware$$&uid=$$user_id$$&mid=$$phone_id$$&pid=$$pebble_id$$&$$extras$$" | |
data["config"]["webviews"]["appstore/watchapps"] = store_uri + "/watchapps?pebble_color=$$pebble_color$$&hardware=$$hardware$$&uid=$$user_id$$&mid=$$phone_id$$&pid=$$pebble_id$$&$$extras$$" | |
return json.dumps(data, sort_keys=True, indent=4, separators=(',', ': ')) | |
except: | |
return data | |
@bottle.route('/boot-staging/<path:re:.*>', method='GET') | |
def boot_staging(path): | |
url = "https://boot.getpebble.com/api/config/" + path + '?app_version=' + bottle.request.query['app_version'] | |
store_uri = bottle.request.query['store_uri'] | |
data = urllib2.urlopen(url).read() | |
bottle.response.headers['Content-Type'] = 'application/json' | |
try: | |
data = json.loads(data) | |
data["config"]["webviews"]["support/faq"] = store_uri + "/faq" | |
data["config"]["webviews"]["appstore/application"] = store_uri + "/application/$$id$$?pebble_color=$$pebble_color$$&hardware=$$hardware$$&uid=$$user_id$$&mid=$$phone_id$$&pid=$$pebble_id$$&$$extras$$" | |
data["config"]["webviews"]["appstore/application_changelog"] = store_uri + "/changelog/$$id$$?pebble_color=$$pebble_color$$&hardware=$$hardware$$&uid=$$user_id$$&mid=$$phone_id$$&pid=$$pebble_id$$&$$extras$$" | |
data["config"]["webviews"]["appstore/developer_apps"] = store_uri + "/developer/$$id$$?pebble_color=$$pebble_color$$&hardware=$$hardware$$&uid=$$user_id$$&mid=$$phone_id$$&pid=$$pebble_id$$&$$extras$$" | |
data["config"]["webviews"]["appstore/watchfaces"] = store_uri + "/watchfaces?pebble_color=$$pebble_color$$&hardware=$$hardware$$&uid=$$user_id$$&mid=$$phone_id$$&pid=$$pebble_id$$&$$extras$$" | |
data["config"]["webviews"]["appstore/watchapps"] = store_uri + "/watchapps?pebble_color=$$pebble_color$$&hardware=$$hardware$$&uid=$$user_id$$&mid=$$phone_id$$&pid=$$pebble_id$$&$$extras$$" | |
return json.dumps(data, sort_keys=True, indent=4, separators=(',', ': ')) | |
except: | |
return data | |
########### | |
if __name__ == '__main__': | |
bottle.run(app=app, | |
host='0.0.0.0', | |
port=8080) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment