Dynamically generate images, store as base64, use virtualenv
5
.gitignore
vendored
|
@ -14,4 +14,9 @@ firefox/package.json
|
||||||
# Source
|
# Source
|
||||||
build/
|
build/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
assets/*.png
|
||||||
|
assets/*.gif
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
|
|
||||||
|
# VirtualEnv
|
||||||
|
env/
|
||||||
|
|
|
@ -24,4 +24,4 @@ As you can tell, the quality of the code isnt perfect, or to a particular standa
|
||||||
All the time the app has a version of `0.0.0`, the extensions are considered to be unstable and unlikely to work properly, if at all.
|
All the time the app has a version of `0.0.0`, the extensions are considered to be unstable and unlikely to work properly, if at all.
|
||||||
|
|
||||||
## Example ##
|
## Example ##
|
||||||
The sytax used is identical to what is used in the hipchat applications: wrapping the identifier in brackets `()`. For example, (yey) (allthethings) .
|
The sytax used is identical to what is used in the hipchat applications: wrapping the identifier in brackets `()`. For example, (yey) (allthethings) (boom) .
|
||||||
|
|
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 1.9 KiB |
BIN
assets/argh.png
Before Width: | Height: | Size: 5.3 KiB |
BIN
assets/atom.png
Before Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 1.4 KiB |
BIN
assets/aww.png
Before Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 1 KiB |
Before Width: | Height: | Size: 1.3 KiB |
BIN
assets/beer.png
Before Width: | Height: | Size: 1.5 KiB |
|
@ -1,23 +1,60 @@
|
||||||
import json
|
import json, requests, os, base64
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
from lxml import html
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
ASSETS_URL="https://raw.githubusercontent.com/RealOrangeOne/hipchat-emoticons-for-all/master/assets/"
|
ASSET_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
LOCAL_FILES = glob('assets/*.png') + glob('assets/*.gif')
|
||||||
|
|
||||||
|
Emoticon = namedtuple('Emoticon', ['ident', 'url'])
|
||||||
|
def get_filename(path):
|
||||||
|
return path.replace('assets/', '')
|
||||||
|
|
||||||
def get_icon_name(path):
|
def get_icon_name(path):
|
||||||
return get_filename(path).replace('.png', '').replace('.gif', '')
|
return get_filename(path).replace('.png', '').replace('.gif', '')
|
||||||
|
|
||||||
def get_filename(path):
|
print("Collecting Page Elements...")
|
||||||
return path.replace('assets/', '')
|
page = requests.get("https://www.hipchat.com/emoticons")
|
||||||
|
html_tree = html.fromstring(page.text)
|
||||||
|
emoticon_paths = html_tree.xpath("//div[@class='emoticon-block']/img/@src")
|
||||||
|
emoticon_names = html_tree.xpath("//div[@class='emoticon-block']/div/text()")
|
||||||
|
|
||||||
|
emoticons = []
|
||||||
|
for i in range(len(emoticon_names)-1):
|
||||||
|
emoticons.append(Emoticon(emoticon_names[i][1:-1], emoticon_paths[i]))
|
||||||
|
|
||||||
|
print("Downloading offline emoticons...")
|
||||||
|
DOWNLOAD_FILES = []
|
||||||
|
for emoticon in emoticons:
|
||||||
|
ext = 'gif' if emoticon.url.endswith('gif') else 'png'
|
||||||
|
path = ASSET_DIR + "/{0}.{1}".format(emoticon.ident, ext)
|
||||||
|
DOWNLOAD_FILES.append(path)
|
||||||
|
if os.path.isfile(path):
|
||||||
|
continue
|
||||||
|
with open(path, 'wb') as handle:
|
||||||
|
response = requests.get(emoticon.url, stream=True)
|
||||||
|
if not response.ok:
|
||||||
|
print("Something went wrong getting " + emoticon.ident)
|
||||||
|
continue
|
||||||
|
|
||||||
|
for block in response.iter_content(1024):
|
||||||
|
handle.write(block)
|
||||||
|
|
||||||
|
print ("{}/{} Files Downloaded\r".format(len(DOWNLOAD_FILES), len(emoticons)), end='' if len(DOWNLOAD_FILES) != len(emoticons) else '\n')
|
||||||
|
|
||||||
|
for filename in LOCAL_FILES:
|
||||||
|
emoticons.append(Emoticon(get_icon_name(filename), filename))
|
||||||
|
|
||||||
files = glob('assets/*.png') + glob('assets/*.gif')
|
|
||||||
images = []
|
images = []
|
||||||
|
print("Converting Files...")
|
||||||
|
for emoticon in emoticons:
|
||||||
|
ext = ext = 'gif' if emoticon.url.endswith('gif') else 'png'
|
||||||
|
path = ASSET_DIR + "/{0}.{1}".format(emoticon.ident, ext)
|
||||||
|
file = base64.b64encode(open(path, 'rb').read()).decode('utf-8').replace('\n', '')
|
||||||
|
data = "data:image/{0};base64,{1}".format(ext, file)
|
||||||
|
images.append({emoticon.ident: data})
|
||||||
|
|
||||||
for filename in files:
|
print("Exporting JSON...")
|
||||||
images.append({get_icon_name(filename): ASSETS_URL + get_filename(filename)})
|
|
||||||
|
|
||||||
|
|
||||||
image_decoder = {"images":images}
|
image_decoder = {"images":images}
|
||||||
|
|
||||||
image_decoder_json = json.dumps(image_decoder, indent=2, sort_keys=True)
|
image_decoder_json = json.dumps(image_decoder, indent=2, sort_keys=True)
|
||||||
|
@ -30,3 +67,7 @@ js_file = js_file.replace("%image_decoder%", image_decoder_json)
|
||||||
|
|
||||||
with open('build/global.js', 'w') as file:
|
with open('build/global.js', 'w') as file:
|
||||||
file.write(js_file)
|
file.write(js_file)
|
||||||
|
|
||||||
|
print("Deleting Temporary Files...")
|
||||||
|
for file in DOWNLOAD_FILES:
|
||||||
|
os.remove(file)
|
||||||
|
|
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 1,012 B |
BIN
assets/doge.png
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 6.2 KiB |
BIN
assets/drool.png
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.6 KiB |
BIN
assets/herp.png
Before Width: | Height: | Size: 16 KiB |
BIN
assets/hubot.png
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.1 KiB |
BIN
assets/llama.png
Before Width: | Height: | Size: 3.8 KiB |
BIN
assets/lol.png
Before Width: | Height: | Size: 2.3 KiB |
BIN
assets/metal.png
Before Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 82 KiB |
Before Width: | Height: | Size: 9.1 KiB |
BIN
assets/nice.png
Before Width: | Height: | Size: 2.9 KiB |
BIN
assets/noot.png
Before Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1 KiB |
BIN
assets/ohmy.png
Before Width: | Height: | Size: 2.4 KiB |
BIN
assets/okay.png
Before Width: | Height: | Size: 1 KiB |
BIN
assets/poo.png
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 3 KiB |
BIN
assets/smug.gif
Before Width: | Height: | Size: 972 B |
BIN
assets/stare.png
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.2 KiB |
BIN
assets/troll.png
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.7 KiB |
BIN
assets/wat.png
Before Width: | Height: | Size: 1.1 KiB |
BIN
assets/wooow.gif
Before Width: | Height: | Size: 17 KiB |
BIN
assets/yey.png
Before Width: | Height: | Size: 2.1 KiB |
9
build.sh
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
pyvenv-3.4 env
|
||||||
|
env/bin/pip install -r requirements.txt
|
||||||
|
|
||||||
|
npm install
|
||||||
|
npm run build
|
|
@ -12,12 +12,12 @@
|
||||||
"test-firefox": "cd firefox/ && jpm run -b /usr/bin/firefox && cd -",
|
"test-firefox": "cd firefox/ && jpm run -b /usr/bin/firefox && cd -",
|
||||||
"test": "npm run develop && npm run test-firefox",
|
"test": "npm run develop && npm run test-firefox",
|
||||||
"build-js": "bash build-js.sh",
|
"build-js": "bash build-js.sh",
|
||||||
"develop": "npm run build-assets && npm run build-js && npm run distribute ",
|
"develop": "npm run build-js && npm run distribute ",
|
||||||
"build-assets": "python3 assets/build-assets.py",
|
"build-assets": "env/bin/python3 assets/build-assets.py",
|
||||||
"build-data-files": "python3 firefox/build-package.py && python3 chrome/build-manifest.py",
|
"build-data-files": "env/bin/python3 firefox/build-package.py && env/bin/python3 chrome/build-manifest.py",
|
||||||
"distribute": "rm -rf firefox/data/* chrome/data/* && cp -rf build/* firefox/data/ && cp -rf build/* chrome/data/",
|
"distribute": "rm -rf firefox/data/* chrome/data/* && cp -rf build/* firefox/data/ && cp -rf build/* chrome/data/",
|
||||||
"build": "npm run create-dirs && npm run build-assets && npm run build-js && npm run distribute && npm run build-data-files",
|
"build": "npm run create-dirs && npm run build-assets && npm run build-js && npm run distribute && npm run build-data-files",
|
||||||
"clean": "rm -rf firefox/data chrome/data node_modules/ build/"
|
"clean": "rm -rf firefox/data chrome/data node_modules/ build/ env/"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
5
requirements.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
coverage==3.7.1
|
||||||
|
flake8==2.4.1
|
||||||
|
lxml==3.4.4
|
||||||
|
pep8==1.5.7
|
||||||
|
requests==2.7.0
|