gdr / bitmoji (public) (License: GPLv3) (since 2017-01-25) (hash sha1)
Download all your bitmoji emoticons, with a nice live search HTML page

/update_json.py (7fc81c47c486da16b7bae4b0dd729909e6a86bdc) (3393 bytes) (mode 100644) (type blob)

#!/usr/bin/python

import jinja2
import json
import os
import os.path
import requests
import traceback

def login(username, password):
    headers = {
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/48.0.2564.116 Chrome/48.0.2564.116 Safari/537.36",
        "Content-Type": "application/json",
    }
    body = {
        "client_id":"imoji",
        "username":username,
        "password":password,
        "grant_type": "password",
        "client_secret":"secret"
    }
    r = requests.post(
        "https://api.bitmoji.com/user/login",
        headers=headers,
        data=json.dumps(body),
    )
    r.raise_for_status()
    response = r.json()
    return response['access_token']


def get_templates(token):
    headers = {
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/48.0.2564.116 Chrome/48.0.2564.116 Safari/537.36",
        "Content-Type": "application/json",
        "Cookie": "bitmoji_bsauth_token=" + token,
    }
    r = requests.get("https://api.bitmoji.com/content/templates", headers=headers)
    r.raise_for_status()
    rv = r.json()
    if 'imoji' not in rv:
        print r.json()
    return rv

def get_avatar_id(token):
    headers = {
        "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/48.0.2564.116 Chrome/48.0.2564.116 Safari/537.36",
        "Content-Type": "application/json",
        "Cookie": "bitmoji_bsauth_token=" + token,
        "bitmoji-token": token,
    }
    r = requests.get("https://api.bitmoji.com/user/avatar", headers=headers)
    r.raise_for_status()
    return r.json()['id']

def precache_images(images):
    images_dir = os.path.join(os.getcwd(), "e")
    if not os.path.exists(images_dir):
        os.makedirs(images_dir)

    for image in images:
        try:
            image_path = os.path.join(images_dir, "%s.png" % image['template_id'])
            if not os.path.exists(image_path):
                r = requests.get(image['src'])
                with open(image_path, "wb") as f:
                    for chunk in r.iter_content(chunk_size=4096):
                        if chunk:
                            f.write(chunk)

        except:
            traceback.print_exc()

        if os.path.exists(image_path):
            image['original_src'] = image['src']
            image['src'] = 'e/%s.png' % image['template_id']
        

def generate_html(images, avatar_id):
    for image in images:
        image['src'] = image['src'] % avatar_id

    precache_images(images)

    images.sort(key=lambda x: x['category_rank'] * x['download_order'])
    env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.getcwd()))
    template = env.get_template("bitmoji.html")
    rendered = template.render(images=images)
    open("index.html", "w").write(rendered)


def generate_page(username, password):
    token = login(username, password)
    avatar_id = get_avatar_id(token)
    templates = get_templates(token)
    images = templates['imoji']
    for pack in templates['packs']:
        for emo in pack['templates']:
            images.append(emo)
    if len(images) == 0:
        print "Zero images"
        return

    generate_html(images, avatar_id)

if __name__ == "__main__":
    generate_page(os.getenv("username"), os.getenv("password"))


Mode Type Size Ref File
100644 blob 241 7e72c01e544f12e9cb1c60811d4de71ba942c744 README.md
100644 blob 1416 1a324c6b1afd910f496e73ab3dda630fee8c2ea4 bitmoji.html
100644 blob 3393 7fc81c47c486da16b7bae4b0dd729909e6a86bdc update_json.py
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/gdr/bitmoji

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/gdr/bitmoji

Clone this repository using git:
git clone git://git.rocketgit.com/user/gdr/bitmoji

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main