Skip to main content

PostgreSQL table to Google sheet

Project description

cameo-pg2gsheet

使用Docker的執行方式

  1. 調整docker-compose.yaml的pg2gsheet_run及pg2gsheet_output路徑
  2. 在docker-compose.yaml填入postgresql連線資訊
  3. 複製src/examples.py到pg2gsheet_run目錄並調整要執行的函式
  4. 輸入以下指令運行Docker
docker-compose build cameo-pg2gsheet
docker-compose up -d cameo-pg2gsheet
  1. 執行examples.py
docker exec DockerContainerId python /app/run/examples.py

不使用Docker的執行方式

前置步驟

  1. 安裝cameo-pg2gsheet套件
pip install cameo-pg2gsheet
  1. 複製src/dot_env_file_template成.env檔,並填入postgresql連線資訊

範例 (另可參考src/examples.py)

  1. 從單一table匯出CSV
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)
  1. 從SQL指令所join的table匯出CSV
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)
  1. 將CSV匯入到Google sheet
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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cameo_pg2gsheet-1.3.0.tar.gz (3.0 kB view details)

Uploaded Source

File details

Details for the file cameo_pg2gsheet-1.3.0.tar.gz.

File metadata

  • Download URL: cameo_pg2gsheet-1.3.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for cameo_pg2gsheet-1.3.0.tar.gz
Algorithm Hash digest
SHA256 e78b76c7f05169cddee9f4d2626979b1baf4b18461003d4671b0228f204c2b82
MD5 96cfba53e80da78ef236045a54d61bb0
BLAKE2b-256 157a61b62c0f500c3d78ef4e33199f80582bd6cfbc8c671438e98ac024b424ac

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page