forked from RocketChat/Rocket.Chat.Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.kts
More file actions
63 lines (60 loc) · 1.89 KB
/
generator.kts
File metadata and controls
63 lines (60 loc) · 1.89 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Generator steps:
*
* 1. Download EmojiOne json file from: https://raw.githubusercontent.com/emojione/emojione/master/emoji.json
* 2. Install sdkman, kotlin and kscript for cli usage
* 3. Run: kscript generator.kts
*
* This file will output a json file named emoji-parsed.json
*/
@file:DependsOn("org.json:json:20090211")
import org.json.JSONArray
import org.json.JSONObject
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
import java.util.*
val stream = File("emoji.json").inputStream()
val sb = StringBuilder()
val isr = InputStreamReader(stream, Charsets.UTF_8)
val br = BufferedReader(isr)
var read: String? = br.readLine()
while (read != null) {
sb.append(read)
read = br.readLine()
}
br.close()
val json = JSONObject(sb.toString())
val all = JSONArray()
val jsonList = mutableListOf<JSONObject>()
json.keys().forEach {
val oldJson = json.getJSONObject(it as String) as JSONObject
val newJson = JSONObject().apply {
put("shortname", oldJson.getString("shortname"))
put("category", oldJson.getString("category"))
put("shortnameAlternates", oldJson.getJSONArray("shortname_alternates"))
put("keywords", oldJson.getJSONArray("keywords"))
put("order", oldJson.getInt("order"))
val codePoints = oldJson.get("code_points") as JSONObject
val unicode = codePoints.getString("fully_qualified")
put("unicode", unicode)
}
all.put(newJson)
jsonList.add(newJson)
}
Collections.sort(jsonList, { o1, o2 ->
val order1 = o1.getInt("order")
val order2 = o2.getInt("order")
return@sort order1 - order2
})
File("emoji-parsed.json").printWriter(Charsets.UTF_8).use { out ->
out.println("[")
for (i in 0..jsonList.size - 1) {
out.print(jsonList.get(i).toString(2))
if (i < jsonList.size - 1) {
out.println(",")
}
}
out.println("]")
}
println("Ok")