ming 3 سال پیش
والد
کامیت
28a3a62301
2فایلهای تغییر یافته به همراه150 افزوده شده و 0 حذف شده
  1. 138 0
      api/gSlide.py
  2. 12 0
      api/spread2.json

+ 138 - 0
api/gSlide.py

@@ -0,0 +1,138 @@
+
+
+from __future__ import print_function
+import os.path
+from googleapiclient.discovery import build
+from google_auth_oauthlib.flow import InstalledAppFlow
+from google.auth.transport.requests import Request
+from google.oauth2.credentials import Credentials
+from google.oauth2 import service_account
+import argparse
+import requests
+import pprint
+import json
+import calendar
+import time
+import os
+import shutil
+from distutils.util import strtobool
+
+# If modifying these scopes, delete the file token.json.
+SCOPES = ['https://www.googleapis.com/auth/presentations.readonly',
+          'https://www.googleapis.com/auth/drive.metadata.readonly']
+
+def main(PRESENTATION_ID, save_to_local,eng):
+
+    credentials = service_account.Credentials.from_service_account_file('spread2.json')
+    scoped_credentials = credentials.with_scopes(SCOPES)
+    creds = credentials
+
+    notes_list=[]
+    sub_title_list=[]
+    img_list=[]
+
+    def save_to_img(name, url): 
+        with open(name, 'wb') as handle:
+            response = requests.get(url, stream=True)
+
+            if not response.ok:
+                print(response)
+
+            for block in response.iter_content(1024):
+                if not block:
+                    break
+
+                handle.write(block)
+        print('\t----> save to',name)
+    
+    
+    def slide_info(PRESENTATION_ID):
+        service = build('slides', 'v1', credentials=creds)
+        # Call the Slides API
+        presentation = service.presentations().get(
+            presentationId=PRESENTATION_ID).execute()
+        slides = presentation.get('slides')
+        
+        # Create the directory
+        if save_to_local:
+            dir = presentation['title']
+            if os.path.exists(dir):
+                shutil.rmtree(dir)
+            os.makedirs(dir)
+        
+        
+        print('The presentation contains {} slides:'.format(len(slides)))
+        for i, slide in enumerate(slides):
+            print('-'*80)
+            print('Page #', i, ' ',slide['objectId'])
+
+            # Check if the notes exists
+            if 'text' in slide['slideProperties']['notesPage']['pageElements'][1]['shape'].keys():
+                
+                notes = slide['slideProperties']['notesPage']['pageElements'][1]['shape']['text']['textElements'][1]['textRun']['content']
+                
+                # Check if the sub_title exists
+                print(notes)
+                print('[sub_title]' in notes)
+                if '[sub_title]' in notes:
+                    sub_title = notes.split('[sub_title]')[1].strip()
+                    print('Sub_title:',end='')
+                    pprint.pprint(sub_title)
+                    sub_title_list.append(sub_title)
+                    
+                    # save to local txt file
+                    if '[sub_title]' in notes:
+                        with open('./'+dir+'/'+presentation['title']+'_sub_title_'+str(i+1)+'.txt', "w") as text_file:
+                            text_file.write(sub_title)
+                        print('\t----> save to',presentation['title']+'_sub_title_'+str(i+1)+'.txt')
+                        
+                    notes = notes.split('[sub_title]')[0].strip()
+                
+                print('Notes:',end='')
+                pprint.pprint(notes)
+                notes_list.append(notes)
+                    
+                # save to local txt file
+                if save_to_local:
+                    with open('./'+dir+'/'+presentation['title']+'_lines_'+str(i+1)+'.txt', "w") as text_file:
+                        text_file.write(notes)
+                    print('\t----> save to',presentation['title']+'_lines_'+str(i+1)+'.txt')
+                    
+            else:
+                notes_list.append("")
+                
+            # Convert the content of the presentation to png
+            thumbnail = service.presentations().pages().getThumbnail(presentationId=PRESENTATION_ID, pageObjectId=slide['objectId']).execute()
+            pprint.pprint(thumbnail)
+            img_list.append(thumbnail['contentUrl'])
+            
+            # save to local img file
+            if save_to_local:
+                save_to_img('./'+dir+'/'+presentation['title']+'_'+str(i+1)+'.png',thumbnail['contentUrl'])
+            
+            
+        # data
+        my_data = { "name": presentation['title'], "text_content": notes_list, "image_urls": img_list, "avatar": "7", "client_id": calendar.timegm(time.gmtime()) }
+        if eng:
+            my_data['sub_titles'] = sub_title_list
+        
+        
+        
+        # headers
+        my_headers = {'accept': 'application/json',
+                      'Content-Type': 'application/json; charset=UTF-8'}
+        
+        # Serializing json   
+        json_object = json.dumps(my_data, indent = 4)
+        
+        
+        # post
+        if eng:
+            r = requests.post('http://www.choozmo.com:8888/make_anchor_video_eng', data = json_object, headers = my_headers)
+        else:
+            r = requests.post('http://www.choozmo.com:8888/make_anchor_video_v2', data = json_object, headers = my_headers)
+        print(r)
+        
+
+    slide_info(PRESENTATION_ID)
+    

+ 12 - 0
api/spread2.json

@@ -0,0 +1,12 @@
+{
+  "type": "service_account",
+  "project_id": "dstest-1-292707",
+  "private_key_id": "41b3cec48b4af2e91b89cf6c1644b2fbdf603a72",
+  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC47O9j5gNkeWsY\n7XsBwl08z/pLNKrKPq8zYoI2tlnctHAOowjSkwXRAuERUeY+O4cRn8HNRqtnZ5M/\nt3kLEtmQpQClk7A8pv21bo4lT8nILZLWU1ovo3bzFNaBN7I/1PNUzSm8G5w4aUSy\noO2/beQLoz0gs1e1WlLAQVkS4NvUFagP/nY3sAgW/1mZSeNsHk8x8VLc1t6rIlSl\n9wPQ52KBCTUUu6gveQ5nzpOZ3eNxr+ftllF378tt/tzCqFdI0DkYYv7jxSAfXa+y\nmlHoSE8mhd+M4hvrf4E5jjvdfyNmALiBpyEW2YAMe1qK0Ay3aUodZxSIKCU8FYo2\njIVCBxTtAgMBAAECggEAVUdafECx1s9RbrzxaVXHJoiona7rhfnTVMh8URvVo/yH\n4pAXvPf1CjagMRsKKS/NcXixaGdLGxP+KTeEd/FY6KXW/wR1FPtTa6xQm+9IF+rA\nWNs2b1qcO6wj4ZIcPuiG0FgOg4NeDvuopRGmog1cyWsdgOuDqou9NpDMMXMFnS8Y\nivS3P1pKXSbg7XKQ4mCWfQk5Oq8Uf3OrOOQncFvUazWQDnhI7GZ9yLw+pqCeziWv\nUeGql2EKtjEsOj9zaN4AeGoSyZDcgVo3X4XRR+sq/Jqd2D8m0aQmlMEcEIVLPmtH\nkugDJsS+Yuk7YQFX4pMbKOCYlO2XCX1STPAn+ytxFwKBgQDlkMG8dvCAn3qoTjlh\n4qj8AHlcyZghcR9Ru1qnSZbw7wVBiTVD8L6mEiLmEGumkNHnwnE/s0PuU10POXeu\nrD4AYtLnJ5f42ycsbBw+ncc1qCwqBwdx4Vo0QXNBs4S+zmf6M8fuzT5wWnaHP5Tg\nbdKByPlpIoGwy/7XseRi3qkQLwKBgQDOOEK3fZ+PQ7PBCGw8DcfWXL4dsUoa5KuC\ncZbkE+sOyGAGBwN+UvxxLQqkSLDtuki6t9+9DvtkfY5N79JN5fGId+BBg8HdhCI+\nxKElGj52f1lcukhMJ3zhLsbUFWz0UFJDudG+qaUuqHRjVCLRJTzlTrvqjHtYLwyO\nQPTi5QnpowKBgQDlURbWZpGUSrrCCXH0v/BB209gSti2/0Nj552E4lPvVTSQ5Lja\np1AqoI9P9jMy7hNgSbHLCg3fslKRdLyDNfexdwZqdfivVGvrSgtk2UM37EhBq0fa\nkFwFOyQhC2ydFZ50JumfOFMY9KTWMcNL9SiFEPdj+F5I914YpNEZmoaTbQKBgF+8\nXLTEvEONYbD20RCcMS8CRTyRpt6PVFQtmahu2sw1F+cUcHm/2vRLvcoA+SqUNdmB\nLXyerPS9GUhzUsXZP2VkiZbArUrCYgeTz1/jLCZk/r5+uLuqBV6hEas5+yf89gP9\nCzOhnE7p44aNc9B2oiuufqzn5QdOaFzOKSIAxLZTAoGBAIicGUmg/FPXj9TC7/8E\nRX7TBFEmJOt+cQNCQZ2KLJD4Io1v7tISjyv2dkYxQZ2tMRE3uOniphyAJhSypseL\naDGyd4LMEkRp6Tazg71T3nepb10MH4pWsvc0O5bXxxEyLeaF+1gWdN3TMALv3B3H\nqcxxFjhWQ492akdnAKYRUgGf\n-----END PRIVATE KEY-----\n",
+  "client_email": "service@dstest-1-292707.iam.gserviceaccount.com",
+  "client_id": "118117667194503067224",
+  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
+  "token_uri": "https://oauth2.googleapis.com/token",
+  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
+  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/service%40dstest-1-292707.iam.gserviceaccount.com"
+}