Advertisement
York_86

Tennis_Range

Jan 17th, 2023 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv
  2. SetBatchLines, -1
  3. #SingleInstance force
  4. StringCaseSense, Locale
  5. #IfWinActive, (*_*)
  6.  
  7.  
  8.  
  9. Array_id := {"career-splits" :"career-splits-chall", "last52-splits":"last52-splits-chall"}
  10.  
  11. Gui, +ToolWindow +AlwaysOnTop
  12. Gui,Font, s15 normal
  13. Gui, Add, Edit, r1  x20  w150 vSearch gValidCheck Number,  № позиции
  14. Gui, Add, Button, x20 y+10 w150 h20 Disabled vnext gOK, % Chr(0x2192)
  15. Gui,Font, s12 normal
  16. Gui, Add, Text, x20 y+10 w200 vName gname,
  17. Gui, Font, s10 normal
  18. Gui, Add, ListView, x10 y+15 r9 w304  NoSort vLV +ReadOnly , Split|M|W|L|Win
  19.  
  20. loop % LV_GetCount("col")
  21.     LV_ModifyCol(A_index,"60 Center")
  22.    
  23. Gui, Add, Picture, x180 y5 w130 h100 vImages gImages +0x1000,
  24.  
  25. LV_Modify(2, "NewCol1")
  26.  
  27. Gui, Show, w320, (*_*)
  28.  
  29. hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
  30. OnMessage(0x200,"WM_MOUSEMOVE")
  31. GuiControl, Focus, Search
  32. return
  33.  
  34. GuiClose:
  35. ExitApp
  36.  
  37. ValidCheck:
  38. GuiControlGet, Search
  39. If (isNumberInRange(Search,0))
  40.    GuiControl, Enable, next
  41. else
  42.    GuiControl, Disable, next
  43. return
  44.  
  45. Images:
  46. ;~ if (capture)
  47. ;~ {
  48.    ;~ Gui, -AlwaysOnTop
  49.    ;~ run, % capture
  50.    ;~ sleep 300
  51.    ;~ WinGet, Pid, PID, A
  52.  
  53.    ;~ while, WinExist("ahk_pid " . Pid)
  54.    ;~ {
  55.       ;~ Sleep 1000
  56.       ;~ Process, close, % PID
  57.       ;~ Gui, +AlwaysOnTop
  58.    ;~ }
  59. ;~ }
  60. return
  61.  
  62. name:
  63. run, % link_gui
  64. return
  65.  
  66. $Enter::
  67. $NumpadEnter::
  68. Ok:
  69. Gui, Submit, NoHide
  70. gosub label_none
  71. ToolTip, Loading!!
  72.  
  73.  
  74.  
  75. url := "https://tennisabstract.com/reports/wtaRankings.html"
  76. loop 3
  77. {
  78.     html := WebRequest(url,,,, error)
  79.     if error
  80.        throw error
  81.     document := DocumentFromHtml(html)
  82.  
  83.    
  84.     if(A_index = 1)
  85.     {
  86.         links := document.getElementsByTagName("tbody")[3].getElementsByTagName("tr")
  87.         loop, % links.length
  88.         {
  89.            if(search = links[A_index - 1].getElementsByTagName("td")[0].innerText)
  90.            {
  91.               url := link_gui:=  links[A_index - 1].getElementsByTagName("td")[1].getElementsByTagName("a")[0].getAttribute("href")
  92.               fullname := links[A_index - 1].getElementsByTagName("td")[1].getElementsByTagName("a")[0].innerText
  93.               break
  94.            }
  95.         }
  96.     }
  97.    
  98.     if(A_index = 2)
  99.     {
  100.        
  101.         links := document.getElementsByTagName("head")[0].getElementsByTagName("script")
  102.         loop, % links.length
  103.         {
  104.             if Instr(links[A_index - 1].getAttribute("src"), RegExReplace(fullname, "\s"))
  105.                 url:= links[A_index - 1].getAttribute("src")
  106.         }
  107.     }
  108.    
  109.     if(A_index = 3)
  110.     {
  111.         for key, var in Array_id
  112.         {
  113.             chek_tag := Instr(html, var) ? var : key
  114.  
  115.             a := 0
  116.             loop 3
  117.             {
  118.                 b := 1
  119.                 qq .=  document.getElementById(chek_tag).getElementsByTagName("tbody")[0].getElementsByTagName("tr")[a].getElementsByTagName("td")[0].innerText "|"
  120.                 loop 4
  121.                 {
  122.                     qq2 .= document.getElementById(chek_tag).getElementsByTagName("tbody")[0].getElementsByTagName("tr")[a].getElementsByTagName("td")[b].innerText "|"
  123.                     b++
  124.                 }
  125.                 a++
  126.             }
  127.         }
  128.     }
  129. }
  130.  
  131. GuiControl, Text, Name, % fullname
  132.  
  133.  
  134. Loop, parse, qq, |
  135. {
  136.     if(A_index = 1 || A_index = 4)
  137.         LV_Add(, "")
  138.     LV_Add(, A_loopfield)
  139.    
  140. }
  141.  
  142.  
  143. i := 1
  144. col := 2
  145. Loop, parse, qq2, |
  146. {
  147.     if(A_index = "5" || A_index = "9" || A_index = "13" || A_index = "17" || A_index = "21") ;(A_index = 4 * i + 1)  
  148.     {
  149.         i++
  150.         col := 2
  151.     }
  152.    
  153.     if(A_index = "13")
  154.         i := i+1
  155.    
  156.     LV_Modify(i+1, "Col" . col, A_LoopField)
  157.     col++
  158.  
  159. }
  160.  
  161.  
  162. UrlDownloadToFile, % Format("{:L}", "https://www.tennisabstract.com/photos/" RegExReplace(fullname, " ", "_") "-sirobi.jpg"), % capture := A_Temp "\capture_tennis.jpg"
  163.  
  164. FileGetSize, OutputVar_size, % capture , K
  165. if (OutputVar_size < 3)
  166. {
  167.     if !FileExist(A_Temp "\capture_tennis_none.jpg")
  168.         UrlDownloadToFile, https://t3.ftcdn.net/jpg/02/15/15/46/240_F_215154625_hJg9QkfWH9Cu6LCTUc8TiuV6jQSI0C5X.jpg, % capture := A_Temp "\capture_tennis_none.jpg"
  169.     else
  170.         capture := A_Temp "\capture_tennis_none.jpg"   
  171. }
  172. GuiControl,, Images, *w130 *h100 %capture%
  173. GuiControl, Text, Search,
  174.  
  175. ToolTip
  176. return
  177.  
  178.  
  179.  
  180. WebRequest(url, method := "GET", HeadersArray := "", body := "", ByRef error := "") {
  181.    Whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
  182.    Whr.Open(method, url, true)
  183.    for name, value in HeadersArray
  184.       Whr.SetRequestHeader(name, value)
  185.    Whr.Send(body)
  186.    Whr.WaitForResponse()
  187.    status := Whr.status
  188.    if (status != 200)
  189.       error := "HttpRequest error, status: " . status
  190.    Arr := Whr.responseBody
  191.    pData := NumGet(ComObjValue(Arr) + 8 + A_PtrSize)
  192.    length := Arr.MaxIndex() + 1
  193.    Return StrGet(pData, length, "UTF-8")
  194. }
  195.  
  196. DocumentFromHtml(html, mode := 9) {
  197.    document := ComObjCreate("HTMLFILE")
  198.    document.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=" . mode . """>")
  199.    document.write(html)
  200.    Return document
  201. }
  202.  
  203.  
  204. WM_MOUSEMOVE(wParam,lParam)
  205. {
  206.    If (A_GuiControl = "Search")
  207.    {
  208.       GuiControlGet, OutputVar,, Search
  209.       if ( OutputVar = "№ позиции")
  210.          GuiControl, Text, Search,
  211.     }  
  212.    
  213.   Global hCurs
  214.   MouseGetPos,,,,ctrl
  215.   IfInString ctrl, Static1
  216.     DllCall("SetCursor","UInt",hCurs)
  217.   Return
  218. }
  219.  
  220. IsNumberInRange(var,low)
  221. {
  222.    If (StrLen(var) > low)
  223.       Return 1
  224. }
  225.  
  226.  
  227. label_none:
  228. chek_tag :=
  229. qq :=
  230. qq2 :=
  231. LV_Delete()
  232. GuiControl, Text, Name,
  233. GuiControl,, Images,
  234. fullname := ""
  235. return
  236.  
  237.  
  238.  
  239. ^esc::ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement