Spaces:
Sleeping
Sleeping
Commit
·
571c30b
1
Parent(s):
32c7a53
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,9 @@ import hashlib
|
|
3 |
from time import strftime, gmtime
|
4 |
import streamlit as st
|
5 |
from datetime import datetime, timedelta
|
6 |
-
import pandas as pd
|
|
|
|
|
7 |
|
8 |
# Function to fetch data from ShareASale
|
9 |
def fetch_shareasale_data(action_verb, affiliate_id, api_token, api_secret_key, api_version=1.4):
|
@@ -26,11 +28,16 @@ def fetch_shareasale_data(action_verb, affiliate_id, api_token, api_secret_key,
|
|
26 |
call = request.Request(f'https://shareasale.com/x.cfm?{data}', headers=my_headers)
|
27 |
|
28 |
try:
|
29 |
-
return_result = request.urlopen(call).read()
|
30 |
return return_result
|
31 |
except Exception as inst:
|
32 |
return str(inst)
|
33 |
|
|
|
|
|
|
|
|
|
|
|
34 |
# Streamlit UI
|
35 |
st.title("Affiliate Earnings Dashboard")
|
36 |
st.sidebar.title("Settings")
|
@@ -50,10 +57,8 @@ if st.sidebar.button("Fetch Data"):
|
|
50 |
action_verb = 'ledger'
|
51 |
ledger_data = fetch_shareasale_data(action_verb, my_affiliate_id, api_token, api_secret_key)
|
52 |
|
53 |
-
#
|
54 |
-
|
55 |
-
# ledger_data_df = some_parsing_function(ledger_data)
|
56 |
|
57 |
-
# Display
|
58 |
-
|
59 |
-
st.write("Replace this line with the parsed table data using st.table")
|
|
|
3 |
from time import strftime, gmtime
|
4 |
import streamlit as st
|
5 |
from datetime import datetime, timedelta
|
6 |
+
import pandas as pd
|
7 |
+
import csv
|
8 |
+
from io import StringIO
|
9 |
|
10 |
# Function to fetch data from ShareASale
|
11 |
def fetch_shareasale_data(action_verb, affiliate_id, api_token, api_secret_key, api_version=1.4):
|
|
|
28 |
call = request.Request(f'https://shareasale.com/x.cfm?{data}', headers=my_headers)
|
29 |
|
30 |
try:
|
31 |
+
return_result = request.urlopen(call).read().decode('utf-8')
|
32 |
return return_result
|
33 |
except Exception as inst:
|
34 |
return str(inst)
|
35 |
|
36 |
+
# Parse CSV data to a Pandas DataFrame
|
37 |
+
def parse_csv_to_df(csv_data):
|
38 |
+
csv_stream = StringIO(csv_data)
|
39 |
+
return pd.read_csv(csv_stream, delimiter='|')
|
40 |
+
|
41 |
# Streamlit UI
|
42 |
st.title("Affiliate Earnings Dashboard")
|
43 |
st.sidebar.title("Settings")
|
|
|
57 |
action_verb = 'ledger'
|
58 |
ledger_data = fetch_shareasale_data(action_verb, my_affiliate_id, api_token, api_secret_key)
|
59 |
|
60 |
+
# Parse the CSV data into a DataFrame
|
61 |
+
df = parse_csv_to_df(ledger_data)
|
|
|
62 |
|
63 |
+
# Display the DataFrame as a table
|
64 |
+
st.write(df)
|
|