Skip to content

Instantly share code, notes, and snippets.

@ymyzk
Created April 27, 2015 05:12
Show Gist options
  • Save ymyzk/6edb75862c3a2bd0852e to your computer and use it in GitHub Desktop.
Save ymyzk/6edb75862c3a2bd0852e to your computer and use it in GitHub Desktop.

Revisions

  1. ymyzk revised this gist Apr 27, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion download.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@

    def get_emojis(token):
    response = requests.get("https://slack.com/api/emoji.list",
    params={ "token": token })
    params={"token": token})
    return response.json()


  2. ymyzk renamed this gist Apr 27, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. ymyzk created this gist Apr 27, 2015.
    52 changes: 52 additions & 0 deletions download
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    from __future__ import unicode_literals

    import os
    import sys

    import requests


    def get_emojis(token):
    response = requests.get("https://slack.com/api/emoji.list",
    params={ "token": token })
    return response.json()


    def download_emojis(emojis, path):
    for name, url in emojis.items():
    print(name)
    if url.startswith("alias:"):
    continue
    try:
    response = requests.get(url)
    content_type = response.headers["content-type"]
    if content_type == "image/png":
    extension = "png"
    elif content_type == "image/jpeg":
    extension = "jpg"
    else:
    extension = ""
    image_file = os.path.join(path, name + "." + extension)
    with open(image_file, "wb") as f:
    f.write(response.content)
    except requests.RequestException as e:
    print(e)



    if __name__ == "__main__":
    token = os.environ.get("SLACK_API_TOKEN")
    if token is None:
    sys.exit(1)

    if len(sys.argv) <= 1:
    sys.exit(1)
    path = sys.argv[1]

    result = get_emojis(token)
    if not result["ok"]:
    sys.exit(1)

    download_emojis(result["emoji"], path)

    sys.exit(0)