opus-data/transferData.py

34 lines
812 B
Python
Raw Normal View History

2021-02-19 09:21:25 +01:00
import requests
import sys
import re
2021-02-19 09:21:25 +01:00
file_name = sys.argv[1]
print(file_name)
dptFile = open(file_name, 'r')
2021-02-19 09:21:25 +01:00
lines = dptFile.readlines()
2021-03-11 16:23:45 +01:00
subject = re.split("(?<=_)(.+)(?=\.)", file_name)[1]
jsonString = '{\" + subject + \": ['
2021-02-19 09:21:25 +01:00
# Concatenate data
for line in lines:
content = line.split(',')
jsonString += '[' + str(content[0]) + ', ' + str(content[1].strip()) + '],'
# Remove last comma
jsonString = jsonString[:-1]
jsonString += ']}'
2021-02-19 09:21:25 +01:00
headers = {
'accept': '*/*',
'hono-ttd': '10',
'Authorization': 'Basic ZGVmaW5tYUB0MzhiYmNjZDE2MjE3NDViODgxMTk5ZGI2ZWQzZGFiNmE6RGVGaW5NYWNoZW4yMDIwIQ==',
'Content-Type': 'application/json',
2021-02-19 09:21:25 +01:00
}
response = requests.post('https://http.bosch-iot-hub.com/telemetry', headers=headers, data=jsonString)
print(response)