Advertisement
leomaster

flyxcode

Feb 18th, 2024
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { readFile, writeFile } from 'fs/promises';
  2.  
  3. async function convert() {
  4.  
  5.         const rawdata = await readFile('raw.tsv', { encoding: 'utf8' })
  6.  
  7.         const rows = rawdata.replace(/\r/g,'').split('\n')
  8.  
  9.         const objdata = rows.map(row => {
  10.             const col = row.split('\t')
  11.             return ({
  12.                 id: col[0],
  13.                 legal: col[1],
  14.                 company: col[2],
  15.                 address: col[3],
  16.                 municipality: col[4],
  17.                 latitude: col[5],
  18.                 longitude: col[6]
  19.             })
  20.         })
  21.  
  22.         await writeFile('objdata.json', JSON.stringify(objdata, null, 4))
  23.  
  24. }
  25.  
  26. convert();
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. import fetch from 'node-fetch';
  36. import { load } from 'cheerio';
  37. import { readFile, writeFile } from 'fs/promises';
  38.  
  39.  
  40. let data = [];
  41.  
  42. async function example(i) {
  43.     try {
  44.       const $ = load(await readFile('neo/'+i+'.html', { encoding: 'utf8' }));
  45.  
  46.      
  47.  
  48.       $('tbody > tr').each( function (i,e) {
  49.  
  50.         let appId = $(this).find('a').attr('onclick')?.split(';')[0]?.split('=')[1];
  51.        
  52.         data.push([...$(this).text().split('\n').filter(i => i.trim()).map(i => i.trim()),appId]);
  53.        
  54.       });
  55.  
  56.       //console.log(data);
  57.  
  58.  
  59.     } catch (err) {
  60.      // console.log(err);
  61.     }
  62.   }
  63.  
  64.  
  65. async function platosmikos(appid, all) {
  66.     const $ = load(await (await fetch("https://keraies.eett.gr/getDetails.php", {
  67.         "headers": {
  68.           "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
  69.           "accept-language": "en-GB,en;q=0.9,en-US;q=0.8,el;q=0.7",
  70.           "cache-control": "max-age=0",
  71.           "content-type": "application/x-www-form-urlencoded",
  72.           "sec-ch-ua": "\"Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"115\", \"Chromium\";v=\"115\"",
  73.           "sec-ch-ua-mobile": "?1",
  74.           "sec-ch-ua-platform": "\"Android\"",
  75.           "sec-fetch-dest": "document",
  76.           "sec-fetch-mode": "navigate",
  77.           "sec-fetch-site": "same-origin",
  78.           "sec-fetch-user": "?1",
  79.           "upgrade-insecure-requests": "1",
  80.           "Referer": "https://keraies.eett.gr/getData.php",
  81.           "Referrer-Policy": "strict-origin-when-cross-origin"
  82.         },
  83.         "body": "appId="+appid,
  84.         "method": "POST"
  85.       }))?.text());
  86.  
  87.       let platos = $('body > div:nth-child(5) > div:nth-child(1) > div:nth-child(4) > div:nth-child(2) > p.list-group-item-heading2').text();
  88.       let mikos = $('body > div:nth-child(5) > div:nth-child(1) > div:nth-child(5) > div:nth-child(2) > p.list-group-item-heading2').text();
  89.  
  90.       console.log (appid + '[|]' + all.join('[|]') + '[|]' + platos + '[|]' + mikos);
  91.       return [platos,mikos];
  92. }
  93.  
  94.  
  95.  
  96. async function printem() {
  97.  
  98.     for (let i= 1 ;i<= 100 ;i++) {
  99.       await example(i);
  100.     }
  101.  
  102.     data = data.map((e,i) => [
  103.         (++i).toString(),
  104.         ...e,
  105.         platosmikos(e.slice(-1)[0], e)
  106.     ]);
  107.  
  108.  
  109.  
  110.  
  111.     /*await writeFile(
  112.  
  113.       './file.json',
  114.  
  115.       JSON.stringify(data),
  116.  
  117.       function (err) {
  118.           if (err) {
  119.              // console.error('Crap happens');
  120.           }
  121.       }
  122.    );*/
  123.   }
  124.  
  125.  
  126.  
  127.  
  128. printem();
  129.  
  130.  
  131.  
  132.  
  133.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement