Advertisement
York_86

Tennis_range_v2

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