RoversX commited on
Commit
6d01669
1 Parent(s): a37c4af

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import streamlit as st
3
+
4
+ # Set page configuration with a title and layout
5
+ st.set_page_config(page_title="Umami Data Processing", layout="wide")
6
+
7
+ # Display the main title of the application
8
+ st.title("Importing CSVs from Umami Cloud to Self-Hosted Umami Data Processing Online")
9
+
10
+ # Provide a link to a tutorial for more detailed instructions
11
+ st.markdown("""
12
+ For detailed instructions on how to use this tool, please visit [myblog](https://blog.closex.org/posts/29bdb155/) or .
13
+ """)
14
+
15
+ # Widget to upload the CSV file
16
+ uploaded_file = st.file_uploader("Choose a CSV file", type=['csv'])
17
+
18
+ # Text input for new website ID
19
+ new_website_id = st.text_input("Enter the new website ID:")
20
+
21
+ if uploaded_file is not None and new_website_id:
22
+ # Load the CSV file
23
+ df = pd.read_csv(uploaded_file)
24
+
25
+ # Update the website_id column with the user-provided website ID
26
+ df['website_id'] = new_website_id
27
+
28
+ # Define the columns for the website_event table
29
+ website_event_columns = [
30
+ 'event_id', 'website_id', 'session_id', 'created_at', 'url_path',
31
+ 'url_query', 'referrer_path', 'referrer_query', 'referrer_domain',
32
+ 'page_title', 'event_type', 'event_name', 'visit_id'
33
+ ]
34
+
35
+ # Create DataFrame for website_event data
36
+ df_website_event = df[website_event_columns]
37
+ df_website_event.to_csv('website_event.csv', index=False)
38
+ st.download_button(label="Download Website Event CSV", data=df_website_event.to_csv(index=False), file_name='website_event.csv', mime='text/csv')
39
+
40
+ # Define the columns for the session table
41
+ session_columns = [
42
+ 'session_id', 'website_id', 'hostname', 'browser', 'os', 'device',
43
+ 'screen', 'language', 'country', 'subdivision1', 'subdivision2',
44
+ 'city', 'created_at'
45
+ ]
46
+
47
+ # Create DataFrame for session data
48
+ df_session = df[session_columns]
49
+ df_session.to_csv('session.csv', index=False)
50
+ st.download_button(label="Download Session CSV", data=df_session.to_csv(index=False), file_name='session.csv', mime='text/csv')
51
+
52
+ st.success("Successfully generated website_event.csv and session.csv")