Gists
This is a sample script for replacing the template texts with an array in Google Document using Docs API with Python.
The sample input and output situations are as follows.
In the current stage, when replaceAllText of Docs API is used with the sample value of ["updated text 1", "updated text 2", "updated text 3"], all values of {{oldText}} are replaced with the 1st value of updated text 1 in one batch request.
Gists
This is the sample scripts for creating new event with Google Meet link to Google Calendar using various languages. When I saw the official document of “Add video and phone conferences to events”, in the current stage, I can see only the sample script for Javascript. But I saw the several questions related to this for various languages. So I published the sample scripts for creating new event with Google Meet link to Google Calendar using various languages.
Gists
This is a sample script for retrieving all values from all sheets from URL of 2PACX- of Web Published Google Spreadsheet using Python.
In this post, it supposes that the Google Spreadsheet has already been published for Web. Ref
Flow The flow of this method is as follows.
Retrieve XLSX data from the URL of web published Google Spreadsheet as BytesIO data. The URL is like https://docs.google.com/spreadsheets/d/e/2PACX-###/pubhtml. XLSX data is parsed with openpyxl.
python library - getfilelistpy was updated to v1.0.7. v1.0.7 (August 11, 2020)
Pull request was reflected. You can check getfilelistpy at https://github.com/tanaikech/getfilelistpy.
You can also check getfilelistpy at https://pypi.org/project/getfilelistpy/.
Updated: GetFileList for golang, Javascript, Node.js and Python
This is the libraries to retrieve the file list with the folder tree from the specific folder of own Google Drive and shared Drives.
Golang: https://github.com/tanaikech/go-getfilelist Updated to v1.0.4. Javascript: https://github.com/tanaikech/GetFileList_js Updated to v1.0.3. Node.js: https://github.com/tanaikech/node-getfilelist Updated to v1.0.5. Python: https://github.com/tanaikech/getfilelistpy Updated to v1.0.6.
python library - getfilelistpy was updated to v1.0.5. v1.0.5 (May 15, 2020)
Shared drive got to be able to be used. The file list can be retrieved from both your Google Drive and the shared drive.
For example, when the folder ID in the shared Drive is used id of resource, you can retrieve the file list from the folder in the shared Drive. You can check getfilelistpy at https://github.
Gists
This is a simple sample script for achieving the resumable upload to Google Drive using Python. In order to achieve the resumable upload, at first, it is required to retrieve the location, which is the endpoint of upload. The location is included in the response headers. After the location was retrieved, the file can be uploaded to the location URL.
In this sample, a PNG file is uploaded with the resumable upload using a single chunk.
Libraries of gdoctableapp for golang, Node.js and python were updated to v1.1.0 go-gdoctableapp
v1.1.0 (January 22, 2020) 2 new methods were added. From this version, the texts can be replaced by images. The direct link and local file can be used as the image. node-gdoctableapp
v1.1.0 (January 22, 2020) New method was added. From this version, the texts can be replaced by images.
Libraries of gdoctableapp for golang, Node.js and python were updated to v1.0.5 go-gdoctableapp node-gdoctableapp gdoctableapppy Update History v1.0.5 (January 21, 2020)
When the inline objects and tables are put in the table. An error occurred. This bug was removed by this update. I got the pull request at here.
python library - getfilelistpy was updated to v1.0.4. v1.0.4 (August 23, 2019)
For OAuth2, oauth2client and google_auth_oauthlib got to be able to be used. About the sample script for google_auth_oauthlib, please see this. You can check getfilelistpy at https://github.com/tanaikech/getfilelistpy.
You can also check getfilelistpy at https://pypi.org/project/getfilelistpy/.
Gists
This is a sample script for creating a table to Google Document by retrieving values from Google Spreadsheet for Python.
Before you use this script, please install python library of gdoctableapppy.
$ pip install gdoctableapppy
Sample script: This sample script uses Service Account.
In this sample script, the values are retrieved from Sheet1!A1:C5 of Spreadsheet, and new table is created to the Document using the values.
from google.oauth2 import service_account
from gdoctableapppy import gdoctableapp
from googleapiclient.
Overview This is a python library to manage the tables on Google Document using Google Docs API.
Description Google Docs API has been released. When I used this API, I found that it is very difficult for me to manage the tables on Google Document using Google Docs API. Although I checked the official document, unfortunately, I thought that it's very difficult for me. So in order to easily manage the tables on Google Document, I created this library.
Overview This is a python library to retrieve the file list with the folder tree from the specific folder of Google Drive.
Description When I create applications for using Google Drive, I often retrieve a file list from a folder in the application. So far, I had created the script for retrieving a file list from a folder for each application. Recently, I thought that if there is the script for retrieving the file list with the folder tree from the folder of Google Drive as a library, it will be useful for me and other users.
Gists
This is a sample script for uploading files from local PC to Google Drive using Python. In this sample, Quickstart is not used. So when you use this script, please retrieve access token.
Curl sample : curl -X POST \
-H "Authorization: Bearer ### access token ###" \
-F "metadata={name : 'sample.png', parents: ['### folder ID ###']};type=application/json;charset=UTF-8" \
-F "file=@sample.png;type=image/png" \
"https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"
]
Python sample : When above curl sample is converted to Python, it becomes as follows.
Gist
This is a sample script for decoding Gmail body with Japanese language using Python.
msg = service.users().messages().get(userId='me', id=id).execute()
parts = msg['payload']['parts']
for e in parts:
msg = base64.urlsafe_b64decode(e['body']['data']).decode('utf-8').encode('cp932', "ignore").decode('cp932')
print(msg)
Gists
This sample script is for updating thumbnail of file on Google Drive using Python.
This sample supposes that quickstart is used and default quickstart works fine. In order to use this sample, please carry out as follows.
Replace main() of the default quickstart to this sample. Script : import base64 # This is used for this sample.
def main():
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.
This sample is for error handling for subprocess.Popen. It confirms whether the execution file is existing. If the execution file is also not in the path, the error message is shown.
import subprocess res = subprocess.Popen( "application", # <- Execution file stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True ).communicate() if len(res[1]) == 0: print("ok: Application is existing.") else: print("Error: Application is not found.")
This sample is for using constructor between classes at Python.
Sample : class test1: def __init__(self): self.msg = "sample text" class test2: def __init__(self): self.msg = test1().msg print(test2().msg) >>> sample text
This “souwapy” is a library for summing array elements with high speed by new algorithm (Pyramid method). The speed is faster than csv and panbdas module of python and v8 engine of node.js. The souwapy module is 2.3 and 3.1 times faster than csv and pandas module, respectively. This was really surprised me. It was found that the theory was correct.
At first, I have created this theory for Google Apps Script.
Suddenly I had to need this.
This script can get the duplicate number of each element in array at Python. In this script, the duplicate number of each element is obtained and sorted by the duplicate number. This was expressed by the comprehension.
data = ['a', 'b', 'c', 'd', 'b', 'c', 'd', 'b', 'c', 'b'] result = sorted({i: data.count(i) for i in set(data)}.items(), key=lambda x: x[1], reverse=True) print(result) >>> [('b', 4), ('c', 3), ('d', 2), ('a', 1)]