Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,80 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import gspread
|
| 4 |
-
from oauth2client.service_account import ServiceAccountCredentials
|
| 5 |
-
from datetime import datetime
|
| 6 |
-
|
| 7 |
-
st.set_page_config(page_title="Skype Contact Manager", layout="wide")
|
| 8 |
-
st.title("π Skype Contacts: Saved Lists")
|
| 9 |
-
|
| 10 |
-
CONTACTS_FILE = "contacts.xlsx"
|
| 11 |
-
CREDS_FILE = "saved_lists_creds.json"
|
| 12 |
-
SHEET_NAME = "saved_lists"
|
| 13 |
-
|
| 14 |
-
# Load contacts
|
| 15 |
-
@st.cache_data
|
| 16 |
-
def load_contacts():
|
| 17 |
-
df = pd.read_excel(CONTACTS_FILE)
|
| 18 |
-
df = df[["display_name", "profile.locations[0].country"]].copy()
|
| 19 |
-
df.columns = ["display_name", "country"]
|
| 20 |
-
return df
|
| 21 |
-
|
| 22 |
-
contacts_df = load_contacts()
|
| 23 |
-
|
| 24 |
-
# Google Sheets setup
|
| 25 |
-
@st.cache_resource
|
| 26 |
-
def get_sheet():
|
| 27 |
-
scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
|
| 28 |
-
creds = ServiceAccountCredentials.from_json_keyfile_name(CREDS_FILE, scope)
|
| 29 |
-
st.write("π Using service account:", creds.service_account_email)
|
| 30 |
-
client = gspread.authorize(creds)
|
| 31 |
-
sheet = client.open_by_url("https://docs.google.com/spreadsheets/d/1bYRrOokZ_D85fj_0bbByc6dfaxW50Hj2PqDRG_r25yU")
|
| 32 |
-
return sheet.worksheet(SHEET_NAME)
|
| 33 |
-
|
| 34 |
-
sheet = get_sheet()
|
| 35 |
-
|
| 36 |
-
# Ticking contacts
|
| 37 |
-
st.markdown("### β
Tick Contacts to Save in a List")
|
| 38 |
-
selected_contacts = st.multiselect("Select contacts", contacts_df["display_name"].tolist())
|
| 39 |
-
|
| 40 |
-
list_name = st.text_input("π Name this list")
|
| 41 |
-
tags_input = st.text_input("π· Optional tags (comma-separated)")
|
| 42 |
-
|
| 43 |
-
if st.button("πΎ Save List to Google Sheet"):
|
| 44 |
-
if not list_name:
|
| 45 |
-
st.warning("Please enter a list name.")
|
| 46 |
-
elif not selected_contacts:
|
| 47 |
-
st.warning("Please select at least one contact.")
|
| 48 |
-
else:
|
| 49 |
-
contact_csv = ",".join(selected_contacts)
|
| 50 |
-
tags = tags_input.strip()
|
| 51 |
-
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 52 |
-
sheet.append_row([list_name, contact_csv, tags, timestamp])
|
| 53 |
-
st.success(f"List '{list_name}' saved successfully!")
|
| 54 |
-
|
| 55 |
-
# Load and manage saved lists
|
| 56 |
-
st.markdown("---")
|
| 57 |
-
st.markdown("### π Load or Manage Saved Lists")
|
| 58 |
-
|
| 59 |
-
saved_lists = sheet.get_all_records()
|
| 60 |
-
if saved_lists:
|
| 61 |
-
list_names = [entry["list_name"] for entry in saved_lists]
|
| 62 |
-
selected_list_name = st.selectbox("π Select a list", list_names)
|
| 63 |
-
|
| 64 |
-
if selected_list_name:
|
| 65 |
-
entry = next((x for x in saved_lists if x["list_name"] == selected_list_name), None)
|
| 66 |
-
if entry:
|
| 67 |
-
st.markdown(f"**List Name:** {entry['list_name']}")
|
| 68 |
-
st.markdown(f"**Contacts:** {entry['contacts_csv']}")
|
| 69 |
-
st.markdown(f"**Tags:** {entry['tags']}")
|
| 70 |
-
st.markdown(f"**Saved on:** {entry['timestamp']}")
|
| 71 |
-
|
| 72 |
-
# Delete
|
| 73 |
-
if st.button("π Delete this list"):
|
| 74 |
-
all_values = sheet.get_all_values()
|
| 75 |
-
headers = all_values[0]
|
| 76 |
-
for idx, row in enumerate(all_values[1:], start=2):
|
| 77 |
-
if row[0] == selected_list_name:
|
| 78 |
-
sheet.delete_rows(idx)
|
| 79 |
-
st.success("List deleted. Please refresh.")
|
| 80 |
-
st.stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|