-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_response.py
57 lines (48 loc) · 1.77 KB
/
check_response.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import json
import time
import requests
import os
def fetch_and_save_json():
if os.path.exists('approval_response.json'):
os.remove('approval_response.json')
response = requests.get('http://107.20.85.27:8000/get_responses')
response.raise_for_status()
json_data = response.json()
with open('approval_response.json', "w") as file:
file.write(response.text)
def check_approval_responses(check_interval=3):
file_path = 'approval_response.json'
open(file_path,"w")
while True:
fetch_and_save_json()
try:
# Load the JSON data from the file
with open(file_path, 'r') as file:
file_content = file.read()
response = json.loads(file_content)
if response == []:
# If the file is empty
print("No responses yet. Waiting...")
time.sleep(check_interval)
continue
else:
if response[0]['response'].lower() == 'yes':
return True
else:
return False
except Exception as e:
# If the file content is not valid JSON
print("Error reading JSON file. Retrying...",e)
time.sleep(check_interval)
continue
# # Check if there are any responses
# if not approval_responses:
# print("No responses yet. Waiting...")
# time.sleep(check_interval)
# continue
# # Check if responses are "yes"
# yes = True
# for response in approval_responses:
# if response['response'].lower() != 'yes':
# all_yes = False
# break