Skip to content

Commit

Permalink
Added push.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fyquah committed Jun 6, 2015
1 parent 6748cbb commit 1512cd9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions push.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python
import os, json, subprocess, string, requests, tinys3, random

dirname = os.path.dirname(os.path.realpath(__file__))
executable = dirname + "/json"
url = "http://localhost:3000/fish"

# j = subprocess.check_output([ executable, "output.jpeg"])
# s = string.split(j, "\n")[1]
# obj = json.loads(s)

obj = {
"width": 1,
"length" : 2.0
}

conn = tinys3.Connection(os.environ["AWS_ACCESS_KEY_ID"], os.environ["AWS_SECRET_KEY"],
tls=True, endpoint='s3-eu-west-1.amazonaws.com')
file_name = str(random.random()) + "-pic.jpeg"
f = open("build/output.jpeg", "rb")
conn.upload(file_name, f, "fish-measurer")
aws_file_name = "https://s3-eu-west-1.amazonaws.com/fish-measurer/" + file_name

# Send the http request
payload = {
"fish": {
"width": obj["width"],
"length": obj["length"],
"lat": 5.476795,
"lng": 100.247197
}
}
headers = { "content-type": "application/json" }

print requests.post(url= url, data=json.dumps(payload), headers=headers)

0 comments on commit 1512cd9

Please sign in to comment.