Spaces:
Running
Running
Update Data_Fetching_and_Rendering.py
Browse files
Data_Fetching_and_Rendering.py
CHANGED
@@ -4,49 +4,14 @@ from sessions import create_session
|
|
4 |
import html
|
5 |
from datetime import datetime, timezone, timedelta # Added timezone, timedelta
|
6 |
import traceback
|
7 |
-
|
|
|
8 |
|
9 |
API_V2_BASE = 'https://api.linkedin.com/v2'
|
10 |
API_REST_BASE = "https://api.linkedin.com/rest"
|
11 |
|
12 |
|
13 |
-
def display_error(message, e=None):
|
14 |
-
"""Formats an error message for display in Gradio. Returns a gr.update object."""
|
15 |
-
error_prefix = "❌ Error: "
|
16 |
-
full_message = f"{error_prefix}{message}"
|
17 |
-
if e:
|
18 |
-
tb = traceback.format_exc()
|
19 |
-
print(f"--- ERROR ---")
|
20 |
-
print(f"Message: {message}")
|
21 |
-
print(f"Exception Type: {type(e)}")
|
22 |
-
print(f"Exception: {e}")
|
23 |
-
# Avoid printing traceback for simple Warnings like scope changes unless debugging deep
|
24 |
-
if not isinstance(e, Warning):
|
25 |
-
print(f"Traceback:\n{tb}")
|
26 |
-
print(f"-------------")
|
27 |
-
|
28 |
-
# Try to get more details from response if it's a requests error
|
29 |
-
if isinstance(e, requests.exceptions.RequestException) and e.response is not None:
|
30 |
-
try:
|
31 |
-
error_details = e.response.json()
|
32 |
-
details_str = json.dumps(error_details, indent=2)
|
33 |
-
full_message += f"\nStatus Code: {e.response.status_code}\nDetails:\n```json\n{details_str}\n```"
|
34 |
-
except json.JSONDecodeError:
|
35 |
-
full_message += f"\nStatus Code: {e.response.status_code}\nResponse Text:\n```\n{e.response.text}\n```"
|
36 |
-
elif hasattr(e, 'description'): # Handle OAuthLib errors which often have a description
|
37 |
-
full_message += f"\nDetails: {getattr(e, 'description', str(e))}"
|
38 |
-
else:
|
39 |
-
# Display the specific warning/error message directly
|
40 |
-
full_message += f"\nDetails: {str(e)}"
|
41 |
-
else:
|
42 |
-
print(f"Error: {message}") # Log simple message
|
43 |
-
|
44 |
-
# Use Markdown for better formatting in Gradio output
|
45 |
-
# Ensure it's wrapped in a way that Gradio Markdown understands as an error block if possible
|
46 |
-
# Simple red text might be best cross-platform
|
47 |
-
error_html = f"<p style='color: red; white-space: pre-wrap;'>{html.escape(full_message)}</p>"
|
48 |
|
49 |
-
return gr.update(value=error_html, visible=True)
|
50 |
|
51 |
def fetch_org_urn(comm_client_id, comm_token_dict):
|
52 |
"""
|
|
|
4 |
import html
|
5 |
from datetime import datetime, timezone, timedelta # Added timezone, timedelta
|
6 |
import traceback
|
7 |
+
import gradio as gr
|
8 |
+
from error_handling import display_error
|
9 |
|
10 |
API_V2_BASE = 'https://api.linkedin.com/v2'
|
11 |
API_REST_BASE = "https://api.linkedin.com/rest"
|
12 |
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
|
|
15 |
|
16 |
def fetch_org_urn(comm_client_id, comm_token_dict):
|
17 |
"""
|