Metadata-Version: 2.1
Name: cameo_pg2gsheet
Version: 0.0.1
Summary: PostgreSQL table to Google sheet
Home-page: https://github.com/bohachu/pg2gsheet
Author: Yi-Hao Su
Author-email: elantievs@gmail.com
License: BSD 2-clause
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# pg2gsheet

## 使用Docker的執行方式
1. 調整docker-compose.yaml的pg2gsheet_run及pg2gsheet_output路徑
2. 在docker-compose.yaml填入postgresql連線資訊
3. 輸入以下指令運行Docker
```bash
docker-compose build pg2gsheet
docker-compose up -d pg2gsheet
```

## 不使用Docker的執行方式
### 前置步驟
1. 安裝所需Python套件
```shell
pip install -r requirements.txt
```
2. 複製src/dot_env_file_template成.env檔，並填入postgresql連線資訊

### 範例 (另可參考src/examples.py)
1. 從單一table匯出CSV
```python
from cameo_pg2gsheet import export_single_table_to_csv

csv_file_path = '匯出的CSV路徑含檔名'
table_name = 'table名稱'
export_single_table_to_csv(csv_file_path, table_name)
```

2. 從SQL指令所join的table匯出CSV
```python
from cameo_pg2gsheet import export_csv_by_sql_command

csv_file_path = '匯出的CSV路徑含檔名'
sql_command = 'SQL指令'
export_csv_by_sql_command(csv_file_path, sql_command)
```

3. 將CSV匯入到Google sheet
```python
from cameo_pg2gsheet import import_csv_to_gsheet

google_api_credentials_file_path = 'Google API驗證檔路徑'
gsheet_id = 'Google sheet ID'
worksheet_name = 'worksheet名稱'
csv_file_path = '匯出的CSV路徑含檔名'
import_csv_to_gsheet(google_api_credentials_file_path, gsheet_id, worksheet_name, csv_file_path)
```
