siddhartharyaai commited on
Commit
8b37015
Β·
verified Β·
1 Parent(s): 537359f

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +79 -0
  2. saved_lists.json +1 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ client = gspread.authorize(creds)
30
+ sheet = client.open_by_url("https://docs.google.com/spreadsheets/d/1bYRrOokZ_D85fj_0bbByc6dfaxW50Hj2PqDRG_r25yU")
31
+ return sheet.worksheet(SHEET_NAME)
32
+
33
+ sheet = get_sheet()
34
+
35
+ # Ticking contacts
36
+ st.markdown("### βœ… Tick Contacts to Save in a List")
37
+ selected_contacts = st.multiselect("Select contacts", contacts_df["display_name"].tolist())
38
+
39
+ list_name = st.text_input("πŸ“ Name this list")
40
+ tags_input = st.text_input("🏷 Optional tags (comma-separated)")
41
+
42
+ if st.button("πŸ’Ύ Save List to Google Sheet"):
43
+ if not list_name:
44
+ st.warning("Please enter a list name.")
45
+ elif not selected_contacts:
46
+ st.warning("Please select at least one contact.")
47
+ else:
48
+ contact_csv = ",".join(selected_contacts)
49
+ tags = tags_input.strip()
50
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
51
+ sheet.append_row([list_name, contact_csv, tags, timestamp])
52
+ st.success(f"List '{list_name}' saved successfully!")
53
+
54
+ # Load and manage saved lists
55
+ st.markdown("---")
56
+ st.markdown("### πŸ“‚ Load or Manage Saved Lists")
57
+
58
+ saved_lists = sheet.get_all_records()
59
+ if saved_lists:
60
+ list_names = [entry["list_name"] for entry in saved_lists]
61
+ selected_list_name = st.selectbox("πŸ“œ Select a list", list_names)
62
+
63
+ if selected_list_name:
64
+ entry = next((x for x in saved_lists if x["list_name"] == selected_list_name), None)
65
+ if entry:
66
+ st.markdown(f"**List Name:** {entry['list_name']}")
67
+ st.markdown(f"**Contacts:** {entry['contacts_csv']}")
68
+ st.markdown(f"**Tags:** {entry['tags']}")
69
+ st.markdown(f"**Saved on:** {entry['timestamp']}")
70
+
71
+ # Delete
72
+ if st.button("πŸ—‘ Delete this list"):
73
+ all_values = sheet.get_all_values()
74
+ headers = all_values[0]
75
+ for idx, row in enumerate(all_values[1:], start=2):
76
+ if row[0] == selected_list_name:
77
+ sheet.delete_rows(idx)
78
+ st.success("List deleted. Please refresh.")
79
+ st.stop()
saved_lists.json ADDED
@@ -0,0 +1 @@
 
 
1
+ []