ardittristan

Untitled

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