2021-02-19 09:21:25 +01:00
|
|
|
import requests
|
|
|
|
import sys
|
2021-03-05 14:26:13 +01:00
|
|
|
import re
|
2021-02-19 09:21:25 +01:00
|
|
|
|
|
|
|
file_name = sys.argv[1]
|
2021-03-05 14:26:13 +01:00
|
|
|
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]
|
2021-03-05 14:26:13 +01:00
|
|
|
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]
|
2021-03-05 14:26:13 +01:00
|
|
|
jsonString += ']}'
|
2021-02-19 09:21:25 +01:00
|
|
|
|
|
|
|
headers = {
|
2021-03-05 14:26:13 +01:00
|
|
|
'accept': '*/*',
|
|
|
|
'hono-ttd': '10',
|
|
|
|
'Authorization': 'Basic ZGVmaW5tYUB0MzhiYmNjZDE2MjE3NDViODgxMTk5ZGI2ZWQzZGFiNmE6RGVGaW5NYWNoZW4yMDIwIQ==',
|
|
|
|
'Content-Type': 'application/json',
|
2021-02-19 09:21:25 +01:00
|
|
|
}
|
|
|
|
|
2021-03-05 14:26:13 +01:00
|
|
|
response = requests.post('https://http.bosch-iot-hub.com/telemetry', headers=headers, data=jsonString)
|
|
|
|
|
|
|
|
print(response)
|
|
|
|
|