Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5.  
  6. ; Build java enum code
  7. upperCode := "public enum Emoji {`n"
  8. lowerCode :=
  9. (
  10.     private long unicode;
  11.    
  12.     private Emoji(long unicode) {
  13.         this.unicode = unicde;
  14.     }
  15.    
  16.     public String toString() {
  17.         return new String(Character.toChars(unicode));
  18.     }
  19. }
  20. )
  21.  
  22. codeFileName := "Emoji.java"
  23. code := top
  24. ; Scraping code
  25. wb := new Browser(true,false)
  26. wb.navigate("https://unicode.org/emoji/charts/emoji-list.html")
  27. table := wb.extract("tag", "table")[0]
  28. Loop, % table.rows.length
  29. {
  30.     row := table.rows[A_Index]
  31.     if (isNumber(row.cells[0].innerText)) {
  32.         unicode := row.cells[1].innerText
  33.         name := row.cells[3].innerText
  34.         msgbox %  enumify(name, unicode)
  35.         code .= enumify(name, unicode) . ((A_Index == table.rows.length) ? ";`n" : ",`n")
  36.     }
  37. }
  38. code .= bottom
  39. FileAppend, % code, % codeFileName
  40. Run, % A_ScriptDir
  41. return
  42.  
  43. enumify(name,unicode) {
  44.     StringUpper, nameUpper, name
  45.     nameUpper := RegExReplace(nameUpper, "\s", "_")
  46.     nameUpper :=  nameUpper "(" RegExReplace(unicode, "U\+", "0x") ")"
  47.     return nameUpper
  48. }
  49.  
  50. isNumber(num) {
  51.     isNum := true
  52.     if (num is not Integer)
  53.         isNum := false
  54.     Loop, parse, % num
  55.         if (!isDigit(A_LoopField))
  56.             isNum := false
  57.     return isNum
  58. }
  59.        
  60. isDigit(digit) {
  61.     digits := ["0","1","2","3","4","5","6","7","8","9"]
  62.     isDigit := false
  63.     for key, value in digits
  64.         if (value == digit)
  65.             isDigit := true
  66.     return isDigit
  67. }
  68.  
  69. #include, Browser.ahk
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement