Skip to content

Commit 273e926

Browse files
added connection status popup and limited snapshot results
Failed connections weren't obvious so I added a popup making this easy to see without looking at the console logging. Also reduced the number of snapshots pulled per application to 65k from 1M as Excel cannot handle over 65k URLs or around a million rows. A future release will tackle large data sets of snapshots, I just haven't decided how I want to do it yet.
1 parent c3a0807 commit 273e926

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

appd-extractor.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,49 @@
3434
token_expiration = 300
3535
expiration_buffer = 30
3636

37+
#--- Functions
38+
def show_popup_message(message, background_color, text_color, duration=3):
39+
"""
40+
Displays a temporary popup message in Streamlit.
41+
42+
Args:
43+
message (str): The message to display.
44+
background_color (str): The background color of the popup.
45+
text_color (str): The text color of the popup.
46+
duration (int): The duration (in seconds) the message should be displayed.
47+
"""
48+
49+
with st.container():
50+
popup_style = f"""
51+
position: fixed;
52+
top: 50%;
53+
left: 50%;
54+
transform: translate(-50%, -50%);
55+
background-color: {background_color};
56+
color: {text_color};
57+
padding: 20px;
58+
border-radius: 5px;
59+
z-index: 9999;
60+
opacity: 1;
61+
transition: opacity 1s ease-in-out;
62+
"""
63+
64+
st.markdown(f'<div style="{popup_style}" id="popup">{message}</div>', unsafe_allow_html=True)
65+
66+
time.sleep(duration)
67+
68+
st.markdown(f"""
69+
<script>
70+
setTimeout(function() {{
71+
document.getElementById('popup').style.opacity = '0';
72+
}}, 100); // Small delay before fade
73+
setTimeout(function() {{
74+
document.getElementById('popup').remove();
75+
}}, {duration * 1000 + 1000}); // Remove after fade
76+
</script>
77+
""", unsafe_allow_html=True)
78+
return None
79+
3780
def load_secrets():
3881
"""Loads API credentials from secrets.yml if it exists."""
3982
try:
@@ -105,16 +148,18 @@ def make_auth_request():
105148
json_response = auth_response.json()
106149
last_token_fetch_time = time.time()
107150
token_expiration = json_response['expires_in']
151+
print("Authenticated with controller.")
152+
show_popup_message(f"Connection established. {auth_response}","green","black",3)
153+
108154
else:
155+
show_popup_message(f"Unable to log in at: {BASE_URL} \n\n HTTP Status Code: {auth_response} - {status}","red","black",3)
109156
print(f"Unable to log in at: {BASE_URL}")
110157
print("Please check your controller URL and try again.")
111-
sys.exit(9)
158+
return False
112159

113160
__session__.headers['X-CSRF-TOKEN'] = json_response['access_token']
114161
__session__.headers['Authorization'] = f'Bearer {json_response["access_token"]}'
115162

116-
print("Authenticated with controller.")
117-
118163
if DEBUG:
119164
print(f"Last token fetch time: {last_token_fetch_time}")
120165
print(f"Token expires in: {json_response['expires_in']}")
@@ -537,7 +582,7 @@ def get_snapshots(application_id):
537582
snapshots_url = BASE_URL + "/controller/rest/applications/" + str(application_id) + \
538583
"/request-snapshots?time-range-type=BEFORE_NOW&duration-in-mins=" + str(snapshot_duration_mins) + \
539584
"&first-in-chain=" + str(first_in_chain) + "&need-exit-calls=" + str(need_exit_calls) + \
540-
"&need-props=" + str(need_props) + "&maximum-results=1000000"
585+
"&need-props=" + str(need_props) + "&maximum-results=65000"
541586

542587
if DEBUG:
543588
print(" --- Fetching snapshots from: "+ snapshots_url)

0 commit comments

Comments
 (0)