Zai commited on
Commit
a861210
·
1 Parent(s): a43974d

testing presentation

Browse files
Files changed (4) hide show
  1. app.py +5 -1
  2. requirements.txt +9 -1
  3. services.py +4 -1
  4. slide.py +46 -0
app.py CHANGED
@@ -1,11 +1,15 @@
1
  import streamlit as st
2
  import pandas as pd
 
3
 
4
  st.title("Carching Presentation")
 
5
 
6
  uploaded_file = st.file_uploader("Choose an Excel file",type="xlsx")
7
 
8
  if uploaded_file is not None:
9
  df = pd.read_excel(uploaded_file)
10
- st.write(f"here's your url https://docs.google.com/presentation/d/1fgDkE5ODOQNQRMy71kiwvUJ4ZJ63DKncc2uDogyZgkM/edit")
 
11
  st.write(df)
 
 
1
  import streamlit as st
2
  import pandas as pd
3
+ from slide import Slide
4
 
5
  st.title("Carching Presentation")
6
+ slide = Slide()
7
 
8
  uploaded_file = st.file_uploader("Choose an Excel file",type="xlsx")
9
 
10
  if uploaded_file is not None:
11
  df = pd.read_excel(uploaded_file)
12
+ slide_url = slide.create_presentation("Carching Presentation Testing")
13
+ st.write(f"Here's the new slide url {slide_url}")
14
  st.write(df)
15
+
requirements.txt CHANGED
@@ -1,3 +1,11 @@
1
  streamlit
2
  pandas
3
- openpyxl
 
 
 
 
 
 
 
 
 
1
  streamlit
2
  pandas
3
+ openpyxl
4
+
5
+ google-api-python-client
6
+ google-auth
7
+ google-auth-httplib2
8
+ google-auth-oauthlib
9
+ httplib2
10
+ matplotlib
11
+ Pillow
services.py CHANGED
@@ -1,12 +1,15 @@
1
  from google.oauth2.service_account import Credentials
2
  from googleapiclient.discovery import build
3
- from googleapiclient.errors import HttpError
4
 
5
  SCOPES = [
6
  'https://www.googleapis.com/auth/presentations',
7
  'https://www.googleapis.com/auth/drive'
8
  ]
 
9
  SERVICE_ACCOUNT_FILE = './service_account.json'
 
10
  credentials = Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
 
11
  slides_service = build('slides', 'v1', credentials=credentials)
 
12
  drive_service = build('drive', 'v3', credentials=credentials)
 
1
  from google.oauth2.service_account import Credentials
2
  from googleapiclient.discovery import build
 
3
 
4
  SCOPES = [
5
  'https://www.googleapis.com/auth/presentations',
6
  'https://www.googleapis.com/auth/drive'
7
  ]
8
+
9
  SERVICE_ACCOUNT_FILE = './service_account.json'
10
+
11
  credentials = Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
12
+
13
  slides_service = build('slides', 'v1', credentials=credentials)
14
+
15
  drive_service = build('drive', 'v3', credentials=credentials)
slide.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from googleapiclient.errors import HttpError
2
+
3
+ from services import drive_service,slides_service
4
+
5
+ class Slide:
6
+ def __init__(self):
7
+ self.template_id = "1fgDkE5ODOQNQRMy71kiwvUJ4ZJ63DKncc2uDogyZgkM"
8
+ self.presentation_id = "1fgDkE5ODOQNQRMy71kiwvUJ4ZJ63DKncc2uDogyZgkM"
9
+
10
+ def create_presentation(self, title="New Presentation"):
11
+ try:
12
+ print("Cloning the template...")
13
+
14
+ # Step 1: Clone the template
15
+ copy = drive_service.files().copy(
16
+ fileId=self.template_id,
17
+ body={"name": title}
18
+ ).execute()
19
+
20
+ presentation_id = copy['id']
21
+ print(f"Presentation created with ID: {presentation_id}")
22
+
23
+ # Step 2: Add edit permission to the specified email
24
+ print("Adding edit permission to zai.carching@gmail.com...")
25
+ permission = {
26
+ "type": "user",
27
+ "role": "writer",
28
+ "emailAddress": "zai.carching@gmail.com"
29
+ }
30
+ drive_service.permissions().create(
31
+ fileId=presentation_id,
32
+ body=permission,
33
+ fields="id"
34
+ ).execute()
35
+
36
+ # Step 3: Log the URL
37
+ presentation_url = f"https://docs.google.com/presentation/d/{presentation_id}/edit"
38
+ print(f"Presentation URL: {presentation_url}")
39
+
40
+ self.presentation_id = presentation_id
41
+
42
+ return presentation_url
43
+
44
+ except HttpError as error:
45
+ print(f"An error occurred: {error}")
46
+ return None