File size: 2,179 Bytes
6d01669
 
 
 
 
 
 
3921171
 
dad4ce6
6d01669
 
 
3921171
6d01669
 
 
82b6302
6d01669
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pandas as pd
import streamlit as st

# Set page configuration with a title and layout
st.set_page_config(page_title="Umami Data Processing", layout="wide")

# Display the main title of the application
st.title("Umami Data Processing")

st.subheader('Importing CSVs from Umami Cloud to Self-Hosted Umami Data Processing Online')

# Provide a link to a tutorial for more detailed instructions
st.markdown("""
For detailed instructions on how to use this tool, please visit [myblog](https://blog.closex.org/posts/29bdb155/) or [Youtube Video]().
""")

# Widget to upload the CSV file
uploaded_file = st.file_uploader("Choose an Umami Cloud CSV file", type=['csv'])

# Text input for new website ID
new_website_id = st.text_input("Enter the new website ID:")

if uploaded_file is not None and new_website_id:
    # Load the CSV file
    df = pd.read_csv(uploaded_file)

    # Update the website_id column with the user-provided website ID
    df['website_id'] = new_website_id

    # Define the columns for the website_event table
    website_event_columns = [
        'event_id', 'website_id', 'session_id', 'created_at', 'url_path',
        'url_query', 'referrer_path', 'referrer_query', 'referrer_domain',
        'page_title', 'event_type', 'event_name', 'visit_id'
    ]

    # Create DataFrame for website_event data
    df_website_event = df[website_event_columns]
    df_website_event.to_csv('website_event.csv', index=False)
    st.download_button(label="Download Website Event CSV", data=df_website_event.to_csv(index=False), file_name='website_event.csv', mime='text/csv')

    # Define the columns for the session table
    session_columns = [
        'session_id', 'website_id', 'hostname', 'browser', 'os', 'device',
        'screen', 'language', 'country', 'subdivision1', 'subdivision2',
        'city', 'created_at'
    ]

    # Create DataFrame for session data
    df_session = df[session_columns]
    df_session.to_csv('session.csv', index=False)
    st.download_button(label="Download Session CSV", data=df_session.to_csv(index=False), file_name='session.csv', mime='text/csv')

    st.success("Successfully generated website_event.csv and session.csv")