-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemojify.py
38 lines (31 loc) Β· 904 Bytes
/
emojify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
import sys
import json
from random import random
def emojify(c):
c = c.decode()
file = open('./.git/hooks/emoji.json')
d = json.load(file)
p = c.split(' ')
l = c.split('\n')[0]
es = []
for e in d:
for w in p:
if w in e['tags']:
es.append(e['emoji'])
if w in e['aliases']:
es.append(e['emoji'])
if es != []:
for e in es:
l += ' '+e
else:
l += ' '+d[int(random() * (len(d)-1))]['emoji']+' '+d[int(random() * (len(d)-1))]['emoji']
return l
def append_to_file():
with open(sys.argv[1], 'r') as message_file:
lines = message_file.readlines()
lines[0] = emojify(lines[0].encode('utf-8'))
with open(sys.argv[1], 'w') as message_file:
message_file.write(''.join(lines))
if __name__ == '__main__':
append_to_file()