Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,10 +20,8 @@ authorization_url, state = google_oauth.authorization_url(AUTHORIZATION_BASE_URL
|
|
20 |
|
21 |
# Streamlit UI
|
22 |
st.title("Search Analytics Viewer")
|
23 |
-
site_url = st.text_input("Enter your website URL:", "https://www.example.com")
|
24 |
-
start_date = st.date_input("Start Date")
|
25 |
-
end_date = st.date_input("End Date")
|
26 |
|
|
|
27 |
if st.button("Authenticate with Google"):
|
28 |
st.write("Please authenticate with Google:", authorization_url)
|
29 |
|
@@ -35,16 +33,29 @@ if st.button("Authenticate with Google"):
|
|
35 |
credentials = google_oauth.credentials
|
36 |
service = build('webmasters', 'v3', credentials=credentials)
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# Streamlit UI
|
22 |
st.title("Search Analytics Viewer")
|
|
|
|
|
|
|
23 |
|
24 |
+
# Authenticate with Google
|
25 |
if st.button("Authenticate with Google"):
|
26 |
st.write("Please authenticate with Google:", authorization_url)
|
27 |
|
|
|
33 |
credentials = google_oauth.credentials
|
34 |
service = build('webmasters', 'v3', credentials=credentials)
|
35 |
|
36 |
+
# Fetch list of available domains
|
37 |
+
domains_request = service.sites().list().execute()
|
38 |
+
available_domains = [site['siteUrl'] for site in domains_request.get('siteEntry', [])]
|
39 |
+
|
40 |
+
# Dropdown field for selecting domain
|
41 |
+
selected_domain = st.selectbox("Select Domain:", available_domains)
|
42 |
+
|
43 |
+
# Date inputs
|
44 |
+
start_date = st.date_input("Start Date")
|
45 |
+
end_date = st.date_input("End Date")
|
46 |
+
|
47 |
+
# Fetch data for selected domain
|
48 |
+
if st.button("Fetch Data"):
|
49 |
+
request = {
|
50 |
+
'startDate': start_date.strftime("%Y-%m-%d"),
|
51 |
+
'endDate': end_date.strftime("%Y-%m-%d"),
|
52 |
+
'dimensions': ['query', 'page'],
|
53 |
+
'siteUrl': selected_domain
|
54 |
+
}
|
55 |
+
response = service.searchanalytics().query(siteUrl=request['siteUrl'], body=request).execute()
|
56 |
+
|
57 |
+
# Display Search Analytics Data (Customize this!)
|
58 |
+
if 'rows' in response:
|
59 |
+
st.dataframe(response['rows'])
|
60 |
+
else:
|
61 |
+
st.write('No data found')
|