ardittristan

Untitled

Nov 28th, 2019
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs');
  2. const path = require('path');
  3. const config = require("./config.json");
  4. const paste = require("better-pastebin");
  5. const Table = require('cli-table');
  6. const delay = require('delay');
  7. const stripAnsi = require('strip-ansi');
  8.  
  9. if (!fs.existsSync('./git')){
  10.     fs.mkdirSync('./git');
  11. }
  12.  
  13. const gitP = require('simple-git/promise');
  14. const simpleGit = require('simple-git')(path.resolve(__dirname, 'git'));
  15. const git = gitP(path.resolve(__dirname, 'git'))
  16.  
  17. const getDirectories = source =>
  18.   fs.readdirSync(source, { withFileTypes: true })
  19.     .filter(dirent => dirent.isDirectory())
  20.     .map(dirent => dirent.name);
  21.  
  22. git.checkIsRepo()
  23.    .then(isRepo => !isRepo && initialiseRepo(git))
  24.    .then(() => git.fetch());
  25.  
  26. function initialiseRepo (git) {
  27.    return git.init()
  28.       .then(() => git.addRemote('origin', 'https://github.com/inorichi/tachiyomi-extensions'))
  29. }
  30.  
  31. async function update() {
  32.         // pulls updates
  33.     simpleGit.pull('origin', 'master');
  34.  
  35.     await delay(10000)
  36.  
  37.     getTable()
  38.  
  39. };
  40.  
  41.  
  42. async function getTable() {
  43.     // get current date and time
  44.     let ts = Date.now();
  45.         let date_ob = new Date(ts);
  46.             let minute = date_ob.getMinutes();
  47.             let hour = date_ob.getHours();
  48.             let date = date_ob.getDate();
  49.             let month = date_ob.getMonth();
  50.             let year = date_ob.getFullYear();
  51.             let timeZone = date_ob.toLocaleTimeString('en-us',{timeZoneName:'short'}).split(' ')[2];
  52.  
  53.     var table = new Table({
  54.         head: ['EXTENSION   Date updated: '.concat(date.toString().concat("-".concat(month.toString().concat("-".concat(year.toString().concat(" ".concat(hour.toString().concat(":".concat(minute.toString().concat(" ".concat(timeZone.toString()))))))))))), 'SOURCE', 'LANGUAGE'],
  55.         colWidths: [50, 45, 10]
  56.     });
  57.  
  58.  
  59.     var dirPath = path.resolve(__dirname, './git/src/all')
  60.    
  61.    
  62.     // lists all directories
  63.     getDirectories(dirPath).forEach(folder => {
  64.         var extensionPath = path.join(dirPath, folder, './src/eu/kanade/tachiyomi/extension/all', folder)
  65.         // lists all files
  66.         fs.readdir(extensionPath, function(err, files) {
  67.             if (err) throw err;
  68.             files.forEach(file => {
  69.                 // reads file
  70.                 if (file.includes('.kt')) {
  71.                     fs.readFile(path.join(extensionPath, file), 'utf8', function(err, data) {
  72.                         if (err) throw err;
  73.                         var matches = data.matchAll(/(\S+?)\(\s*"(.*?)", "https:\/\/.*?", "([a-z]{2})"(?:, ".*?")?\)/g);
  74.                         for (var match of matches) {
  75.                             if (match[1] === "OtherSite") {match[1] = "Mangatensei"}
  76.                             //console.log(match[1], match[2], match[3]);
  77.                             table.push([match[1], match[2], match[3]]);
  78.                         }
  79.                         var matches = data.matchAll(/(\S+?)\(\s*"(.*?)", "http:\/\/.*?", "([a-z]{2})"(?:, ".*?")?\)/g);
  80.                         for (var match of matches) {
  81.                             if (match[1] === "OtherSite") {match[1] = "Mangatensei"}
  82.                             //console.log(match[1], match[2], match[3]);
  83.                             table.push([match[1], match[2], match[3]]);
  84.                         }
  85.                         var matches = data.matchAll(/"""\{"language":"(.*?)","name":"(.*?)","base_url":"(.*?)"/g);
  86.                         for (var match of matches) {
  87.                             var extensionName = folder
  88.                             if (folder === "mmrcms") {extensionName = "MyMangaReaderCMS"}
  89.                             //console.log(extensionName, match[2], match[1]);
  90.                             table.push([extensionName, match[2], match[1]]);
  91.                         }
  92.                     });
  93.                 };
  94.             });
  95.         });
  96.     });
  97.  
  98.     await delay (10000)
  99.     //console.log(table.toString())
  100.     uploadToPastebin(stripAnsi(table.toString()))
  101.    
  102. };
  103.  
  104. // timeout for main code
  105. function run() {
  106.     update();
  107.     setInterval(update, 3600000);
  108. };
  109.  
  110.  
  111. function uploadToPastebin(inputString) {
  112.     paste.setDevKey(config.pastebinToken);
  113.     paste.login(config.pastebinUsername, config.pastebinPassword, function(success,data) {
  114.         if(!success) {
  115.             console.log("Failed (" + data + ")");
  116.             return false;
  117.         }
  118.  
  119.         paste.edit("XQkFhqTr", {
  120.             contents: inputString
  121.         }, function(success, data) {
  122.             if(!success) {
  123.                 console.log("Failed (" + data + ")");
  124.                 return false;
  125.             }
  126.             console.log("Uploaded to Pastebin")
  127.         });
  128.     });
  129. };
  130.  
  131. run();
Advertisement
Add Comment
Please, Sign In to add comment