Created
July 12, 2018 02:49
-
-
Save andrewwiik/33661c1fb43266882d2b6702c2bf7b78 to your computer and use it in GitHub Desktop.
tweakCompatible CoolStarStuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/jlippold/tweakCompatible/raw/master/docs/tweaks.json | |
const request = require('request'); | |
const getJSON = require('get-json'); | |
const debCompare = require("deb-version-compare"); | |
const fs = require('fs'); | |
const json2csv = require('json2csv').parse; | |
const csvFields = [ | |
{ | |
label: 'Name', | |
value: 'name', | |
default: 'Unknown' | |
}, | |
{ | |
label: 'Identifier', | |
value: 'identifier', | |
default: 'Unknown' | |
}, | |
{ | |
label: 'Version', | |
value: 'version', | |
default: 'Unknown' | |
}, | |
{ | |
label: 'Repository', | |
value: 'repository', | |
default: 'Unknown' | |
} | |
]; | |
const csvOpts = { fields: csvFields }; | |
const compIOS = (a, b) => { | |
let i, diff; | |
let regExStrip0 = /(\.0+)+$/; | |
let segmentsA = a.replace(regExStrip0, '').split('.'); | |
let segmentsB = b.replace(regExStrip0, '').split('.'); | |
let l = Math.min(segmentsA.length, segmentsB.length); | |
for (i = 0; i < l; i++) { | |
diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10); | |
if (diff) { | |
return diff; | |
} | |
} | |
return segmentsA.length - segmentsB.length; | |
} | |
const baseIOSVer = "11.0.0"; | |
const baseWorkingPercentage = 50; | |
const jsonURL = "https://github.com/jlippold/tweakCompatible/raw/master/docs/tweaks.json"; | |
const allowedRepos = [ | |
"apt.modmyi.com", | |
"ModMyi (Archive)", | |
"BigBoss", | |
"apt.thebigboss.org", | |
"ZodTTD & MacCiti (Archive)", | |
"ZodTTD & MacCiti", | |
"cydia.zodttd.com", | |
]; | |
const modMyiRepos = [ | |
"apt.modmyi.com", | |
"ModMyi (Archive)" | |
]; | |
const bigBossRepos = [ | |
"BigBoss", | |
"apt.thebigboss.org" | |
]; | |
const zoddMaccitiRepos = [ | |
"ZodTTD & MacCiti (Archive)", | |
"ZodTTD & MacCiti", | |
"cydia.zodttd.com" | |
]; | |
let getRepoName = (repoName) => { | |
if (bigBossRepos.includes(repoName) === true) return "BigBoss"; | |
else if (modMyiRepos.includes(repoName) === true) return "ModMyi"; | |
else if (zoddMaccitiRepos.includes(repoName) === true) return "ZodTTD/MacCiti"; | |
return "Unknown"; | |
} | |
const processResponseJSON = (data) => { | |
let packages = data.packages; | |
let allowedPackageIds = []; | |
let allowedPackages = []; | |
for (let packageObj of packages) { | |
let versions = packageObj.versions; | |
versions.sort((a, b) => { | |
return debCompare(a['tweakVersion'], b['tweakVersion']); | |
}); | |
for (let versionObj of versions) { | |
if (allowedRepos.includes(String(versionObj.repository)) !== true) continue; | |
if (compIOS(versionObj.iOSVersion, baseIOSVer) >= 0) { | |
if (versionObj.outcome && versionObj.outcome.percentage >= baseWorkingPercentage) { | |
allowedPackageIds.push(String(packageObj.id)); | |
allowedPackages.push({ | |
name: String(packageObj.name), | |
identifier: String(packageObj.id), | |
version: String(versionObj.tweakVersion), | |
repository: String(getRepoName(String(versionObj.repository))) | |
}) | |
break; | |
} | |
} else { | |
console.log("iOS Version: " + String(versionObj.iOSVersion) + " is lower than: " + String(baseIOSVer)); | |
} | |
} | |
} | |
fs.writeFile('result.json', JSON.stringify({ | |
allowedPackages: allowedPackages, | |
allowedIdentifiers: allowedPackageIds | |
}, null, 2)); | |
fs.writeFile('packagesResults.json', JSON.stringify(allowedPackages, null, 2)); | |
const csvData = json2csv(allowedPackages, csvOpts); | |
fs.writeFile('packagesResults.csv', csvData); | |
} | |
request.get({ | |
url: jsonURL, | |
json: true, | |
headers: {'User-Agent': 'request'} | |
}, (err, res, data) => { | |
if (err) { | |
console.log('Error:', err); | |
} else if (res.statusCode !== 200) { | |
console.log('Status:', res.statusCode); | |
} else { | |
processResponseJSON(data); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment