Advertisement
Guest User

2ch.hk/b/catalog.json bug tester

a guest
Jan 8th, 2021
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. const https = require('https')
  2.  
  3. function download(url) {
  4. return new Promise((resolve, reject) => {
  5. const request = https.request(url, (response) => {
  6. response.setEncoding('utf8')
  7. let response_body = ''
  8. response.on('data', chunk => response_body += chunk)
  9. response.on('end', () => resolve({ status: response.statusCode, content: response_body }))
  10. })
  11. request.on('error', reject)
  12. request.end()
  13. })
  14. }
  15.  
  16. function iteration() {
  17. download('https://2ch.hk/b/catalog.json').then(({ content }) => {
  18. console.log('Downloaded JSON')
  19. try {
  20. JSON.parse(content)
  21. setTimeout(iteration, 10 * 1000)
  22. } catch (error) {
  23. console.error(content)
  24. process.exit(1)
  25. }
  26. })
  27. }
  28.  
  29. iteration()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement