opus-data/transferData.py

35 lines
915 B
Python

import requests
import sys
file_name = sys.argv[1]
dptFile = open("DPT/" + file_name, 'r')
lines = dptFile.readlines()
jsonString = '['
# Concatenate data
for line in lines:
content = line.split(',')
jsonString += '[' + str(content[0]) + ', ' + str(content[1].strip()) + '],'
# Remove last comma
jsonString = jsonString[:-1]
jsonString += ']'
headers = {
'accept': '*/*',
'Authorization': 'Basic ZGVmaW5tYV9jb25uZWN0X1JuZ0B0YTJlMzViYjkyZDRjNDkyZDgwMjdkNDMyOTMxNzBkMDRfaHViOkRlZmlubWE=',
'Content-Type': 'application/json',
}
data = '{"topic":"definma_connect/Rng/things/twin/commands/modify", "path":"features/data","value":{"properties":' + jsonString + '}}'
print(data)
# Convert jsonString to dictionary
#jsonDict = json.loads(jsonString)
# Write Json into file
#with open(file_name, 'w') as jsonFile:
# json.dump(jsonDict, jsonFile)