Docx to Google Drive uploader.
Project description
# Docx to Google Drive uploader for Foliant
Gdoc is an extension of Pandoc backend, it's used to upload created docx documents to Google Drive.
Gdoc adds `gdoc` target to Foliant.
## Installation
```shell
$ pip install foliantcontrib.gdoc
```
## Config
To enable the backend, add `gdoc` to `backend_config` section in the project config. As `gdoc` needs *docx* to upload, `pandoc` settings also have to be here.
Backend has a number of options (all fields are required but can have no values):
```yaml
backend_config:
pandoc:
...
gdoc:
gdrive_folder_name: Foliant upload
gdrive_folder_id:
gdoc_title:
gdoc_id:
```
`gdrive_folder_name`
: Folder with this name will be created on Google Drive to upload file.
`gdrive_folder_id`
: This field is necessary to upload files to previously created folder.
`gdoc_title`
: Uploaded file will have this title. If empty, real filename will be used.
`gdoc_id`
: This field is necessary to rewrite previously uploaded file and keep the link to it.
## Usage
At first you have to get Google Drive authentication file.
1. Go to [APIs Console](https://console.developers.google.com/cloud-resource-manager) and make your own project.
2. Go to [library](https://console.developers.google.com/apis/library), search for ‘Google Drive API’, select the entry, and click ‘Enable’.
3. Select ‘Credentials’ from the left menu, click ‘Create Credentials’, select ‘OAuth client ID’.
4. Now, the product name and consent screen need to be set -> click ‘Configure consent screen’ and follow the instructions. Once finished:
- Select ‘Application type’ to be Web application.
- Enter an appropriate name.
- Input http://localhost:8080 for ‘Authorized JavaScript origins’.
- Input http://localhost:8080/ for ‘Authorized redirect URIs’.
- Click ‘Save’.
5. Click ‘Download JSON’ on the right side of Client ID to download client_secret_<really long ID>.json. The downloaded file has all authentication information of your application.
6. Rename the file to “client_secrets.json” and place it in your working directory near foliant.yml.
Now add the backend to the project config with all 4 settings strings. At this moment you have no data to set *Google Drive folder ID* and *google doc ID* so keep it empty.
Run Foliant with `gdoc` target:
```shell
$ foliant make gdoc
✔ Parsing config
✔ Applying preprocessor flatten
✔ Making docx with Pandoc
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?...
Authentication successful.
─────────────────────
Result:
Doc link: https://docs.google.com/document/d/1GPvNSMJ4ZutZJwhUYM1xxCKWMU5Sg/edit?usp=drivesdk
Google drive folder ID: 1AaiWMNIYlq9639P30R3T9
Google document ID: 1GPvNSMJ4Z19YM1xCKWMU5Sg
```
Authentication will be opened. Choose account to log in. After that docx will be uploaded to Google Drive in google doc format and opened in new browser tab.
Now you can use *Google Drive folder ID* to upload files to the same folder and *google doc ID* (the same as in the link) to rewrite document.
### Notes
If you set up *google doc ID* without *Google Drive folder ID* file will be moved to the new folder with the same link.
Gdoc is an extension of Pandoc backend, it's used to upload created docx documents to Google Drive.
Gdoc adds `gdoc` target to Foliant.
## Installation
```shell
$ pip install foliantcontrib.gdoc
```
## Config
To enable the backend, add `gdoc` to `backend_config` section in the project config. As `gdoc` needs *docx* to upload, `pandoc` settings also have to be here.
Backend has a number of options (all fields are required but can have no values):
```yaml
backend_config:
pandoc:
...
gdoc:
gdrive_folder_name: Foliant upload
gdrive_folder_id:
gdoc_title:
gdoc_id:
```
`gdrive_folder_name`
: Folder with this name will be created on Google Drive to upload file.
`gdrive_folder_id`
: This field is necessary to upload files to previously created folder.
`gdoc_title`
: Uploaded file will have this title. If empty, real filename will be used.
`gdoc_id`
: This field is necessary to rewrite previously uploaded file and keep the link to it.
## Usage
At first you have to get Google Drive authentication file.
1. Go to [APIs Console](https://console.developers.google.com/cloud-resource-manager) and make your own project.
2. Go to [library](https://console.developers.google.com/apis/library), search for ‘Google Drive API’, select the entry, and click ‘Enable’.
3. Select ‘Credentials’ from the left menu, click ‘Create Credentials’, select ‘OAuth client ID’.
4. Now, the product name and consent screen need to be set -> click ‘Configure consent screen’ and follow the instructions. Once finished:
- Select ‘Application type’ to be Web application.
- Enter an appropriate name.
- Input http://localhost:8080 for ‘Authorized JavaScript origins’.
- Input http://localhost:8080/ for ‘Authorized redirect URIs’.
- Click ‘Save’.
5. Click ‘Download JSON’ on the right side of Client ID to download client_secret_<really long ID>.json. The downloaded file has all authentication information of your application.
6. Rename the file to “client_secrets.json” and place it in your working directory near foliant.yml.
Now add the backend to the project config with all 4 settings strings. At this moment you have no data to set *Google Drive folder ID* and *google doc ID* so keep it empty.
Run Foliant with `gdoc` target:
```shell
$ foliant make gdoc
✔ Parsing config
✔ Applying preprocessor flatten
✔ Making docx with Pandoc
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?...
Authentication successful.
─────────────────────
Result:
Doc link: https://docs.google.com/document/d/1GPvNSMJ4ZutZJwhUYM1xxCKWMU5Sg/edit?usp=drivesdk
Google drive folder ID: 1AaiWMNIYlq9639P30R3T9
Google document ID: 1GPvNSMJ4Z19YM1xCKWMU5Sg
```
Authentication will be opened. Choose account to log in. After that docx will be uploaded to Google Drive in google doc format and opened in new browser tab.
Now you can use *Google Drive folder ID* to upload files to the same folder and *google doc ID* (the same as in the link) to rewrite document.
### Notes
If you set up *google doc ID* without *Google Drive folder ID* file will be moved to the new folder with the same link.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for foliantcontrib.gdoc-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3e6371abb66cee04a54e0cd6ef0a910469045954015f9617a08f273a5b87d0a |
|
MD5 | 13f679d31afc5b61b1371cc402d8a421 |
|
BLAKE2b-256 | b3b366c5119cfd0870750a164ea4590111031602b07624e38ad4bd9dcd0c2f82 |