Added habitat upload. Not complete yet but close #6

master
Richard Meadows 2015-08-01 20:58:37 +01:00
rodzic 078bc30736
commit 33baba8270
2 zmienionych plików z 44 dodań i 1 usunięć

Wyświetl plik

@ -0,0 +1,37 @@
"""
Uploads payload_telemetry to habhub
"""
import base64
import hashlib
import couchdb
from datetime import datetime
couch = couchdb.Server('http://habitat.habhub.org/')
db = couch['habitat']
def habitat_upload(packet_string):
print packet_string
packet_base64 = base64.standard_b64encode(packet_string+"\n")
print packet_base64
packet_sha256 = hashlib.sha256(packet_base64).hexdigest()
print packet_sha256
now = datetime.utcnow()
time_uploaded = now.replace(microsecond=0).isoformat()+"+00:00"
print time_uploaded
print db.save({
"type":"payload_telemetry",
"_id": packet_sha256,
"data":{
"_raw": packet_base64
},
"receivers": {
"BACKLOG": {
"time_created": time_uploaded,
"time_uploaded": time_uploaded
}
}
})

Wyświetl plik

@ -13,6 +13,7 @@ else will be ignored.
import re
import sys
from ukhas_format import *
from habitat_upload import *
from datetime import datetime
from math import log, exp
@ -136,5 +137,10 @@ with open(file_name, 'r') as data_file:
# Print data
for datum in data:
ukhas_format(datum)
print "%s: %s, %s" % ((str(datum['time']),) + datum['coords'][:2])
# Upload data to habitat
datum = data[0]
ukhas_str = ukhas_format(datum)
print ukhas_str
habitat_upload(ukhas_str)