commit d4743023d0bf570990f0d43edd31d383eaf728fb
Author: ssung <js.lee@sdt.inc>
Date:   Wed Sep 6 19:02:39 2023 +0900

    first commit

diff --git a/config/acquisition_config.json b/config/acquisition_config.json
new file mode 100755
index 0000000..604af7f
--- /dev/null
+++ b/config/acquisition_config.json
@@ -0,0 +1,18 @@
+{
+  "genicam_gentl64_path": "/opt/ids-peak-with-ueyetl_2.5.0.0-16074_amd64/lib/ids/cti/",
+  "amqp_url": "25.2.96.55",
+  "amqp_port": 5672,
+  "amqp_vhost": "/",
+  "amqp_id": "worker",
+  "amqp_pw": "gseps1234",
+  "amqp_queue": "TaskQ",
+  "Minio_url": "http://13.209.39.139:31191",
+  "AccessKey":"VV2gooVNevRAIg7HrXQr",
+  "SecretKey":"epJmFWxwfzUUgYeyDqLa8ouitHZaWTwAvPfPNUBL",
+  "Boto3SignatureVersion":"s3v4",
+  "Boto3RegionName":"us-east-1",
+  "BucketName":"gseps-test-a",
+  "image_save_path": "/home/sdt/Workspace/gseps/image_acquisition/capture/",
+  "fail_log_file": "/home/sdt/Workspace/gseps/image_acquisition/fail_message.txt",
+  "success_log_file": "/home/sdt/Workspace/gseps/image_acquisition/acquisition.log"
+}
diff --git a/config/send_and_pub_config.json b/config/send_and_pub_config.json
new file mode 100755
index 0000000..5bdafa5
--- /dev/null
+++ b/config/send_and_pub_config.json
@@ -0,0 +1,18 @@
+{
+  "amqp_url": "13.209.39.139",
+  "amqp_port": 30747,
+  "amqp_vhost": "/",
+  "amqp_id": "sdt",
+  "amqp_pw": "251327",
+  "amqp_queue": "gseps-mq",
+  "Minio_url": "http://13.209.39.139:31191",
+  "AccessKey":"VV2gooVNevRAIg7HrXQr",
+  "SecretKey":"epJmFWxwfzUUgYeyDqLa8ouitHZaWTwAvPfPNUBL",
+  "Boto3SignatureVersion":"s3v4",
+  "Boto3RegionName":"us-east-1",
+  "BucketName":"gseps-test-a",
+  "file_save_path": "/home/sdt/Workspace/gseps/capture/",
+  "send_json_flag": true,
+  "delete_sended_file_flag": true,
+  "send_interval":30
+}
diff --git a/install.sh b/install.sh
new file mode 100755
index 0000000..5a29dd0
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+if [ -f '/etc/systemd/system/send_and_pub.service' ]; then
+    sudo systemctl disable send_and_pub.service
+    sudo systemctl stop send_and_pub.service
+    sudo rm -rf /etc/systemd/system/send_and_pub.service
+fi
+
+sudo cp /home/sdt/Workspace/gseps/send_and_pub.service /etc/systemd/system
+
+sudo systemctl daemon-reload
+sudo systemctl enable send_and_pub.service
+sudo systemctl start send_and_pub.service
diff --git a/send_and_pub.py b/send_and_pub.py
new file mode 100755
index 0000000..076954c
--- /dev/null
+++ b/send_and_pub.py
@@ -0,0 +1,83 @@
+import os
+import sys
+import json
+import time
+import datetime
+import traceback
+
+import pika
+import boto3
+from botocore.client import Config
+
+################################################################################
+#                                      Config                                  #
+################################################################################
+
+with open('/home/sdt/Workspace/gseps/send_and_pub/config/send_and_pub_config.json', 'r') as f:
+    info = json.load(f)
+
+################################################################################
+#                                   S3 Set up                                  #
+################################################################################
+
+s3 = boto3.resource('s3',
+        endpoint_url = info['Minio_url'],
+        aws_access_key_id=info['AccessKey'],
+        aws_secret_access_key=info['SecretKey'],
+        config=Config(signature_version=info['Boto3SignatureVersion']),
+        region_name=info['Boto3RegionName']
+)
+
+
+class Publisher:
+    def __init__(self):
+        self.__url = info['amqp_url']
+        self.__port = info['amqp_port']
+        self.__vhost = info['amqp_vhost']
+        self.__cred = pika.PlainCredentials(info['amqp_id'], info['amqp_pw'])
+        self.__queue = info['amqp_queue']
+
+    def pub(self, body: dict):
+        try:
+            conn = pika.BlockingConnection(pika.ConnectionParameters(self.__url,
+                                                                     self.__port,
+                                                                     self.__vhost,
+                                                                     self.__cred))
+            chan = conn.channel()
+            chan.basic_publish(exchange='',
+                               routing_key=self.__queue,
+                               body=json.dumps(body))
+            conn.close()
+            return
+        except Exception as e:
+            print(traceback.format_exc())
+
+
+
+
+def main():
+    publisher = Publisher()
+    while True:
+       if not os.path.exists(info['file_save_path']):
+           os.makedirs(info['file_save_path'])
+
+       file_list = os.listdir(info['file_save_path'])
+       if(len(file_list) == 0):
+           print(f"Folder is empty! send data after {info['send_interval']} sec")
+           time.sleep(info['send_interval'])
+           continue
+
+       for file_name in file_list:
+           local_file_path = os.path.join(info['file_save_path'],file_name)
+           print(s3.Bucket(info['BucketName']).upload_file(local_file_path,file_name))
+           if(info['send_json_flag']==True):
+               if(file_name.split(".")[1] == "json"):
+                   with open(local_file_path,"r") as f:
+                       publisher.pub(f.read())
+           if(info['delete_sended_file_flag']==True):
+               os.remove(local_file_path)
+               print(f"Remove {local_file_path}")
+
+
+if __name__ == '__main__':
+    main()
diff --git a/send_and_pub.service b/send_and_pub.service
new file mode 100755
index 0000000..aa49a4a
--- /dev/null
+++ b/send_and_pub.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=image upload  periodically
+
+[Service]
+ExecStart=/usr/bin/python3 /home/sdt/Workspace/gseps/send_and_pub/send_and_pub.py
+Restart=on-failure
+Group=sdt
+User=sdt
+
+[Install]
+WantedBy=multi-user.target