Spaces:
Sleeping
Sleeping
Add app.py
Browse files- app.py +139 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: Appointlet2GS.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['iface', 'Appointlet', 'GoogleSheets', 'run']
|
5 |
+
|
6 |
+
# %% Appointlet2GS.ipynb 0
|
7 |
+
from selenium import webdriver
|
8 |
+
from selenium.webdriver.chrome.service import Service as ChromeService
|
9 |
+
from selenium.webdriver.chrome.options import Options
|
10 |
+
from webdriver_manager.chrome import ChromeDriverManager
|
11 |
+
from selenium.webdriver.common.by import By
|
12 |
+
import time
|
13 |
+
import os
|
14 |
+
import gspread
|
15 |
+
import pandas as pd
|
16 |
+
from pathlib import Path
|
17 |
+
import gradio as gr
|
18 |
+
|
19 |
+
# %% Appointlet2GS.ipynb 1
|
20 |
+
class Appointlet():
|
21 |
+
def __init__(self, url = 'https://app.appointlet.com/unified_login'):
|
22 |
+
self.url = url
|
23 |
+
|
24 |
+
def setup(self):
|
25 |
+
options = Options()
|
26 |
+
options.add_argument('--incognito')
|
27 |
+
options.add_argument("--headless")
|
28 |
+
service = ChromeService(ChromeDriverManager().install())
|
29 |
+
driver = webdriver.Chrome(options=options, service=service)
|
30 |
+
driver.maximize_window()
|
31 |
+
return driver
|
32 |
+
|
33 |
+
|
34 |
+
def download(self, account):
|
35 |
+
email, password = open(account, 'r').read().splitlines()
|
36 |
+
driver = self.setup()
|
37 |
+
driver.get(url=self.url)
|
38 |
+
driver.implicitly_wait(30)
|
39 |
+
|
40 |
+
# input email
|
41 |
+
driver.find_element(By.CSS_SELECTOR, "input[name='email']").send_keys(email)
|
42 |
+
driver.find_element(By.CSS_SELECTOR, 'button.mt-16').click()
|
43 |
+
|
44 |
+
# input password
|
45 |
+
driver.find_element(By.CSS_SELECTOR, "input[name='password']").send_keys(password)
|
46 |
+
driver.find_element(By.CSS_SELECTOR, 'button.mt-16').click()
|
47 |
+
|
48 |
+
# remove welcome message
|
49 |
+
try:
|
50 |
+
driver.find_element(By.CSS_SELECTOR, 'button.btn-block').click()
|
51 |
+
except:
|
52 |
+
pass
|
53 |
+
|
54 |
+
# remove introduction
|
55 |
+
try:
|
56 |
+
driver.find_element(By.CSS_SELECTOR, 'button.shepherd-cancel-icon').click()
|
57 |
+
except:
|
58 |
+
pass
|
59 |
+
|
60 |
+
# Meeting filter
|
61 |
+
# Launch meeting filter
|
62 |
+
driver.find_element(By.ID, 'MeetingFilters').click()
|
63 |
+
# # Filter by meeting types
|
64 |
+
# driver.find_element(By.CSS_SELECTOR, 'svg.css-8mmkcg').click()
|
65 |
+
# driver.find_element(By.XPATH, '//div[contains(text(), "Example Meeting")]').click()
|
66 |
+
# Filter by status
|
67 |
+
driver.find_element(By.CSS_SELECTOR, "input[name='isPending']").click()
|
68 |
+
# Apply filters
|
69 |
+
driver.find_element(By.XPATH, '//span[contains(text(), "Apply Filters")]').click()
|
70 |
+
|
71 |
+
# Download csv file
|
72 |
+
driver.find_element(By.CSS_SELECTOR, "div.MoreButton.dropdown > button[class='dropdown-toggle btn btn-outline-secondary']").click()
|
73 |
+
driver.find_element(By.XPATH, '//span[contains(text(), "Export Attendees (CSV)")]').click()
|
74 |
+
|
75 |
+
# Close the browser windows and ends the WebDriver session
|
76 |
+
time.sleep(5)
|
77 |
+
driver.quit()
|
78 |
+
|
79 |
+
|
80 |
+
# %% Appointlet2GS.ipynb 2
|
81 |
+
class GoogleSheets():
|
82 |
+
# def __init__(self, creds_file = 'credentials.json', sh_file = 'googlesheet_info.txt'):
|
83 |
+
def __init__(self, creds_file, sh_file):
|
84 |
+
self.creds = creds_file
|
85 |
+
self.sh = sh_file
|
86 |
+
self.folder = '.'
|
87 |
+
|
88 |
+
def get_sheet_info(self):
|
89 |
+
sh_id, wk_name = open(self.sh, 'r').read().splitlines()
|
90 |
+
return sh_id, wk_name
|
91 |
+
|
92 |
+
def read_csv(self):
|
93 |
+
# read the downoaded csv file into dataframe and remove the file
|
94 |
+
for fn in os.listdir(self.folder):
|
95 |
+
if fn.find('Meeting Attendees') != -1:
|
96 |
+
file = os.path.join(self.folder, fn)
|
97 |
+
df = pd.read_csv(file, low_memory=False)
|
98 |
+
df = df.fillna('')
|
99 |
+
os.remove(file)
|
100 |
+
return df
|
101 |
+
|
102 |
+
def update_worksheet(self):
|
103 |
+
# Setup service account
|
104 |
+
sh_id, wk_name = self.get_sheet_info()
|
105 |
+
gc = gspread.service_account(filename=self.creds)
|
106 |
+
|
107 |
+
# Open a sheet from a spreadsheet
|
108 |
+
wk = gc.open_by_key(sh_id).worksheet(wk_name)
|
109 |
+
|
110 |
+
# Clear the worksheet
|
111 |
+
wk.clear()
|
112 |
+
|
113 |
+
# Get the new data
|
114 |
+
df = self.read_csv()
|
115 |
+
|
116 |
+
# Writing the new data to Google Sheets
|
117 |
+
wk.update([df.columns.values.tolist()] + df.values.tolist())
|
118 |
+
|
119 |
+
|
120 |
+
# %% Appointlet2GS.ipynb 3
|
121 |
+
def run(account, creds_file, sh_file):
|
122 |
+
if not account:
|
123 |
+
return 'Please upload an account file'
|
124 |
+
else:
|
125 |
+
Appointlet().download(account.name)
|
126 |
+
# Appointlet().download(account)
|
127 |
+
GoogleSheets(creds_file.name, sh_file.name).update_worksheet()
|
128 |
+
return 'Update Google Sheets completed!'
|
129 |
+
|
130 |
+
# %% Appointlet2GS.ipynb 6
|
131 |
+
iface = gr.Interface(fn=run,
|
132 |
+
inputs=[gr.File(label='Account File'),
|
133 |
+
gr.File(label='Credentials Json File'),
|
134 |
+
gr.File(label='Googlesheet Info')],
|
135 |
+
outputs=gr.Text(),
|
136 |
+
allow_flagging='never',
|
137 |
+
title='Appointlet2GS Application',
|
138 |
+
description='Download Meeting Attendees file From Appointlet and upload it to Google Sheets')
|
139 |
+
iface.launch(height=450, width=500)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
selenium
|
2 |
+
webdriver_manager
|
3 |
+
gspread
|
4 |
+
pandas
|