Skip to content

Instantly share code, notes, and snippets.

@suzutan
Last active May 23, 2021 09:45
Show Gist options
  • Save suzutan/93b48162cec99555e61fa94980487401 to your computer and use it in GitHub Desktop.
Save suzutan/93b48162cec99555e61fa94980487401 to your computer and use it in GitHub Desktop.
Google Photoの画像エクスポートしたやつをGyazoに取り込むやつ

google photoの画像をエクスポートしたやつをGyazoに取り込むやつ

ただDDするとcreated_atが今になるので画像作成日時をmetadataからとってきて設定する

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"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment