Browse Source

Dynamically generate images, store as base64, use virtualenv

master
Jake Howard 6 years ago
parent
commit
8fceb80c15
  1. 5
      .gitignore
  2. 2
      README.md
  3. BIN
      assets/acceptable.png
  4. BIN
      assets/allthethings.png
  5. BIN
      assets/angrycat.png
  6. BIN
      assets/areyoukiddingme.png
  7. BIN
      assets/argh.png
  8. BIN
      assets/atom.png
  9. BIN
      assets/awesome.png
  10. BIN
      assets/awthanks.png
  11. BIN
      assets/aww.png
  12. BIN
      assets/awyeah.png
  13. BIN
      assets/badass.png
  14. BIN
      assets/beer.png
  15. 57
      assets/build-assets.py
  16. BIN
      assets/bullshirt.png
  17. BIN
      assets/challengeaccepted.png
  18. BIN
      assets/chompy.gif
  19. BIN
      assets/content.png
  20. BIN
      assets/doge.png
  21. BIN
      assets/donotwant.gif
  22. BIN
      assets/drool.png
  23. BIN
      assets/evilburns.png
  24. BIN
      assets/facepalm.png
  25. BIN
      assets/greenbeer.png
  26. BIN
      assets/herp.png
  27. BIN
      assets/hubot.png
  28. BIN
      assets/iseewhatyoudidthere.png
  29. BIN
      assets/jackie.png
  30. BIN
      assets/llama.png
  31. BIN
      assets/lol.png
  32. BIN
      assets/metal.png
  33. BIN
      assets/mindblown.gif
  34. BIN
      assets/mygoditsfullofstars.png
  35. BIN
      assets/nice.png
  36. BIN
      assets/noot.png
  37. BIN
      assets/notbad.png
  38. BIN
      assets/nothingtodohere.png
  39. BIN
      assets/ohcrap.png
  40. BIN
      assets/ohgodwhy.png
  41. BIN
      assets/ohmy.png
  42. BIN
      assets/okay.png
  43. BIN
      assets/poo.png
  44. BIN
      assets/ragegirl.png
  45. BIN
      assets/rageguy.png
  46. BIN
      assets/sadpanda.png
  47. BIN
      assets/sadtroll.png
  48. BIN
      assets/shipit.png
  49. BIN
      assets/shrinkray.png
  50. BIN
      assets/smug.gif
  51. BIN
      assets/stare.png
  52. BIN
      assets/sweetjesus.png
  53. BIN
      assets/troll.png
  54. BIN
      assets/truestory.png
  55. BIN
      assets/unacceptable.png
  56. BIN
      assets/waiting.gif
  57. BIN
      assets/wat.png
  58. BIN
      assets/wooow.gif
  59. BIN
      assets/yey.png
  60. 9
      build.sh
  61. 8
      package.json
  62. 5
      requirements.txt

5
.gitignore

@ -14,4 +14,9 @@ firefox/package.json
# Source
build/
node_modules/
assets/*.png
assets/*.gif
npm-debug.log
# VirtualEnv
env/

2
README.md

@ -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.
## 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) .

BIN
assets/acceptable.png

Before

Width: 30  |  Height: 30  |  Size: 2.7 KiB

BIN
assets/allthethings.png

Before

Width: 36  |  Height: 30  |  Size: 3.1 KiB

BIN
assets/angrycat.png

Before

Width: 30  |  Height: 30  |  Size: 5.6 KiB

BIN
assets/areyoukiddingme.png

Before

Width: 25  |  Height: 25  |  Size: 1.9 KiB

BIN
assets/argh.png

Before

Width: 30  |  Height: 25  |  Size: 5.3 KiB

BIN
assets/atom.png

Before

Width: 30  |  Height: 30  |  Size: 2.4 KiB

BIN
assets/awesome.png

Before

Width: 30  |  Height: 30  |  Size: 2.9 KiB

BIN
assets/awthanks.png

Before

Width: 31  |  Height: 30  |  Size: 1.4 KiB

BIN
assets/aww.png

Before

Width: 30  |  Height: 30  |  Size: 3.2 KiB

BIN
assets/awyeah.png

Before

Width: 30  |  Height: 18  |  Size: 1.0 KiB

BIN
assets/badass.png

Before

Width: 30  |  Height: 23  |  Size: 1.3 KiB

BIN
assets/beer.png

Before

Width: 20  |  Height: 20  |  Size: 1.5 KiB

57
assets/build-assets.py

@ -1,23 +1,60 @@
import json
import json, requests, os, base64
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):
return get_filename(path).replace('.png', '').replace('.gif', '')
def get_filename(path):
return path.replace('assets/', '')
print("Collecting Page Elements...")
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]))
files = glob('assets/*.png') + glob('assets/*.gif')
images = []
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 filename in files:
images.append({get_icon_name(filename): ASSETS_URL + get_filename(filename)})
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))
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})
print("Exporting JSON...")
image_decoder = {"images":images}
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:
file.write(js_file)
print("Deleting Temporary Files...")
for file in DOWNLOAD_FILES:
os.remove(file)

BIN
assets/bullshirt.png

Before

Width: 30  |  Height: 30  |  Size: 1.3 KiB

BIN
assets/challengeaccepted.png

Before

Width: 23  |  Height: 28  |  Size: 1.1 KiB

BIN
assets/chompy.gif

Before

Width: 25  |  Height: 25  |  Size: 5.3 KiB

BIN
assets/content.png

Before

Width: 25  |  Height: 25  |  Size: 1012 B

BIN
assets/doge.png

Before

Width: 25  |  Height: 25  |  Size: 17 KiB

BIN
assets/donotwant.gif

Before

Width: 30  |  Height: 25  |  Size: 6.2 KiB

BIN
assets/drool.png

Before

Width: 26  |  Height: 30  |  Size: 2.8 KiB

BIN
assets/evilburns.png

Before

Width: 24  |  Height: 30  |  Size: 2.6 KiB

BIN
assets/facepalm.png

Before

Width: 25  |  Height: 25  |  Size: 2.1 KiB

BIN
assets/greenbeer.png

Before

Width: 20  |  Height: 20  |  Size: 1.6 KiB

BIN
assets/herp.png

Before

Width: 23  |  Height: 25  |  Size: 16 KiB

BIN
assets/hubot.png

Before

Width: 30  |  Height: 30  |  Size: 2.5 KiB

BIN
assets/iseewhatyoudidthere.png

Before

Width: 28  |  Height: 25  |  Size: 1.2 KiB

BIN
assets/jackie.png

Before

Width: 30  |  Height: 18  |  Size: 1.1 KiB

BIN
assets/llama.png

Before

Width: 30  |  Height: 25  |  Size: 3.8 KiB

BIN
assets/lol.png

Before

Width: 25  |  Height: 25  |  Size: 2.3 KiB

BIN
assets/metal.png

Before

Width: 30  |  Height: 30  |  Size: 4.8 KiB

BIN
assets/mindblown.gif

Before

Width: 30  |  Height: 25  |  Size: 82 KiB

BIN
assets/mygoditsfullofstars.png

Before

Width: 30  |  Height: 25  |  Size: 9.1 KiB

BIN
assets/nice.png

Before

Width: 30  |  Height: 28  |  Size: 2.9 KiB

BIN
assets/noot.png

Before

Width: 30  |  Height: 30  |  Size: 5.2 KiB

BIN
assets/notbad.png

Before

Width: 20  |  Height: 28  |  Size: 1.1 KiB

BIN
assets/nothingtodohere.png

Before

Width: 16  |  Height: 25  |  Size: 1.5 KiB

BIN
assets/ohcrap.png

Before

Width: 25  |  Height: 21  |  Size: 1.2 KiB

BIN
assets/ohgodwhy.png

Before

Width: 25  |  Height: 25  |  Size: 1.0 KiB

BIN
assets/ohmy.png

Before

Width: 23  |  Height: 30  |  Size: 2.4 KiB

BIN
assets/okay.png

Before

Width: 18  |  Height: 25  |  Size: 1.0 KiB

BIN
assets/poo.png

Before

Width: 23  |  Height: 21  |  Size: 1.7 KiB

BIN
assets/ragegirl.png

Before

Width: 30  |  Height: 30  |  Size: 3.2 KiB

BIN
assets/rageguy.png

Before

Width: 24  |  Height: 25  |  Size: 2.2 KiB

BIN
assets/sadpanda.png

Before

Width: 28  |  Height: 30  |  Size: 2.5 KiB

BIN
assets/sadtroll.png

Before

Width: 25  |  Height: 20  |  Size: 1.9 KiB

BIN
assets/shipit.png

Before

Width: 30  |  Height: 25  |  Size: 5.5 KiB

BIN
assets/shrinkray.png

Before

Width: 30  |  Height: 30  |  Size: 3.0 KiB

BIN
assets/smug.gif

Before

Width: 26  |  Height: 25  |  Size: 972 B

BIN
assets/stare.png

Before

Width: 34  |  Height: 25  |  Size: 1.7 KiB

BIN
assets/sweetjesus.png

Before

Width: 28  |  Height: 25  |  Size: 1.2 KiB

BIN
assets/troll.png

Before

Width: 25  |  Height: 25  |  Size: 1.3 KiB

BIN
assets/truestory.png

Before

Width: 29  |  Height: 27  |  Size: 2.5 KiB

BIN
assets/unacceptable.png

Before

Width: 20  |  Height: 30  |  Size: 2.1 KiB

BIN
assets/waiting.gif

Before

Width: 30  |  Height: 30  |  Size: 2.7 KiB

BIN
assets/wat.png

Before

Width: 25  |  Height: 25  |  Size: 1.1 KiB

BIN
assets/wooow.gif

Before

Width: 30  |  Height: 30  |  Size: 17 KiB

BIN
assets/yey.png

Before

Width: 25  |  Height: 25  |  Size: 2.1 KiB

9
build.sh

@ -0,0 +1,9 @@
#!/bin/bash
set -e
pyvenv-3.4 env
env/bin/pip install -r requirements.txt
npm install
npm run build

8
package.json

@ -12,12 +12,12 @@
"test-firefox": "cd firefox/ && jpm run -b /usr/bin/firefox && cd -",
"test": "npm run develop && npm run test-firefox",
"build-js": "bash build-js.sh",
"develop": "npm run build-assets && npm run build-js && npm run distribute ",
"build-assets": "python3 assets/build-assets.py",
"build-data-files": "python3 firefox/build-package.py && python3 chrome/build-manifest.py",
"develop": "npm run build-js && npm run distribute ",
"build-assets": "env/bin/python3 assets/build-assets.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/",
"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": {
"type": "git",

5
requirements.txt

@ -0,0 +1,5 @@
coverage==3.7.1
flake8==2.4.1
lxml==3.4.4
pep8==1.5.7
requests==2.7.0
Loading…
Cancel
Save