google photoの画像をエクスポートしたやつをGyazoに取り込むやつ
ただDDするとcreated_atが今になるので画像作成日時をmetadataからとってきて設定する
requests |
from pathlib import Path | |
import json | |
import requests | |
import shutil | |
from multiprocessing import Pool | |
# 画像とmetadataのjsonが大量にあるディレクトリを指定 | |
google_photo_export_path: Path = Path("/path/to/Takeout/Google フォト/") | |
# https://gyazo.com/oauth/applications | |
access_token: str = "<access_token>" | |
collection_id: str = "<collection_id>" | |
desc: str = "Import from Google Photos" | |
app: str = "app_name" | |
uploaded_dir: Path = google_photo_export_path / "upload" | |
uploaded_dir.mkdir(exist_ok=True,parents=True) | |
def upload_picture(jsonpath: Path): | |
#creation time取得 | |
image_json: str | |
with jsonpath.open("r") as f: | |
image_json = json.load(f) | |
sess = requests.session() | |
files = {"imagedata": (jsonpath.parent / jsonpath.stem).open("rb")} | |
data = { | |
"access_token": access_token, | |
"created_at": image_json["photoTakenTime"]["timestamp"], | |
"collection_id": collection_id, # ShareX | |
"app": app, | |
"desc": desc, | |
"title": jsonpath.stem | |
} | |
res = sess.post(f"https://upload.gyazo.com/api/upload",data=data, files=files) | |
shutil.move(str(jsonpath), str(uploaded_dir)) | |
print( "url:{} created_at:{}".format(res.json()["url"],res.json()["created_at"])) | |
with Pool(10) as p: | |
p.map(upload_picture, google_photo_export_path.glob("*.json")) | |