Spaces:
Sleeping
Sleeping
poemsforaphrodite
commited on
Commit
•
9f7dd1f
1
Parent(s):
f1307a4
Update app.py
Browse files
app.py
CHANGED
@@ -329,7 +329,7 @@ def google_auth(client_config):
|
|
329 |
return flow, auth_url
|
330 |
|
331 |
def auth_search_console(client_config, credentials):
|
332 |
-
logging.info("Authenticating with Google Search Console")
|
333 |
token = {
|
334 |
"token": credentials.token,
|
335 |
"refresh_token": credentials.refresh_token,
|
@@ -339,7 +339,7 @@ def auth_search_console(client_config, credentials):
|
|
339 |
"scopes": credentials.scopes,
|
340 |
"id_token": getattr(credentials, "id_token", None),
|
341 |
}
|
342 |
-
logging.info("Google Search Console authenticated")
|
343 |
return searchconsole.authenticate(client_config=client_config, credentials=token)
|
344 |
|
345 |
# -------------
|
@@ -355,7 +355,7 @@ def list_gsc_properties(credentials):
|
|
355 |
return properties
|
356 |
|
357 |
def fetch_gsc_data(webproperty, search_type, start_date, end_date, dimensions, device_type=None):
|
358 |
-
logging.info(f"Fetching GSC data for property: {webproperty}, search_type: {search_type}, date_range: {start_date} to {end_date}, dimensions: {dimensions}, device_type: {device_type}")
|
359 |
query = webproperty.query.range(start_date, end_date).search_type(search_type).dimension(*dimensions)
|
360 |
if 'device' in dimensions and device_type and device_type != 'All Devices':
|
361 |
query = query.filter('device', 'equals', device_type.lower())
|
@@ -406,11 +406,11 @@ def calculate_relevancy_scores(df, model_type):
|
|
406 |
# -------------
|
407 |
|
408 |
def update_dimensions(selected_search_type):
|
409 |
-
|
410 |
return BASE_DIMENSIONS + ['device'] if selected_search_type in SEARCH_TYPES else BASE_DIMENSIONS
|
411 |
|
412 |
def calc_date_range(selection, custom_start=None, custom_end=None):
|
413 |
-
|
414 |
range_map = {
|
415 |
'Last 7 Days': 7,
|
416 |
'Last 30 Days': 30,
|
@@ -428,7 +428,7 @@ def calc_date_range(selection, custom_start=None, custom_end=None):
|
|
428 |
logging.debug("Defaulting custom date range to last 7 days")
|
429 |
return today - datetime.timedelta(days=7), today
|
430 |
date_range = today - datetime.timedelta(days=range_map.get(selection, 0)), today
|
431 |
-
logging.debug(f"Date range calculated: {date_range}")
|
432 |
return date_range
|
433 |
|
434 |
def show_error(e):
|
@@ -436,7 +436,7 @@ def show_error(e):
|
|
436 |
st.error(f"An error occurred: {e}")
|
437 |
|
438 |
def property_change():
|
439 |
-
logging.info(f"Property changed to: {st.session_state['selected_property_selector']}")
|
440 |
st.session_state.selected_property = st.session_state['selected_property_selector']
|
441 |
|
442 |
# -------------
|
|
|
329 |
return flow, auth_url
|
330 |
|
331 |
def auth_search_console(client_config, credentials):
|
332 |
+
#logging.info("Authenticating with Google Search Console")
|
333 |
token = {
|
334 |
"token": credentials.token,
|
335 |
"refresh_token": credentials.refresh_token,
|
|
|
339 |
"scopes": credentials.scopes,
|
340 |
"id_token": getattr(credentials, "id_token", None),
|
341 |
}
|
342 |
+
#logging.info("Google Search Console authenticated")
|
343 |
return searchconsole.authenticate(client_config=client_config, credentials=token)
|
344 |
|
345 |
# -------------
|
|
|
355 |
return properties
|
356 |
|
357 |
def fetch_gsc_data(webproperty, search_type, start_date, end_date, dimensions, device_type=None):
|
358 |
+
#logging.info(f"Fetching GSC data for property: {webproperty}, search_type: {search_type}, date_range: {start_date} to {end_date}, dimensions: {dimensions}, device_type: {device_type}")
|
359 |
query = webproperty.query.range(start_date, end_date).search_type(search_type).dimension(*dimensions)
|
360 |
if 'device' in dimensions and device_type and device_type != 'All Devices':
|
361 |
query = query.filter('device', 'equals', device_type.lower())
|
|
|
406 |
# -------------
|
407 |
|
408 |
def update_dimensions(selected_search_type):
|
409 |
+
# logging.debug(f"Updating dimensions for search type: {selected_search_type}")
|
410 |
return BASE_DIMENSIONS + ['device'] if selected_search_type in SEARCH_TYPES else BASE_DIMENSIONS
|
411 |
|
412 |
def calc_date_range(selection, custom_start=None, custom_end=None):
|
413 |
+
# logging.debug(f"Calculating date range for selection: {selection}")
|
414 |
range_map = {
|
415 |
'Last 7 Days': 7,
|
416 |
'Last 30 Days': 30,
|
|
|
428 |
logging.debug("Defaulting custom date range to last 7 days")
|
429 |
return today - datetime.timedelta(days=7), today
|
430 |
date_range = today - datetime.timedelta(days=range_map.get(selection, 0)), today
|
431 |
+
#logging.debug(f"Date range calculated: {date_range}")
|
432 |
return date_range
|
433 |
|
434 |
def show_error(e):
|
|
|
436 |
st.error(f"An error occurred: {e}")
|
437 |
|
438 |
def property_change():
|
439 |
+
#logging.info(f"Property changed to: {st.session_state['selected_property_selector']}")
|
440 |
st.session_state.selected_property = st.session_state['selected_property_selector']
|
441 |
|
442 |
# -------------
|