2015-09-23 15:07:29 +01:00
|
|
|
import json, requests
|
2015-08-24 17:54:23 +01:00
|
|
|
from glob import glob
|
2015-09-23 15:07:29 +01:00
|
|
|
from lxml import html
|
|
|
|
from collections import namedtuple
|
2015-08-24 17:54:23 +01:00
|
|
|
|
2015-09-23 15:07:29 +01:00
|
|
|
CUSTOM_ASSETS_URL="https://raw.githubusercontent.com/RealOrangeOne/hipchat-emoticons-for-all/master/assets/"
|
2015-08-25 14:27:00 +01:00
|
|
|
|
2015-09-23 15:07:29 +01:00
|
|
|
Emoticon = namedtuple('Emoticon', ['ident', 'url'])
|
2015-08-25 14:27:00 +01:00
|
|
|
|
|
|
|
def get_icon_name(path):
|
2015-08-25 16:09:58 +01:00
|
|
|
return get_filename(path).replace('.png', '').replace('.gif', '')
|
2015-08-25 14:27:00 +01:00
|
|
|
|
2015-08-24 17:54:23 +01:00
|
|
|
def get_filename(path):
|
2015-08-25 14:27:00 +01:00
|
|
|
return path.replace('assets/', '')
|
2015-08-24 17:54:23 +01:00
|
|
|
|
|
|
|
|
2015-09-23 15:07:29 +01:00
|
|
|
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]))
|
|
|
|
|
2015-08-25 14:27:00 +01:00
|
|
|
images = []
|
2015-09-23 15:07:29 +01:00
|
|
|
for emoticon in emoticons:
|
|
|
|
images.append({emoticon.ident: emoticon.url})
|
2015-08-24 17:54:23 +01:00
|
|
|
|
2015-09-23 15:07:29 +01:00
|
|
|
files = glob('assets/*.png') + glob('assets/*.gif')
|
2015-08-24 17:54:23 +01:00
|
|
|
for filename in files:
|
2015-09-23 15:07:29 +01:00
|
|
|
images.append({get_icon_name(filename): CUSTOM_ASSETS_URL + get_filename(filename)})
|
2015-08-25 10:45:40 +01:00
|
|
|
|
2015-08-25 16:09:58 +01:00
|
|
|
|
2015-08-25 14:27:00 +01:00
|
|
|
image_decoder = {"images":images}
|
2015-08-24 17:54:23 +01:00
|
|
|
|
|
|
|
image_decoder_json = json.dumps(image_decoder, indent=2, sort_keys=True)
|
|
|
|
|
|
|
|
js_file = None
|
2015-08-28 15:52:12 +01:00
|
|
|
with open('src/global.js', "r") as file:
|
2015-08-24 17:54:23 +01:00
|
|
|
js_file = file.read()
|
2015-08-25 14:27:00 +01:00
|
|
|
|
2015-08-24 17:54:23 +01:00
|
|
|
js_file = js_file.replace("%image_decoder%", image_decoder_json)
|
2015-08-25 14:27:00 +01:00
|
|
|
|
2015-08-28 15:00:39 +01:00
|
|
|
with open('build/global.js', 'w') as file:
|
2015-08-24 17:54:23 +01:00
|
|
|
file.write(js_file)
|