Automate process with inotifywait
This commit is contained in:
		
							
								
								
									
										23
									
								
								OpusData.R
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								OpusData.R
									
									
									
									
									
								
							@@ -1,27 +1,30 @@
 | 
			
		||||
#!/usr/bin/env Rscript
 | 
			
		||||
 | 
			
		||||
# Attach package to workspace, execute with every new session
 | 
			
		||||
# Attach packages to workspace, execute with every new session
 | 
			
		||||
source("ReadOpus.R")
 | 
			
		||||
 | 
			
		||||
# Determine file path
 | 
			
		||||
path <- paste(getwd(), "/OPUS/", sep = "")
 | 
			
		||||
path <- paste0(getwd(), "/OPUS/")
 | 
			
		||||
file_name <- commandArgs(trailingOnly = TRUE)[1]
 | 
			
		||||
file_path <- paste(path, file_name, sep = "")
 | 
			
		||||
 | 
			
		||||
# Convert opus binary file into dataframe
 | 
			
		||||
data <- read_opus_univ(file_path, 5)
 | 
			
		||||
 | 
			
		||||
# Set working directory to path where the result file should appear
 | 
			
		||||
setwd(paste(path, "../DPT", sep = ""))
 | 
			
		||||
# Replace last "." with "_", add ".DPT"
 | 
			
		||||
file_name <- paste0(sub(".([^.]*)$", "_\\1", file_name), ".DPT")
 | 
			
		||||
 | 
			
		||||
# Replace last "." with "_", add ".DPT" and create file
 | 
			
		||||
file_name <- paste(sub(".([^.]*)$", "_\\1", file_name), ".DPT", sep = "")
 | 
			
		||||
file.create(file_name)
 | 
			
		||||
# Determine target, where the result should appear
 | 
			
		||||
target_path <- paste0(path, "../DPT/", file_name)
 | 
			
		||||
 | 
			
		||||
# Create file
 | 
			
		||||
file.create(target_path)
 | 
			
		||||
 | 
			
		||||
# Fill file with dataframe
 | 
			
		||||
write.table(data, file_name, row.names = FALSE, col.names = FALSE, sep = ",")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
write.table(data, target_path, row.names = FALSE, col.names = FALSE, sep = ",")
 | 
			
		||||
 | 
			
		||||
# Call python script
 | 
			
		||||
system(paste('python3 transferData.py', file_name))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,5 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
inotifywait -m OPUS -e create -e moved_to |
 | 
			
		||||
	while read fpath action file; do
 | 
			
		||||
		echo "The file '$file' appeard in directory '$fpath' via '$action'"
 | 
			
		||||
		Rscript OpusData.R $file
 | 
			
		||||
	done
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								transferData.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								transferData.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
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)
 | 
			
		||||
		Reference in New Issue
	
	Block a user