2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ChatWorkの絵文字(emoticon)を全部まとめてzip化してダウンロードする

Last updated at Posted at 2023-02-04

タイトルそのままです。
Pythonのスクリプトで、ChatWorkが公開している絵文字をまとめてzip化してダウンロードします。

標準ライブラリのみ使用しているので、依存モジュールのinstall等は不要でそのまま実行可能です。

import io
import zipfile

import requests

BASE_URL = "https://www.chatwork.com/image/emoticon/"
file_paths = [
    "emo_smile.gif",
    "emo_sad.gif",
    "emo_more_smile.gif",
    "emo_lucky.gif",
    "emo_surprise.gif",
    "emo_wink.gif",
    "emo_tears.gif",
    "emo_sweat.gif",
    "emo_mumu.gif",
    "emo_kiss.gif",
    "emo_tongueout.gif",
    "emo_blush.gif",
    "emo_wonder.gif",
    "emo_snooze.gif",
    "emo_love.gif",
    "emo_grin.gif",
    "emo_talk.gif",
    "emo_yawn.gif",
    "emo_puke.gif",
    "emo_ikemen.gif",
    "emo_otaku.gif",
    "emo_ninmari.gif",
    "emo_nod.gif",
    "emo_shake.gif",
    "emo_wry_smile.gif",
    "emo_whew.gif",
    "emo_clap.gif",
    "emo_bow.gif",
    "emo_roger.gif",
    "emo_muscle.gif",
    "emo_dance.gif",
    "emo_komanechi.gif",
    "emo_devil.gif",
    "emo_star.gif",
    "emo_heart.gif",
    "emo_flower.gif",
    "emo_cracker.gif",
    "emo_cake.gif",
    "emo_coffee.gif",
    "emo_beer.gif",
    "emo_handshake.gif",
    "emo_yes.gif",
]

zip_buffer = io.BytesIO()
with zipfile.ZipFile(zip_buffer, "a", zipfile.ZIP_DEFLATED, False) as zip_file:
    for file_path in file_paths:
        image_url = BASE_URL + file_path
        img_data = requests.get(image_url).content
        zip_file.writestr(file_path.split("/")[-1], img_data)

with open("chatwork_emoticons.zip", "wb") as f:
    f.write(zip_buffer.getvalue())

zipfile.ZipFile()でインメモリのfile-like objectをそのままzip化できます。

Gistにも公開しています。
https://gist.github.com/sin9270/eea6769b1e86786a415871b355f6f1e3

参考にした記事

https://gist.github.com/ttsuruoka/32b764ecd8254aaa214c
https://stackoverflow.com/questions/2463770/python-in-memory-zip-library

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?