Closed gpkirk closed 9 years ago
Here you go:
#!/usr/bin/env python
import sys
import json
import random
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
class Handler(SimpleHTTPRequestHandler):
def do_GET(self):
data = list()
for index in xrange(10):
data.append({'key': index, 'value': random.randint(0, 50)})
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.request.sendall(json.dumps({'options': data}))
if __name__ == '__main__':
port = sys.argv[1] if len(sys.argv) > 1 else 8099
print('http server is starting...')
# ip and port of server
server_address = ('0.0.0.0', port)
httpd = HTTPServer(server_address, Handler)
print('http server is running...listening on port %s' % port)
httpd.serve_forever()
This is simple web server in python, that returns data in json format. I add random data, but you can fill anything you like. Here is how it looks like:
curl localhost:8099
{"options": [{"value": 32, "key": 0}, {"value": 17, "key": 1}, {"value": 30, "key": 2}, {"value": 13, "key": 3}, {"value": 41, "key": 4}, {"value": 0, "key": 5}, {"value": 18, "key": 6}, {"value": 38, "key": 7}, {"value": 29, "key": 8}, {"value": 49, "key": 9}]}
Hope it helps.
I understand what you mean about setting up the web service in the webserver directory, but i do not understand how to get the values I need into the options.json if they are coming from someplace dynamically like a VCS or from a listing of successful build numbers in TeamCity for a specific build configuration. So far any api call i make returns way to much information to be inserted into that options file. As you may already have guessed i am trying to dynamically return a list of successful builds numbers or a list of VCS labels from which I can choose to deploy to an environment. I hope that makes sense. I would greatly appreciate any insight you can provide. Thanks!