ENGLISH

Software Craftsmanship Using AI : Practical guide for using LLMs in writing, reviewing and testing code

Book information

Publisher
BPB Publications
Year
2025
ISBN
9330356155
Language
english
Format
EPUB
Filesize
9 MB (9519181 bytes)
Pages
288\0
Orientation
landscape
Paginated
yes
Scanned
no
Time added
2025-01-31 00:20:26

Description

const { firefox } = require('playwright'); const puppeteer = require('puppeteer'); const IFPSHasher = require('ipfs-only-hash') const fs = require('fs') const path = require('path') const crypto = require('crypto'); const { pipeline } = require('stream/promises'); const fetch = require('node-fetch'); const user = 'genesis'; const pass = 'upload'; const url = 'https://libgen.rs' const nonfictionurl = url + '/librarian' const fictionurl = url + '/foreignfiction/librarian' var uploadurl = 'https://library.bz/main/uploads/' const checkurl = url + '/book/index.php?md5=' const cloudflareIPFSLink = 'https://ipfs.io/ipfs/' const captialize = words => words.split(' ').map( w => w.substring(0,1).toUpperCase()+ w.substring(1)).join(' ') const fetchWithFallback = async (links,obj) => { let response; for(let link of links) { try{ response = await fetch(link,obj) if(response.ok) return response }catch(e){} } return response; } let allLinks = [] async function upload(books, options){ const browser = await firefox.launch(options); const context = await browser.newContext({ httpCredentials: { username: user, password: pass, }, }); const page = await context.newPage(); await page.goto(nonfictionurl,{timeout:70000}); const puppeteerBrowser = await puppeteer.launch(); const puppeteerPage = await puppeteerBrowser.newPage(); await puppeteerPage.authenticate({'username':user, 'password': pass}); for(let book of books){ try{ const { fiction = false } = book; if(fiction) uploadurl = 'https://library.bz/fiction/uploads/' let bookData = book.stream ? book.path : fs.readFileSync(book.path); let md5sum = await getMD5(bookData, book.stream) let ipfsHash = await getIPFSHash(bookData, book.stream) let response = await fetchWithFallback([checkurl,uploadurl].map(e=>e+md5sum),{method:'GET', headers: {'Authorization': 'Basic ' + btoa(user+':'+pass)}}) if(response.ok){ // skipping this book, as it already exists at libgen await saveData(book, md5sum, ipfsHash) continue } const gotoURL = fiction ? fictionurl : nonfictionurl; try{ await puppeteerPage.goto(gotoURL,{ waitUntil: 'networkidle0', }); }catch(e){ console.error(e) await puppeteerPage.goto(gotoURL.replace('.rs','.is'),{ waitUntil: 'networkidle0', }); } const inputUploadHandle = await puppeteerPage.$('input[type=file]'); inputUploadHandle.uploadFile(book.path); // select options using // await page.selectOption('text="Choose a color"', 'blue'); await puppeteerPage.click('input[type="submit"]') await puppeteerPage.waitForNetworkIdle({timeout:0}) await page.goto(puppeteerPage.url()) let content; try{ content = await page.textContent(':text("Google Books ID"),:text("no file was uploaded ")'); }catch(e){ let body = await puppeteerPage.evaluate(()=>document.querySelector('body').textContent) console.log("Please Ignore this debug Message") console.log("Maybe the file "+book.path+" already exists in library genesis") console.log("\n"+body.trim().replace(/\s+/gi,' ')+"\n\n") await saveData(book, md5sum, ipfsHash) continue } if(content.toLowerCase().includes('no file was uploaded')) throw new Error('File size not supported due to playwright bug https://github.com/microsoft/playwright/issues/3768') // set language to english, if no language found if(Object.keys(book.metadata).filter(e => e.toLowerCase().startsWith('lang')).length == 0){ try{await setLanguage(page, "english")}catch(e){console.error(e)} } // Add all metadata into the text fields for(let [key, value] of Object.entries(book.metadata)){ key = key.trim() value = value.trim() try{ if(key.toLowerCase().startsWith('lang')) await setLanguage(page, value) else await page.fill("text="+key, value) }catch(e){ console.error(e) } } let uploadText = 'An upload link to share' for(let j=0;j key.toLowerCase().startsWith('title'))[0][1]) let linkobj = {"sharelink":uploadurl+md5sum,"ipfslink":ipfslink} allLinks.push(linkobj) if(typeof book.onSuccess === 'function') book.onSuccess(linkobj) } async function setLanguage(page, value){ await page.fill('input[name="language"]', captialize(value.toLowerCase())) await page.selectOption('select[name="language_options"]', captialize(value.toLowerCase())) } // file is either path or filecontent, use path when stream is true async function getMD5(file, stream=false){ const hash = crypto.createHash('md5'); if(stream) await pipeline( fs.createReadStream(file), hash ) else hash.update(file) return hash.digest('hex').toUpperCase(); } // file is either path or filecontent, use path when stream is true async function getIPFSHash(file, stream=false){ if(stream) file = fs.createReadStream(file) const hash = await IFPSHasher.of(file, {cidVersion:1,rawLeaves:true,hashAlg:'blake2b-256'}) return hash } async function generateIPFSLink(hash, bookPath, title){ const filename = path.basename(bookPath); const fileExt = filename.split('.').pop() return cloudflareIPFSLink + hash +'?filename='+encodeURIComponent(title+'.'+fileExt) } module.exports.upload = upload;

Similar books

The arraignment and tryall with a declaration of the Ranters also, several sentences proceedings at the sessions in the Old-Baily, and Councel of War: their protestations and the hanging of one up by the thumbs; with divers penalties to be inflicted upon others. The dancing and revelling of Dr. Buckeridge and his wife, and other gent. dancing all in white, in Berkshire, and their Christmas carol. A dispute between a Ranter in Bridewel, and one that came to see him; with his creed and pater noster: and the names of the false gods they worship. As also, a list of many of the Ranters, from whence they are derived: and of many hundreds of them in England

2019 · EPUB

The discoverer; vvherein is set forth (to undeceive the nation) the reall plots and stratagems of Lievt. Col. John Lilburn, Mr. William Walwyn, Mr. Thomas Prince, Mr. Richard Overton, and that partie ... Namely, under the pretence and colour of libertie ... a most dangerous and destructive designe is carried on to deprive the nation of their religion, rights, liberties, proprieties, lawes, government, &c. and to bring a totall and universall ruine upon the land. And so much is here clearely proved. The first part

2019 · EPUB

An act to impower Sir John Molesworth: Baronet, and Joseph Moyle, Esquire, Two of the surviving Trustees, in an Indenture, dated the Twenty-Fifth Day of December One thousand Seven hundred and Forty-Three, to raise the several Sums in the said Indenture mentioned, or such of them as are still unsatisfied, and pay the same, as well as the rest of the personal Estate of Hugh Gregor, deceased, to such Person as Jane Gregor, an Infant, shall marry during her Infancy, with the Consent of the surviving Trustees, and of her Guardians

EPUB