Skip to content

Instantly share code, notes, and snippets.

@Mucid
Last active August 29, 2015 14:10
Show Gist options
  • Save Mucid/539e74c1144275782ea2 to your computer and use it in GitHub Desktop.
Save Mucid/539e74c1144275782ea2 to your computer and use it in GitHub Desktop.
Convert Cloud Emoticon to Fcitx Quickphrase
#!/usr/bin/env python
#coding=UTF-8
'''
@author: mucid
@email: muciwd@gmail.com
@blog: brilliant.gd
'''
import urllib,sys,os,json,collections
def percent(a,b,c):
per=100*a*b//c
if per>100:per=100
sys.stdout.write('#'*per+str(per)+'%\r')
sys.stdout.flush()
print 'Downloading KT.json......'
urllib.urlretrieve('http://plumz.me/KT.json','KT.json',percent)
print '\nConvert Cloud Emoji to Fcitx QuickEmoution....'
kt=open('KT.json')
kt=json.load(kt)
cat=kt['categories']
quickphrase=collections.defaultdict(list)
for i in cat:
for k in i['entries']:
de=k['description']
if not de:de='normal'
quickphrase[de].append(k['emoticon'])
home=os.getenv("HOME")
epath=os.path.join(home,'.config','fcitx','data')
epath=epath+'/quickphrase.d/'
if not os.path.exists(epath):os.mkdir(epath)
print 'Fcitx emoji.mb file is at %s, You can edit it by yourself!' %epath
emoji=open(epath+'emoji.mb','w')
for k,v in quickphrase.items():
for i in v:emoji.write(k.encode('utf8')+' '+i.encode('utf8')+'\n')
emoji.close()
os.system('cat /usr/share/fcitx/data/quickphrase.d/emoji.mb >> %semoji.mb' %epath)
print '\nAuto Restart Fcitx....!'
os.system('fcitx -r >/dev/null 2>&1')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment