Advertisement
plirof2

chess - scan_countries3a

Mar 21st, 2024 (edited)
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. const do_get_age=false;
  6. let age_table= new Array();
  7. let name_table= new Array();
  8. let pending=false;
  9.  
  10. let array_wanted_cities=["Sofia","СОФИЯ","Добринище","Dobrinishte","ЯКОРУДА","Yakoruda"];
  11. array_wanted_cities=[303, 303, 232, 232, 250, 250];
  12.  
  13.  
  14. function Html2Text(html="no-input-jon") {
  15.   let text = html.replace(/<[^>]+>/g, ''); // Remove all HTML tags
  16.   text = text.replace(/&nbsp;/g, ' '); // Replace   with empty space
  17.   text = text.replace(/&amp;/g, '&'); // Replace &amp; with &
  18.   text = text.replace(/&gt;/g, '>'); // Replace &gt; with >
  19.   text = text.replace(/&lt;/g, '<'); // Replace &lt; with <
  20.  
  21.   return text;
  22. }
  23.  
  24. function isWeekend(date) {
  25.     return (new Date(date).getDay() >= 6);
  26. }
  27.  
  28. function extract_text(str, start_text, end_text){
  29.     const regular = new RegExp(`${start_text}(.*?)${end_text}`);
  30.     const match = str.match(regular);
  31.     if (match) {
  32.         return match[1];
  33.     }
  34. }
  35.  
  36. function extract_next_text(data, start_text, length=10){
  37.     const part = data.substring(data.indexOf(start_text) + start_text.length, data.indexOf(start_text) + start_text.length + length);
  38.     return part;
  39. }
  40.  
  41. function checkIfFutureDate(given_date){
  42.     const givenDate = new Date(given_date);
  43.     const today = new Date();
  44.     return givenDate > today;
  45. }
  46.  
  47. function array_search_partial(keyword, arr) {
  48.     for(let i = 0; i < arr.length; i++) {
  49.         if (arr[i].includes(keyword)) {
  50.             return i;
  51.         }
  52.     }
  53. }
  54.  
  55. function fetch_tournament_data(tour_url="http://localhost"){
  56.     let tourdata = ["NOT FOUND", "--", "---"];
  57.    
  58.     return fetch(tour_url)
  59.     .then(response => response.text())
  60.     .then(data => {
  61.         const mytext = data;
  62.    
  63.         if (mytext.includes("To reduce the server load")) {
  64.             return ["OLD", "<font color='darkred'>OLD-ARCHIVED</font>", "", ""];
  65.         }
  66.    
  67.         const regex = /Arbiter(.*?)Pairing/;
  68.         const match = mytext.match(regex);
  69.    
  70.         if (match) {
  71.             let tourdata = match[1];
  72.             let plaintext = new Html2Text().convert(tourdata);
  73.    
  74.             let array = plaintext.toString().split("\n");
  75.    
  76.             let date = extract_next_text(plaintext, "Date", 13);
  77.             let location = extract_next_text(plaintext, "Location", 13);
  78.             let timecontrol = extract_next_text(plaintext, "Time", 13);
  79.             let ratingavg = array[array_search_partial('Rating-', array)];
  80.             ratingavg = ratingavg.substr(9, 25);
  81.    
  82.             location = array[array_search_partial("Location", array)].substr(9);
  83.             date = array[array_search_partial('Date', array)].substr(5, 25);
  84.             timecontrol = array[array_search_partial("Time", array)].substr(12, 20);
  85.    
  86.             tourdata = [date, location, timecontrol, ratingavg];
  87.         }
  88.    
  89.         return tourdata;
  90.     });
  91. }
  92.  
  93. let temp_keywords_pattern = '';
  94. let production_show = true;
  95. let country = "BUL";
  96. //let url = "https://corsproxy.io/?https://chess-results.com/fed.aspx?lan=1&fed=" + country;
  97. let url = "https://corsproxy.io/?https://chess-results.com/fed.aspx?lan=1&fed=" + country;
  98. let keywords_pattern = /(\bu12|u99|etc\b)/i;
  99. let fide_id=1111111;
  100. let player_url = "" + fide_id;
  101.  
  102. let txt = "";
  103. let split_text = '<td class="CRc">';
  104.  
  105. fetch(url)
  106. .then(response => response.text())
  107. .then(data => {
  108.     let mytext = data;
  109.     let result = mytext.toString().split(split_text);
  110.     result[0] = "";
  111.     console.log("result====="+result);
  112.     result.forEach(text => {
  113.         txt += text + "\n";
  114.     });
  115.  
  116.     txt = new Html2Text(txt);
  117.     let txt2 = txt.toString().split("\n");
  118.  
  119.     let end_result = "<ol>";
  120.  
  121.     txt2.forEach(string => {
  122.         if (string.match(keywords_pattern)) {
  123.             let matches = string.matchAll(/\[(.*?)\]/g);
  124.  
  125.             let name = matches[0][0].replace("[", "").replace("]", "");
  126.  
  127.             if (name.length < 4 || name.includes("Chess-Tournament-Results") || name.includes("Legal details")) {
  128.                 return;
  129.             }
  130.  
  131.             let snr = string.match(/snr\=\d{1,3}/g)[0].replace("snr=", "");
  132.             let tnr = string.match(/tnr\d{1,7}/g)[0].replace("tnr", "");
  133.  
  134.             let link = 'https://chess-results.com/tnr' + tnr + '.aspx?lan=1&turdet=YES';
  135.  
  136.             let tour_url = link;
  137.             fetch_tournament_data(tour_url)
  138.             .then(tourdata => {
  139.                 let date_only = tourdata[0].substr(0, 10);
  140.  
  141.                 if (!checkIfFutureDate(date_only)) {
  142.                     end_result += '<FONT COLOR=red>OLD - </FONT></TD></tr>';
  143.                     return;
  144.                 }
  145.  
  146.                 if (isWeekend(date_only)) {
  147.                     end_result += '<FONT COLOR=GREEN>WEEKEND- </FONT>';
  148.                 }
  149.  
  150.                 if (tourdata[3] > 1500) {
  151.                     end_result += '<FONT COLOR=CYAN>[elo:' + tourdata[3] + ']</FONT>';
  152.                 }
  153.  
  154.                 end_result += tourdata[1] + '</td><td>' + tourdata[0] + '</td><td>' + tourdata[2] + '</td><td>Elo:<BR>' + tourdata[3] + '</td>';
  155.  
  156.                 end_result += "<td><input type='checkbox' name='selected_names[]' id='player' value='" + name + "' />";
  157.                 let name2 = name;
  158.                 end_result += "<b><a target=_blank href='" + link + "'>" + name2 + "|</a></b>--";
  159.                 end_result += "</td></tr>";
  160.             });
  161.         }
  162.     });
  163.  
  164.     if (production_show) {
  165.         document.getElementById("result").innerHTML = end_result;
  166.     }
  167. });
  168.  
  169. </script>
  170. </head>
  171. <body>
  172. <form action="" method="POST">
  173. <input type="text" value="BUL" name="country">
  174.  
  175. <input type="submit">
  176. </form>
  177. <div id="result"></div>
  178. </body>
  179. </html>
  180.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement