fork download
  1. import subprocess
  2. import json
  3. import os
  4. import sys
  5.  
  6. API_OUTPUT_FILE = "output.json"
  7. def parse(self, response):
  8. self.logger.debug(f"Response URL: {response.url}")
  9. self.logger.debug(f"Response Headers: {response.headers}")
  10. self.logger.debug(f"Response Text (first 500 chars): {response.text[:500]}")
  11.  
  12. try:
  13. body = response.text
  14. data = json.loads(body)
  15.  
  16. for ad in data.get("data", []):
  17. yield {
  18. "title": ad.get("title"),
  19. "price": ad.get("price", {}).get("value"),
  20. "location": ad.get("locations_resolved", {}).get("COUNTRY_name"),
  21. "url": ad.get("url"),
  22. }
  23.  
  24. except Exception as e:
  25. self.logger.warning(f"JSON parsing failed: {e}")
  26. self.logger.warning("Falling back to HTML spider.")
  27. self.crawler.engine.close_spider(self, reason="api_failed")
  28. import os
  29. import subprocess
  30. import json
  31. import sys
  32. def run_spider(spider_name):
  33. print(f"\nšŸš€ Running spider: {spider_name}")
  34. result = subprocess.run(
  35. ["scrapy", "crawl", spider_name],
  36. stdout=subprocess.PIPE,
  37. stderr=subprocess.STDOUT,
  38. text=True,
  39. )
  40. print(result.stdout)
  41. return result.returncode == 0
  42.  
  43. def json_has_items(file_path):
  44. if not os.path.exists(file_path):
  45. print("āš ļø Output file not found.")
  46. return False
  47. try:
  48. with open(file_path, "r", encoding="utf-8") as f:
  49. data = json.load(f)
  50. if isinstance(data, list) and len(data) > 0:
  51. print(f"āœ… API spider succeeded with {len(data)} items.")
  52. return True
  53. else:
  54. print("āš ļø API output is empty.")
  55. return False
  56. except Exception as e:
  57. print(f"āŒ Failed to parse JSON: {e}")
  58. return False
  59.  
  60. def main():
  61. print("🌐 Attempting API scrape...")
  62. api_success = run_spider("olx_api")
  63.  
  64. if not api_success or not json_has_items(API_OUTPUT_FILE):
  65. print("šŸ”„ Falling back to HTML spider (olx_buildings)...")
  66. run_spider("olx_buildings")
  67.  
  68. print("āœ… Done.")
  69.  
  70. if __name__ == "__main__":
  71. main()
  72.  
  73.  
  74.  
  75.  
  76.  
  77. # import scrapy
  78. # import re
  79. # from olx_scraper.items import OlxScraperItem
  80.  
  81.  
  82. # class OlxBuildingsSpider(scrapy.Spider):
  83. # name = "olx_buildings"
  84. # start_urls = [
  85. # "https://w...content-available-to-author-only...x.in/kozhikode_g4058877/for-rent-houses-apartments_c1723"
  86. # ]
  87.  
  88. # def start_requests(self):
  89. # for url in self.start_urls:
  90. # yield scrapy.Request(
  91. # url,
  92. # meta={
  93. # "playwright": True,
  94. # "playwright_include_page": True,
  95. # "playwright_page_methods": [
  96. # {
  97. # "method": "evaluate",
  98. # "expression": """
  99. # () => {
  100. # Object.defineProperty(navigator, 'webdriver', { get: () => false });
  101. # window.navigator.chrome = { runtime: {} };
  102. # window.navigator.plugins = [1, 2, 3];
  103. # window.navigator.languages = ['en-US', 'en'];
  104. # }
  105. # """
  106. # },
  107. # {
  108. # "method": "wait_for_selector",
  109. # "selector": "a._95r8F"
  110. # }
  111. # ]
  112. # },
  113. # callback=self.parse
  114. # )
  115. # async def parse(self, response):
  116. # with open("debug.html", "w", encoding="utf-8") as f:
  117. # f.write(response.text)
  118. # property_links = response.css("a._95r8F::attr(href)").getall()
  119. # for href in property_links:
  120. # yield response.follow(
  121. # href,
  122. # callback=self.parse_listing,
  123. # meta={"playwright": True}
  124. # )
  125.  
  126.  
  127. # async def parse(self, response):
  128. # property_links = response.css("a._95r8F::attr(href)").getall()
  129. # for href in property_links:
  130. # yield response.follow(
  131. # href,
  132. # callback=self.parse_listing,
  133. # meta={"playwright": True}
  134. # )
  135.  
  136. # async def parse_listing(self, response):
  137. # item = OlxScraperItem()
  138. # item["property_name"] = response.css("h1::text").get()
  139. # item["property_id"] = response.url.split("-iid-")[-1]
  140. # item["breadcrumbs"] = response.css("li._2gcMP a::text").getall()
  141.  
  142. # price_text = response.css("span._3FkyT::text").get()
  143. # item["price"] = {
  144. # "amount": price_text or "",
  145. # "currency": re.search(r"[^\d]+", price_text).group() if price_text else ""
  146. # }
  147.  
  148. # item["image_url"] = response.css("img::attr(src)").get()
  149. # item["description"] = response.css("div._1q8vA::text").get()
  150. # item["seller_name"] = response.css("div._3oOe9 span::text").get()
  151. # item["location"] = response.css("div._2CNjF::text").get()
  152. # item["property_type"] = "Apartments"
  153. # item["bathrooms"] = None
  154. # item["bedrooms"] = None
  155. # yield item
  156.  
  157. # def close(self, reason):
  158. # self.logger.info(f"Spider closed: {self.name}, reason: {reason}")
  159. # with open("debug.html", "w", encoding="utf-8") as f:
  160. # f.write(self.crawler.stats.get_value("response_body"))
  161. # self.logger.info("Debug HTML written to debug.html")
  162. # self.logger.info("Spider finished successfully.")
  163. # self.logger.info(f"Total items scraped: {self.crawler.stats.get_value('item_scraped_count')}")
  164. # self.logger.info(f"Total requests made: {self.crawler.stats.get_value('downloader/request_count')}")
  165. # self.logger.info(f"Total responses received: {self.crawler.stats.get_value('downloader/response_count')}")
  166. # self.logger.info(f"Total errors encountered: {self.crawler.stats.get_value('log_count/ERROR')}")
  167. # self.logger.info(f"Total warnings encountered: {self.crawler.stats.get_value('log_count/WARNING')}")
  168. # self.logger.info(f"Total time taken: {self.crawler.stats.get_value('elapsed_time_seconds')} seconds")
  169. # self.logger.info("Spider closed successfully.")
  170. /* package whatever; // don't place package name! */
  171. /*
  172.  
  173.   This source code accompanies the article, "Using The Golay Error Detection And
  174.   Correction Code", by Hank Wallace. This program demonstrates use of the Golay
  175.   code.
  176.   Usage: G DATA Encode/Correct/Verify/Test
  177.   where DATA is the data to be encoded, codeword to be corrected,
  178.   or codeword to be checked for errors. DATA is hexadecimal.
  179.   Examples:
  180.   G 555 E encodes information value 555 and prints a codeword
  181.   G ABC123 C corrects codeword ABC123
  182.   G ABC123 V checks codeword ABC123 for errors
  183.   G ABC123 T tests routines, ABC123 is a dummy parameter
  184.   This program may be freely incorporated into your programs as needed. It
  185.   compiles under Borland's Turbo C 2.0. No warranty of any kind is granted.
  186.   */
  187. #include "stdio.h"
  188. #include "conio.h"
  189. #define POLY 0xAE3 /* or use the other polynomial, 0xC75 */
  190.  
  191. /* ====================================================== */
  192.  
  193. unsigned long golay(unsigned long cw)
  194. /* This function calculates [23,12] Golay codewords.
  195.   The format of the returned longint is
  196.   [checkbits(11),data(12)]. */
  197. {
  198. int i;
  199. unsigned long c;
  200. cw&=0xfffl;
  201. c=cw; /* save original codeword */
  202. for (i=1; i<=12; i++) /* examine each data bit */
  203. {
  204. if (cw & 1) /* test data bit */
  205. cw^=POLY; /* XOR polynomial */
  206. cw>>=1; /* shift intermediate result */
  207. }
  208. return((cw<<12)|c); /* assemble codeword */
  209. }
  210.  
  211. /* ====================================================== */
  212.  
  213. int parity(unsigned long cw)
  214. /* This function checks the overall parity of codeword cw.
  215.   If parity is even, 0 is returned, else 1. */
  216. {
  217. unsigned char p;
  218.  
  219. /* XOR the bytes of the codeword */
  220. p=*(unsigned char*)&cw;
  221. p^=*((unsigned char*)&cw+1);
  222. p^=*((unsigned char*)&cw+2);
  223.  
  224. /* XOR the halves of the intermediate result */
  225. p=p ^ (p>>4);
  226. p=p ^ (p>>2);
  227. p=p ^ (p>>1);
  228.  
  229. /* return the parity result */
  230. return(p & 1);
  231. }
  232.  
  233. /* ====================================================== */
  234.  
  235. unsigned long syndrome(unsigned long cw)
  236. /* This function calculates and returns the syndrome
  237.   of a [23,12] Golay codeword. */
  238. {
  239. int i;
  240. cw&=0x7fffffl;
  241. for (i=1; i<=12; i++) /* examine each data bit */
  242. {
  243. if (cw & 1) /* test data bit */
  244. cw^=POLY; /* XOR polynomial */
  245. cw>>=1; /* shift intermediate result */
  246. }
  247. return(cw<<12); /* value pairs with upper bits of cw */
  248. }
  249.  
  250. /* ====================================================== */
  251.  
  252. int weight(unsigned long cw)
  253. /* This function calculates the weight of
  254.   23 bit codeword cw. */
  255. {
  256. int bits,k;
  257.  
  258. /* nibble weight table */
  259. const char wgt[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
  260.  
  261. bits=0; /* bit counter */
  262. k=0;
  263. /* do all bits, six nibbles max */
  264. while ((k<6) && (cw))
  265. {
  266. bits=bits+wgt[cw & 0xf];
  267. cw>>=4;
  268. k++;
  269. }
  270.  
  271. return(bits);
  272. }
  273.  
  274. /* ====================================================== */
  275.  
  276. unsigned long rotate_left(unsigned long cw, int n)
  277. /* This function rotates 23 bit codeword cw left by n bits. */
  278. {
  279. int i;
  280.  
  281. if (n != 0)
  282. {
  283. for (i=1; i<=n; i++)
  284. {
  285. if ((cw & 0x400000l) != 0)
  286. cw=(cw << 1) | 1;
  287. else
  288. cw<<=1;
  289. }
  290. }
  291.  
  292. return(cw & 0x7fffffl);
  293. }
  294.  
  295. /* ====================================================== */
  296.  
  297. unsigned long rotate_right(unsigned long cw, int n)
  298. /* This function rotates 23 bit codeword cw right by n bits. */
  299. {
  300. int i;
  301.  
  302. if (n != 0)
  303. {
  304. for (i=1; i<=n; i++)
  305. {
  306. if ((cw & 1) != 0)
  307. cw=(cw >> 1) | 0x400000l;
  308. else
  309. cw>>=1;
  310. }
  311. }
  312.  
  313. return(cw & 0x7fffffl);
  314. }
  315.  
  316. /* ====================================================== */
  317.  
  318. unsigned long correct(unsigned long cw, int *errs)
  319. /* This function corrects Golay [23,12] codeword cw, returning the
  320.   corrected codeword. This function will produce the corrected codeword
  321.   for three or fewer errors. It will produce some other valid Golay
  322.   codeword for four or more errors, possibly not the intended
  323.   one. *errs is set to the number of bit errors corrected. */
  324. {
  325. unsigned char
  326. w; /* current syndrome limit weight, 2 or 3 */
  327. unsigned long
  328. mask; /* mask for bit flipping */
  329. int
  330. i,j; /* index */
  331. unsigned long
  332. s, /* calculated syndrome */
  333. cwsaver; /* saves initial value of cw */
  334.  
  335. cwsaver=cw; /* save */
  336. *errs=0;
  337. w=3; /* initial syndrome weight threshold */
  338. j=-1; /* -1 = no trial bit flipping on first pass */
  339. mask=1;
  340. while (j<23) /* flip each trial bit */
  341. {
  342. if (j != -1) /* toggle a trial bit */
  343. {
  344. if (j>0) /* restore last trial bit */
  345. {
  346. cw=cwsaver ^ mask;
  347. mask+=mask; /* point to next bit */
  348. }
  349. cw=cwsaver ^ mask; /* flip next trial bit */
  350. w=2; /* lower the threshold while bit diddling */
  351. }
  352.  
  353. s=syndrome(cw); /* look for errors */
  354. if (s) /* errors exist */
  355. {
  356. for (i=0; i<23; i++) /* check syndrome of each cyclic shift */
  357. {
  358. if ((*errs=weight(s)) <= w) /* syndrome matches error pattern */
  359. {
  360. cw=cw ^ s; /* remove errors */
  361. cw=rotate_right(cw,i); /* unrotate data */
  362. return(s=cw);
  363. }
  364. else
  365. {
  366. cw=rotate_left(cw,1); /* rotate to next pattern */
  367. s=syndrome(cw); /* calc new syndrome */
  368. }
  369. }
  370. j++; /* toggle next trial bit */
  371. }
  372. else
  373. return(cw); /* return corrected codeword */
  374. }
  375.  
  376. return(cwsaver); /* return original if no corrections */
  377. } /* correct */
  378.  
  379. /* ====================================================== */
  380.  
  381. int decode(int correct_mode, int *errs, unsigned long *cw)
  382. /* This function decodes codeword *cw in one of two modes. If correct_mode
  383.   is nonzero, error correction is attempted, with *errs set to the number of
  384.   bits corrected, and returning 0 if no errors exist, or 1 if parity errors
  385.   exist. If correct_mode is zero, error detection is performed on *cw,
  386.   returning 0 if no errors exist, 1 if an overall parity error exists, and
  387.   2 if a codeword error exists. */
  388. {
  389. unsigned long parity_bit;
  390.  
  391. if (correct_mode) /* correct errors */
  392. {
  393. parity_bit=*cw & 0x800000l; /* save parity bit */
  394. *cw&=~0x800000l; /* remove parity bit for correction */
  395.  
  396. *cw=correct(*cw, errs); /* correct up to three bits */
  397. *cw|=parity_bit; /* restore parity bit */
  398.  
  399. /* check for 4 bit errors */
  400. if (parity(*cw)) /* odd parity is an error */
  401. return(1);
  402. return(0); /* no errors */
  403. }
  404. else /* detect errors only */
  405. {
  406. *errs=0;
  407. if (parity(*cw)) /* odd parity is an error */
  408. {
  409. *errs=1;
  410. return(1);
  411. }
  412. if (syndrome(*cw))
  413. {
  414. *errs=1;
  415. return(2);
  416. }
  417. else
  418. return(0); /* no errors */
  419. }
  420. } /* decode */
  421.  
  422. /* ====================================================== */
  423.  
  424. void golay_test(void)
  425. /* This function tests the Golay routines for detection and correction
  426.   of various patterns of error_limit bit errors. The error_mask cycles
  427.   over all possible values, and error_limit selects the maximum number
  428.   of induced errors. */
  429. {
  430. unsigned long
  431. error_mask, /* bitwise mask for inducing errors */
  432. trashed_codeword, /* the codeword for trial correction */
  433. virgin_codeword; /* the original codeword without errors */
  434. unsigned char
  435. pass=1, /* assume test passes */
  436. error_limit=3; /* select number of induced bit errors here */
  437. int
  438. error_count; /* receives number of errors corrected */
  439.  
  440. virgin_codeword=golay(0x555); /* make a test codeword */
  441. if (parity(virgin_codeword))
  442. virgin_codeword^=0x800000l;
  443. for (error_mask=0; error_mask<0x800000l; error_mask++)
  444. {
  445. /* filter the mask for the selected number of bit errors */
  446. if (weight(error_mask) <= error_limit) /* you can make this faster! */
  447. {
  448. trashed_codeword=virgin_codeword ^ error_mask; /* induce bit errors */
  449.  
  450. decode(1,&error_count,&trashed_codeword); /* try to correct bit errors */
  451.  
  452. if (trashed_codeword ^ virgin_codeword)
  453. {
  454. printf("Unable to correct %d errors induced with error mask = 0x%lX\n",
  455. weight(error_mask),error_mask);
  456. pass=0;
  457. }
  458.  
  459. if (kbhit()) /* look for user input */
  460. {
  461. if (getch() == 27) return; /* escape exits */
  462.  
  463. /* other key prints status */
  464. printf("Current test count = %ld of %ld\n",error_mask,0x800000l);
  465. }
  466. }
  467. }
  468. printf("Golay test %s!\n",pass?"PASSED":"FAILED");
  469. }
  470.  
  471. /* ====================================================== */
  472.  
  473. void main(int argument_count, char *argument[])
  474. {
  475. int i,j;
  476. unsigned long l,g;
  477. const char *errmsg = "Usage: G DATA Encode/Correct/Verify/Test\n\n"
  478. " where DATA is the data to be encoded, codeword to be corrected,\n"
  479. " or codeword to be checked for errors. DATA is hexadecimal.\n\n"
  480. "Examples:\n\n"
  481. " G 555 E encodes information value 555 and prints a codeword\n"
  482. " G ABC123 C corrects codeword ABC123\n"
  483. " G ABC123 V checks codeword ABC123 for errors\n"
  484. " G ABC123 T tests routines, ABC123 is a dummy parameter\n\n";
  485.  
  486. if (argument_count != 3)
  487. {
  488. printf(errmsg);
  489. exit(0);
  490. }
  491.  
  492. if (sscanf(argument[1],"%lx",&l) != 1)
  493. {
  494. printf(errmsg);
  495. exit(0);
  496. }
  497.  
  498. switch (toupper(*argument[2]))
  499. {
  500. case 'E': /* encode */
  501. l&=0xfff;
  502. l=golay(l);
  503. if (parity(l)) l^=0x800000l;
  504. printf("Codeword = %lX\n",l);
  505. break;
  506.  
  507. case 'V': /* verify */
  508. if (decode(0,&i,&l))
  509. printf("Codeword %lX is not a Golay codeword.\n",l);
  510. else
  511. printf("Codeword %lX is a Golay codeword.\n",l);
  512. break;
  513.  
  514. case 'C': /* correct */
  515. g=l; /* save initial codeword */
  516. j=decode(1,&i,&l);
  517. if ((j) && (i))
  518. printf("Codeword %lX had %d bits corrected,\n"
  519. "resulting in codeword %lX with a parity error.\n",g,i,l);
  520. else
  521. if ((j == 0) && (i))
  522. printf("Codeword %lX had %d bits corrected, resulting in codeword %lX.\n",g,i,l);
  523. else
  524. if ((j) && (i == 0))
  525. printf("Codeword %lX has a parity error. No bits were corrected.\n",g);
  526. else
  527. if ((j == 0) && (i == 0))
  528. printf("Codeword %lX does not require correction.\n",g);
  529. break;
  530.  
  531. case 'T': /* test */
  532. printf("Press SPACE for status, ESC to exit test...\n");
  533. golay_test();
  534. break;
  535.  
  536. default:
  537. printf(errmsg);
  538. exit(0);
  539. }
  540. }
  541.  
  542. /* end of G.C */
  543.  
  544.  
  545. import java.util.*;
  546. import java.lang.*;
  547. import java.io.*;
  548.  
  549. /* Name of the class has to be "Main" only if the class is public. */
  550. class Ideone
  551. {
  552. public static void main (String[] args) throws java.lang.Exception
  553. {
  554. // your code goes here
  555. }
  556. }
Success #stdin #stdout 0.04s 25708KB
stdin
Standard input is empty
stdout
import subprocess
import json
import os
import sys

API_OUTPUT_FILE = "output.json"
def parse(self, response):
    self.logger.debug(f"Response URL: {response.url}")
    self.logger.debug(f"Response Headers: {response.headers}")
    self.logger.debug(f"Response Text (first 500 chars): {response.text[:500]}")

    try:
        body = response.text
        data = json.loads(body)

        for ad in data.get("data", []):
            yield {
                "title": ad.get("title"),
                "price": ad.get("price", {}).get("value"),
                "location": ad.get("locations_resolved", {}).get("COUNTRY_name"),
                "url": ad.get("url"),
            }

    except Exception as e:
        self.logger.warning(f"JSON parsing failed: {e}")
        self.logger.warning("Falling back to HTML spider.")
        self.crawler.engine.close_spider(self, reason="api_failed")
import os
import subprocess
import json     
import sys
def run_spider(spider_name):
    print(f"\nšŸš€ Running spider: {spider_name}")
    result = subprocess.run(
        ["scrapy", "crawl", spider_name],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        text=True,
    )
    print(result.stdout)
    return result.returncode == 0

def json_has_items(file_path):
    if not os.path.exists(file_path):
        print("āš ļø Output file not found.")
        return False
    try:
        with open(file_path, "r", encoding="utf-8") as f:
            data = json.load(f)
            if isinstance(data, list) and len(data) > 0:
                print(f"āœ… API spider succeeded with {len(data)} items.")
                return True
            else:
                print("āš ļø API output is empty.")
                return False
    except Exception as e:
        print(f"āŒ Failed to parse JSON: {e}")
        return False

def main():
    print("🌐 Attempting API scrape...")
    api_success = run_spider("olx_api")

    if not api_success or not json_has_items(API_OUTPUT_FILE):
        print("šŸ”„ Falling back to HTML spider (olx_buildings)...")
        run_spider("olx_buildings")

    print("āœ… Done.")

if __name__ == "__main__":
    main()





# import scrapy
# import re
# from olx_scraper.items import OlxScraperItem


# class OlxBuildingsSpider(scrapy.Spider):
#     name = "olx_buildings"
#     start_urls = [
#         "https://w...content-available-to-author-only...x.in/kozhikode_g4058877/for-rent-houses-apartments_c1723"
#     ]

#     def start_requests(self):
#         for url in self.start_urls:
#             yield scrapy.Request(
#                 url,
#                 meta={
#                     "playwright": True,
#                     "playwright_include_page": True,
#                     "playwright_page_methods": [
#                         {
#                             "method": "evaluate",
#                             "expression": """
#                                 () => {
#                                     Object.defineProperty(navigator, 'webdriver', { get: () => false });
#                                     window.navigator.chrome = { runtime: {} };
#                                     window.navigator.plugins = [1, 2, 3];
#                                     window.navigator.languages = ['en-US', 'en'];
#                                 }
#                             """
#                         },
#                         {
#                             "method": "wait_for_selector",
#                             "selector": "a._95r8F"
#                         }
#                     ]
#                 },
#                 callback=self.parse
#             )
#     async def parse(self, response):
#      with open("debug.html", "w", encoding="utf-8") as f:
#         f.write(response.text)
#         property_links = response.css("a._95r8F::attr(href)").getall()
#         for href in property_links:
#             yield response.follow(
#                 href,
#                 callback=self.parse_listing,
#                 meta={"playwright": True}
#             )


#     async def parse(self, response):
#         property_links = response.css("a._95r8F::attr(href)").getall()
#         for href in property_links:
#             yield response.follow(
#                 href,
#                 callback=self.parse_listing,
#                 meta={"playwright": True}
#             )

#     async def parse_listing(self, response):
#         item = OlxScraperItem()
#         item["property_name"] = response.css("h1::text").get()
#         item["property_id"] = response.url.split("-iid-")[-1]
#         item["breadcrumbs"] = response.css("li._2gcMP a::text").getall()

#         price_text = response.css("span._3FkyT::text").get()
#         item["price"] = {
#             "amount": price_text or "",
#             "currency": re.search(r"[^\d]+", price_text).group() if price_text else ""
#         }

#         item["image_url"] = response.css("img::attr(src)").get()
#         item["description"] = response.css("div._1q8vA::text").get()
#         item["seller_name"] = response.css("div._3oOe9 span::text").get()
#         item["location"] = response.css("div._2CNjF::text").get()
#         item["property_type"] = "Apartments"
#         item["bathrooms"] = None
#         item["bedrooms"] = None
#         yield item

#     def close(self, reason):
#         self.logger.info(f"Spider closed: {self.name}, reason: {reason}")
#         with open("debug.html", "w", encoding="utf-8") as f:
#             f.write(self.crawler.stats.get_value("response_body"))  
#         self.logger.info("Debug HTML written to debug.html")    
#         self.logger.info("Spider finished successfully.")
#         self.logger.info(f"Total items scraped: {self.crawler.stats.get_value('item_scraped_count')}")
#         self.logger.info(f"Total requests made: {self.crawler.stats.get_value('downloader/request_count')}")
#         self.logger.info(f"Total responses received: {self.crawler.stats.get_value('downloader/response_count')}")
#         self.logger.info(f"Total errors encountered: {self.crawler.stats.get_value('log_count/ERROR')}")
#         self.logger.info(f"Total warnings encountered: {self.crawler.stats.get_value('log_count/WARNING')}")
#         self.logger.info(f"Total time taken: {self.crawler.stats.get_value('elapsed_time_seconds')} seconds")
#         self.logger.info("Spider closed successfully.")
       /* package whatever; // don't place package name! */
/*
    
    This source code accompanies the article, "Using The Golay Error Detection And
    Correction Code", by Hank Wallace. This program demonstrates use of the Golay
    code.
      Usage: G DATA Encode/Correct/Verify/Test
        where DATA is the data to be encoded, codeword to be corrected,
        or codeword to be checked for errors. DATA is hexadecimal.
      Examples:
        G 555 E      encodes information value 555 and prints a codeword
        G ABC123 C   corrects codeword ABC123
        G ABC123 V   checks codeword ABC123 for errors
        G ABC123 T   tests routines, ABC123 is a dummy parameter
    This program may be freely incorporated into your programs as needed. It
    compiles under Borland's Turbo C 2.0. No warranty of any kind is granted.
    */
    #include "stdio.h"
    #include "conio.h"
    #define POLY  0xAE3  /* or use the other polynomial, 0xC75 */
    
    /* ====================================================== */
    
    unsigned long golay(unsigned long cw)
    /* This function calculates [23,12] Golay codewords.
      The format of the returned longint is
      [checkbits(11),data(12)]. */
    {
      int i;
      unsigned long c;
      cw&=0xfffl;
      c=cw; /* save original codeword */
      for (i=1; i<=12; i++)  /* examine each data bit */
        {
          if (cw & 1)        /* test data bit */
            cw^=POLY;        /* XOR polynomial */
          cw>>=1;            /* shift intermediate result */
        }
      return((cw<<12)|c);    /* assemble codeword */
    }
    
    /* ====================================================== */
    
    int parity(unsigned long cw)
    /* This function checks the overall parity of codeword cw.
      If parity is even, 0 is returned, else 1. */
    {
      unsigned char p;
    
      /* XOR the bytes of the codeword */
      p=*(unsigned char*)&cw;
      p^=*((unsigned char*)&cw+1);
      p^=*((unsigned char*)&cw+2);
    
      /* XOR the halves of the intermediate result */
      p=p ^ (p>>4);
      p=p ^ (p>>2);
      p=p ^ (p>>1);
    
      /* return the parity result */
      return(p & 1);
    }
    
    /* ====================================================== */
    
    unsigned long syndrome(unsigned long cw)
    /* This function calculates and returns the syndrome
      of a [23,12] Golay codeword. */
    {
      int i;
      cw&=0x7fffffl;
      for (i=1; i<=12; i++)  /* examine each data bit */
        {
          if (cw & 1)        /* test data bit */
            cw^=POLY;        /* XOR polynomial */
          cw>>=1;            /* shift intermediate result */
        }
      return(cw<<12);        /* value pairs with upper bits of cw */
    }
    
    /* ====================================================== */
    
    int weight(unsigned long cw)
    /* This function calculates the weight of
      23 bit codeword cw. */
    {
      int bits,k;
    
      /* nibble weight table */
      const char wgt[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
    
      bits=0; /* bit counter */
      k=0;
      /* do all bits, six nibbles max */
      while ((k<6) && (cw))
        {
          bits=bits+wgt[cw & 0xf];
          cw>>=4;
          k++;
        }
    
      return(bits);
    }
    
    /* ====================================================== */
    
    unsigned long rotate_left(unsigned long cw, int n)
    /* This function rotates 23 bit codeword cw left by n bits. */
    {
      int i;
    
      if (n != 0)
        {
          for (i=1; i<=n; i++)
            {
              if ((cw & 0x400000l) != 0)
                cw=(cw << 1) | 1;
              else
                cw<<=1;
            }
        }
    
      return(cw & 0x7fffffl);
    }
    
    /* ====================================================== */
    
    unsigned long rotate_right(unsigned long cw, int n)
    /* This function rotates 23 bit codeword cw right by n bits. */
    {
      int i;
    
      if (n != 0)
        {
          for (i=1; i<=n; i++)
            {
              if ((cw & 1) != 0)
                cw=(cw >> 1) | 0x400000l;
              else
                cw>>=1;
            }
        }
    
      return(cw & 0x7fffffl);
    }
    
    /* ====================================================== */
    
    unsigned long correct(unsigned long cw, int *errs)
    /* This function corrects Golay [23,12] codeword cw, returning the
      corrected codeword. This function will produce the corrected codeword
      for three or fewer errors. It will produce some other valid Golay
      codeword for four or more errors, possibly not the intended
      one. *errs is set to the number of bit errors corrected. */
    {
      unsigned char
        w;                /* current syndrome limit weight, 2 or 3 */
      unsigned long
        mask;             /* mask for bit flipping */
      int
        i,j;              /* index */
      unsigned long
        s,                /* calculated syndrome */
        cwsaver;          /* saves initial value of cw */
    
      cwsaver=cw;         /* save */
      *errs=0;
      w=3;                /* initial syndrome weight threshold */
      j=-1;               /* -1 = no trial bit flipping on first pass */
      mask=1;
      while (j<23) /* flip each trial bit */
        {
          if (j != -1) /* toggle a trial bit */
            {
              if (j>0) /* restore last trial bit */
                {
                  cw=cwsaver ^ mask;
                  mask+=mask; /* point to next bit */
                }
              cw=cwsaver ^ mask; /* flip next trial bit */
              w=2; /* lower the threshold while bit diddling */
            }
    
          s=syndrome(cw); /* look for errors */
          if (s) /* errors exist */
            {
              for (i=0; i<23; i++) /* check syndrome of each cyclic shift */
                {
                  if ((*errs=weight(s)) <= w) /* syndrome matches error pattern */
                    {
                      cw=cw ^ s;              /* remove errors */
                      cw=rotate_right(cw,i);  /* unrotate data */
                      return(s=cw);
                    }
                  else
                    {
                      cw=rotate_left(cw,1);   /* rotate to next pattern */
                      s=syndrome(cw);         /* calc new syndrome */
                    }
                }
              j++; /* toggle next trial bit */
            }
          else
            return(cw); /* return corrected codeword */
        }
    
      return(cwsaver); /* return original if no corrections */
    } /* correct */
    
    /* ====================================================== */
    
    int decode(int correct_mode, int *errs, unsigned long *cw)
    /* This function decodes codeword *cw in one of two modes. If correct_mode
      is nonzero, error correction is attempted, with *errs set to the number of
      bits corrected, and returning 0 if no errors exist, or 1 if parity errors
      exist. If correct_mode is zero, error detection is performed on *cw,
      returning 0 if no errors exist, 1 if an overall parity error exists, and
      2 if a codeword error exists. */
    {
      unsigned long parity_bit;
    
      if (correct_mode)               /* correct errors */
        {
          parity_bit=*cw & 0x800000l; /* save parity bit */
          *cw&=~0x800000l;            /* remove parity bit for correction */
    
          *cw=correct(*cw, errs);     /* correct up to three bits */
          *cw|=parity_bit;            /* restore parity bit */
    
          /* check for 4 bit errors */
          if (parity(*cw))            /* odd parity is an error */
            return(1);
          return(0); /* no errors */
        }
      else /* detect errors only */
        {
          *errs=0;
          if (parity(*cw)) /* odd parity is an error */
            {
              *errs=1;
              return(1);
            }
          if (syndrome(*cw))
            {
              *errs=1;
              return(2);
            }
          else
            return(0); /* no errors */
        }
    } /* decode */
    
    /* ====================================================== */
    
    void golay_test(void)
    /* This function tests the Golay routines for detection and correction
      of various patterns of error_limit bit errors. The error_mask cycles
      over all possible values, and error_limit selects the maximum number
      of induced errors. */
    {
      unsigned long
        error_mask,         /* bitwise mask for inducing errors */
        trashed_codeword,   /* the codeword for trial correction */
        virgin_codeword;    /* the original codeword without errors */
      unsigned char
        pass=1,             /* assume test passes */
        error_limit=3;      /* select number of induced bit errors here */
      int
        error_count;        /* receives number of errors corrected */
    
      virgin_codeword=golay(0x555); /* make a test codeword */
      if (parity(virgin_codeword))
        virgin_codeword^=0x800000l;
      for (error_mask=0; error_mask<0x800000l; error_mask++)
        {
          /* filter the mask for the selected number of bit errors */
          if (weight(error_mask) <= error_limit) /* you can make this faster! */
            {
              trashed_codeword=virgin_codeword ^ error_mask; /* induce bit errors */
    
              decode(1,&error_count,&trashed_codeword); /* try to correct bit errors */
    
              if (trashed_codeword ^ virgin_codeword)
                {
                  printf("Unable to correct %d errors induced with error mask = 0x%lX\n",
                    weight(error_mask),error_mask);
                  pass=0;
                }
    
              if (kbhit()) /* look for user input */
                {
                  if (getch() == 27) return; /* escape exits */
    
                  /* other key prints status */
                  printf("Current test count = %ld of %ld\n",error_mask,0x800000l);
                }
            }
        }
      printf("Golay test %s!\n",pass?"PASSED":"FAILED");
    }
    
    /* ====================================================== */
    
    void main(int argument_count, char *argument[])
    {
      int i,j;
      unsigned long l,g;
      const char *errmsg = "Usage: G DATA Encode/Correct/Verify/Test\n\n"
                 "  where DATA is the data to be encoded, codeword to be corrected,\n"
                 "  or codeword to be checked for errors. DATA is hexadecimal.\n\n"
                 "Examples:\n\n"
                 "  G 555 E      encodes information value 555 and prints a codeword\n"
                 "  G ABC123 C   corrects codeword ABC123\n"
                 "  G ABC123 V   checks codeword ABC123 for errors\n"
                 "  G ABC123 T   tests routines, ABC123 is a dummy parameter\n\n";
    
      if (argument_count != 3)
        {
          printf(errmsg);
          exit(0);
        }
    
      if (sscanf(argument[1],"%lx",&l) != 1)
        {
          printf(errmsg);
          exit(0);
        }
    
      switch (toupper(*argument[2]))
        {
          case 'E': /* encode */
            l&=0xfff;
            l=golay(l);
            if (parity(l)) l^=0x800000l;
            printf("Codeword = %lX\n",l);
            break;
    
          case 'V': /* verify */
            if (decode(0,&i,&l))
              printf("Codeword %lX is not a Golay codeword.\n",l);
            else
              printf("Codeword %lX is a Golay codeword.\n",l);
            break;
    
          case 'C': /* correct */
            g=l; /* save initial codeword */
            j=decode(1,&i,&l);
            if ((j) && (i))
              printf("Codeword %lX had %d bits corrected,\n"
                     "resulting in codeword %lX with a parity error.\n",g,i,l);
            else
              if ((j == 0) && (i))
                printf("Codeword %lX had %d bits corrected, resulting in codeword %lX.\n",g,i,l);
              else
                if ((j) && (i == 0))
                  printf("Codeword %lX has a parity error. No bits were corrected.\n",g);
                else
                  if ((j == 0) && (i == 0))
                    printf("Codeword %lX does not require correction.\n",g);
            break;
    
          case 'T': /* test */
            printf("Press SPACE for status, ESC to exit test...\n");
            golay_test();
            break;
    
          default:
            printf(errmsg);
            exit(0);
        }
    }
    
    /* end of G.C */


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
	}
}