-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_script.py
More file actions
50 lines (39 loc) · 1.43 KB
/
run_script.py
File metadata and controls
50 lines (39 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from local_db import Influx_Database_class
from modbus_driver import Modbus_Driver
import time
import argparse
def main():
# read arguments passed at .py file call
parser = argparse.ArgumentParser()
parser.add_argument("config", help="config file")
args = parser.parse_args()
config_file = args.config
#config_file = 'config_template.yaml'
obj = Modbus_Driver(config_file)
obj.initialize_modbus()
local_db = Influx_Database_class(config_in=config_file, config_type="local")
remote_db = Influx_Database_class(config_in=config_file, config_type="remote")
i=0
while True:
data = obj.get_data()
print(data)
time.sleep(1)
'''
local_db.push_json_to_db(data=data)
time.sleep(1)
if i%10 == 0 and i!=0:
time_now = time.time()
local_data = local_db.read_from_db(time_now=time_now)
print("length of data in local db:", len(local_data))
remote_db.push_df_to_db(df=local_data)
local_db.successful_push()
remote_data = remote_db.read_from_db(time_now=time_now)
print("length after remote push = ",len(remote_data))
#local_db.delete_from_db(time_now=time_now)
#local_data2 = local_db.read_from_db(time_now=time_now)
#print("length after deleting from local = ", len(local_data2))
i+=1
'''
return
if __name__ == "__main__":
main()