-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.py
36 lines (28 loc) · 1.63 KB
/
scripts.py
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
import subprocess
import os
import sys
def create_shell_script(directory, script_name, shell_content):
if not os.path.exists(directory):
os.makedirs(directory)
script_path = os.path.join(directory, script_name)
with open(script_path, 'w') as file:
file.write(shell_content)
os.chmod(script_path, 0o755)
return script_path
def execute_shell_script(script_path):
subprocess.run([script_path], shell=True, check=True, timeout=60)
def push_files_in_directory(directory):
for filename in os.listdir(directory):
if filename.endswith(".csv") and not (filename == "is_day ().csv" or filename == "weathercode (wmo code).csv"):
file_path = os.path.join(directory, filename)
shell_content = f'influx write -b "intern-bucket" -f "{file_path}" --precision s ' \
f'--header "#constant measurement,forecast" --header "#datatype string,tag,tag,tag,tag,tag,tag,' \
f'dateTime:number,tag,tag,double"'
script_name = f'push_{filename.replace(" ", "_").replace("(", "").replace(")", "").replace("°C", "Celsius").replace("%", "Percent").replace("W_m²", "W_Msquared").replace("°", "Degrees").replace(".csv", "")}.sh'
script_directory = f'scripts_{longitude[:6]}_{latitude[:6]}' # Replace with your desired directory name
script_path = create_shell_script(script_directory, script_name, shell_content)
execute_shell_script(script_path)
latitude = sys.argv[1]
longitude = sys.argv[2]
directory_to_push = f'HistoricalParameters_{longitude[:6]}_{latitude[:6]}'
push_files_in_directory(directory_to_push)