diff --git a/import/main.go b/import/main.go index a07428c..5c4d6ba 100644 --- a/import/main.go +++ b/import/main.go @@ -1,5 +1,8 @@ package main +// Import emoji data from Emojipedia.org +// Useful for rebuilding the emoji data found in the `data/emoji.json` file + import ( "encoding/json" "fmt" @@ -71,23 +74,30 @@ func main() { return } + // Create a new goquery reader doc, docErr := goquery.NewDocumentFromReader(res.Body) if docErr != nil { panic(docErr) } + // Grab the emoji from the "Copy emoji" input field on the HTML page emojiString, _ := doc.Find(".copy-paste input[type=text]").Attr("value") + + // Convert the raw Emoji value to our hex key hexString := utils.StringToHexKey(emojiString) + // Add this emoji to our map emojis[hexString] = emoji.Emoji{ Key: hexString, Value: emojiString, Descriptor: lookup.Name, } + // Print our progress to the console fmt.Println(emojis[hexString]) } + // Marshal the emojis map as JSON and write to the data directory s, _ := json.MarshalIndent(emojis, "", "\t") ioutil.WriteFile("data/emoji.json", []byte(s), 0644) } diff --git a/utils/conv.go b/utils/conv.go index a44ad1b..cc68fcf 100644 --- a/utils/conv.go +++ b/utils/conv.go @@ -1,3 +1,4 @@ +// Package utils - Functions for converting between Hex, String, and Rune representations of emoji package utils import ( diff --git a/utils/rebuild.go b/utils/rebuild.go deleted file mode 100644 index 41b09a5..0000000 --- a/utils/rebuild.go +++ /dev/null @@ -1,26 +0,0 @@ -package utils - -// Used to rebuild the raw emoji "values" in the emoji.json from their -// Key field which is the Hex representation of their Unicode Code Point value -func rebuildValuesFromHex() { - // for i, emoji := range emoji.Emojis { - - // hexParts := strings.Split(emoji.Value, "-") - - // s := []rune{} - // for _, p := range hexParts { - // n, _ := strconv.ParseUint(p, 16, 32) - // s = append(s, rune(n)) - // } - - // Emojis[i] = Emoji{ - // Key: emoji.Key, - // Value: string(s), - // Descriptor: emoji.Descriptor, - // } - // } - - // s, _ := json.MarshalIndent(Emojis, "", "\t") - // ioutil.WriteFile("data/emoji.json", []byte(s), 0644) - -}