Skip to content

Commit

Permalink
merge python client
Browse files Browse the repository at this point in the history
  • Loading branch information
nii236 committed Jun 24, 2016
2 parents 04f2458 + f796f8a commit c759c1f
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:1.6-alpine
RUN apk update && apk add git
RUN go get github.com/Masterminds/glide
COPY . /go/src/open-algot.servebeer.com/open-algot/open-algot-platform/
WORKDIR /go/src/open-algot.servebeer.com/open-algot/open-algot-platform
COPY . /go/src/github.com/nii236/nii-finance
WORKDIR /go/src/github.com/nii236/nii-finance
RUN glide up
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ services:
command: -s nats://nats:4222 "go.micro.srv.BitstampRecorder"
depends_on:
- nats
yahoo_ticker:
build: ./services/Python/
restart: always
ports:
- "4000:4000"
depends_on:
- nats
sidecar:
build:
dockerfile: ./services/Sidecar/Dockerfile
Expand Down
4 changes: 2 additions & 2 deletions services/BitstampTickSubscriber/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM openalgotplatform_go:0.1
WORKDIR /go/src/open-algot.servebeer.com/open-algot/open-algot-platform/services/BitstampTickSubscriber
COPY . /go/src/open-algot.servebeer.com/open-algot/open-algot-platform/
WORKDIR /go/src/github.com/nii236/nii-finance/services/BitstampTickSubscriber
COPY . /go/src/github.com/nii236/nii-finance/
RUN go install
ENTRYPOINT ["BitstampTickSubscriber"]
4 changes: 2 additions & 2 deletions services/OandaTickSubscriber/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM openalgotplatform_go:0.1
WORKDIR /go/src/open-algot.servebeer.com/open-algot/open-algot-platform/services/OandaTickSubscriber
COPY . /go/src/open-algot.servebeer.com/open-algot/open-algot-platform/
WORKDIR /go/src/github.com/nii236/nii-finance/services/OandaTickSubscriber
COPY . /go/src/github.com/nii236/nii-finance/
RUN go install
ENTRYPOINT ["OandaTickSubscriber"]
Binary file added services/Python/.Dockerfile.swp
Binary file not shown.
19 changes: 19 additions & 0 deletions services/Python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:2.7-alpine

MAINTAINER [email protected]

RUN pip install werkzeug
RUN pip install requests
RUN pip install protobuf


EXPOSE 4000

ADD . /python_app

WORKDIR /python_app

CMD [ "python", "yahoo_ticker.py" ]



28 changes: 28 additions & 0 deletions services/Python/python-client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 02 22:36:21 2016
@author: Jacob
"""

import test_pb2
import requests

payload = {"jsonrpc": "2.0",
"method": "postMessage",
"params": [{"name": "Jacob"}],
"id": 99}

msg = test_pb2.MessageData()
msg.id = 1234
msg.name = "John Doe"

url = "http://127.0.0.1:4000"

# POST with protobuf
r = requests.post(url, data=msg.SerializeToString())

print r.text
print r.headers['content-type']
print r.status_code

7 changes: 7 additions & 0 deletions services/Python/test.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package openalgot;

message MessageData {
required string name = 1;
required int32 id = 2;
}

74 changes: 74 additions & 0 deletions services/Python/test_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions services/Python/yahoo_ticker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""

# pip install websocket-client
# pip install protobuf
# pandas
# numpy



#import pandas.io.data as web
#import websocket
#import numpy as np
#import requests


import test_pb2



from werkzeug.wrappers import Request, Response
from werkzeug.serving import run_simple
#from jsonrpc import JSONRPCResponseManager, dispatcher

import uuid
import requests
import json

#// units ns|us|ms|s|m|h
#// http://127.0.0.1:8081/registry?ttl=10s

payload={"Name": "foo.bar",
"Nodes": [{
"Port": 9091,
"Address": "127.0.0.1",
"Id": "foo.bar-017da09a-734f-11e5-8136-68a86d0d36b6"
}]}

def register():
register_uri = "http://192.168.99.100:8081/registry"
service = "go.micro.srv.yahoo"
headers = {'content-type': 'application/json'}
payload = {
"name": service,
"nodes": [{
"id": service + "-" + str(uuid.uuid4()),
"address": "192.168.0.7",
"port": 4000,
}],
}
requests.post(register_uri, data=json.dumps(payload), headers=headers)

@Request.application
def application(request):
# Dispatcher is dictionary {<method_name>: callable}

#dispatcher["postMessage"] = lambda s: "hello " + s["name"]

msg = test_pb2.MessageData()
msg.ParseFromString(request.data)

#response = JSONRPCResponseManager.handle(
# request.data, dispatcher)
#return Response(response.json, mimetype='application/json')

return Response(msg.SerializeToString(), mimetype='application/octet-stream')


if __name__ == '__main__':
print "registering service"
#register()
print "running service"
run_simple('localhost', 4000, application)




#r = requests.post('http://192.168.99.100:8081', json=payload)


#r = requests.get('http://192.168.99.100:8081/registry')
#print r.status_code
#print r.headers['content-type']

#r = requests.get('http://192.168.99.100:8081/registry')
#print r.text


#ws = websocket.WebSocket()
#ws.connect("ws://192.168.99.100:8081/broker?topic=go.micro.srv.BitstampRecorder")
#ws.connect("ws://192.168.99.100:8081/broker?topic=go.micro.srv.TickRecorder")
#print ws.recv()

#ws://192.168.0.12:8081/broker?topic=go.micro.srv.TickRecorder


#foo = np.random.randint(0, 10, (4,5,6))

#print foo

#print foo.mean(axis=0)


#DAX = web.DataReader(name='GOOG', data_source='yahoo', start='2000-1-1')
#DAX.info()
#DAX['Close'].plot()

#print DAX.tail()


4 changes: 2 additions & 2 deletions services/Sidecar/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openalgotplatform_go:0.1
WORKDIR /go/src/open-algot.servebeer.com/open-algot/open-algot-platform/services/Sidecar
FROM openalgotplatform_go:0.1
WORKDIR /go/src/github.com/nii236/nii-finance/services/Sidecar
RUN go install
ENTRYPOINT ["Sidecar"]
4 changes: 2 additions & 2 deletions services/TickRecorder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openalgotplatform_go:0.1
WORKDIR /go/src/open-algot.servebeer.com/open-algot/open-algot-platform/services/TickRecorder
FROM openalgotplatform_go:0.1
WORKDIR /go/src/github.com/nii236/nii-finance/services/TickRecorder
RUN go install
ENTRYPOINT ["TickRecorder"]

0 comments on commit c759c1f

Please sign in to comment.