-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.py
106 lines (84 loc) · 2.82 KB
/
hello.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import streamlit as st
import pandas as pd
from dotenv import load_dotenv
load_dotenv()
from services.splitwise import SplitwiseService
def main():
st.title("Splitwise")
st.write("This is a simple app to send your expenses to Splitwise")
try:
st.write("Logged in with the user: " + SplitwiseService().getUser().getEmail())
show_file_uploader()
except:
st.write("Splitwise credentials non functional")
if st.button("View last expenses"):
expenses_popup()
def show_file_uploader():
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
# Can be used wherever a "file-like" object is accepted:
global data_df
data_df = pd.read_csv(uploaded_file, sep=";")
global uploaded_file_name
uploaded_file_name = uploaded_file.name
show_table()
def show_table():
if "df_value" not in st.session_state:
st.session_state.df_value = data_df
data_df["send_to_splitwise"] = False
try:
data_df.drop(columns=["Credit"], inplace=True)
except:
pass
try:
data_df.drop(columns=["Numero de Carte"], inplace=True)
except:
pass
try:
data_df.drop(columns=["Solde"], inplace=True)
except:
pass
global edited_df
edited_df = st.data_editor(
data_df,
use_container_width=True,
column_config={
"send_to_splitwise": st.column_config.CheckboxColumn(
"Send to Splitwise",
help="Select",
default=False,
)
},
on_change=changed,
disabled=["widgets"],
hide_index=True,
)
btn = st.button("Send", type="primary")
if btn:
to_send = edited_df[edited_df['send_to_splitwise'] == True]
splitwise = SplitwiseService()
for index, row in to_send.iterrows():
try:
expense_id = splitwise.send_to_sw(row)
st.write("Expense sent with id: " + str(expense_id))
except:
st.write("Error sending to splitwise")
if edited_df is not None and not edited_df.equals(st.session_state["df_value"]):
# This will only run if
# 1. Some widget has been changed (including the dataframe editor), triggering a
# script rerun, and
# 2. The new dataframe value is different from the old value
changed()
st.session_state["df_value"] = edited_df
def changed():
edited_df.to_csv('data/' + uploaded_file_name + "_modified")
st.write("Changed!")
@st.dialog("View last expenses", width="large")
def expenses_popup():
st.write(f"List of expenses")
expenses = SplitwiseService().get_latest_expenses()
print(expenses[0])
df = pd.DataFrame(expenses)
st.table(df)
if __name__ == "__main__":
main()