はじめに
Raspberry pi4 を用いて Google Drive を共有フォルダーとして使う方法について記す。
外部から Raspberry pi に取り込んだデータをサーバ上に置くことを目的としている。調査する中で Rclone が比較的ハードルが低い様に感じたので このツールを用いて取り組むことにした。
ここでは、Raspberry pi 上で Python を利用しての プログラム例を示す。
Raspberry pi で、コマンドラインを使用する方法は こちら に示した。
尚、このツールは Google Drive だけでなく One Drive など 多くのサービスに対応している。
参考:Rcloneのページ
1:Rclone for Python を Raspberry pi にインストール
$ pip install rclone-python
2:参考:コマンド一覧は、ここに記載されているソースプログラム [rclone_python\recon.py] 内に記載されているので確認出来る。
3:参考プログラム
Test001.py
#!/usr/bin/env python3
import tkinter as tk
from rclone_python import rclone
from rclone_python.remote_types import RemoteTypes
# Google Drive にファイルをコピー
def GoogleCopy():
try:
rclone.copy('./Test001.py', 'TestDrive:TestFolder')
statusbar.config(text="Copy 完了!")
except Exception as e:
statusbar.config(text=f"コピー失敗: {e}")
# Google Drive からファイルを削除
def GoogleDel():
try:
rclone.delete('TestDrive:TestFolder/Test001.py')
statusbar.config(text="Delete 完了!")
except Exception as e:
statusbar.config(text=f"削除失敗: {e}")
#TestDrive が存在していない場合、以下を作成
#rclone.create_remote('TestDrive', RemoteTypes.drive)
# rootウィンドウ設定
root = tk.Tk()
root.title("This is Test")
root.geometry("350x100")
# Copyボタン
copy_button = tk.Button(root, text="Copy", command=GoogleCopy)
copy_button.place(x=50, y=40)
# Deleteボタン
delete_button = tk.Button(root, text="Delete", command=GoogleDel)
delete_button.place(x=200, y=40)
# ステータスバー
statusbar = tk.Label(root, text="Ready", bd=1, relief=tk.SUNKEN, anchor=tk.W)
statusbar.pack(side=tk.BOTTOM, fill=tk.X)
root.mainloop()
☆2025年 4月2日(水) 午前09時30分 初版(Ver1.00) 作成
☆2025年 4月4日(金) 午前10時30分 初版(Ver1.10) 作成:3:参考プログラムを置換え