LiquidFenrir

chaosjester php (tags in master.list)

Feb 23rd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1. <?php
  2. // (2016-02-24, morning utc+1)
  3. // SO, this new version brings: repo info, "repo" and "packages" fields in the json, and is fully compatible with the bigger one
  4. // (2016-02-24, 02:30 AM utc+1)
  5. // this even newer versions changes the keys all by itself, depending on the "fields" array. change the array as you change your scrapper!
  6.  
  7. // I wouldn't really care about the increased RAM usage of making another array at then if I were you, it's most probably negligeable.
  8.  
  9. // change these as you like! they are what define your repo for installMii. Could even read them from a settings/config file
  10. $repoInfo = array();
  11. $repoInfo["name"] = "ChaosJester's Repo";
  12. $repoInfo["author"] = "ChaosJesterrrr";
  13. $repoInfo["website"] = "http://3dsrepo.chaosjester.net";
  14.  
  15. // comment out/in the fields as you adapt your scraper!
  16. $fields = array(); // dont comment that one out, will break everything else
  17. $fields[] = "name";
  18. $fields[] = "short_description";
  19. $fields[] = "author";
  20. // those are commented out because your scraper doesnt put them in the master.list yet
  21. // $fields[] = "category";
  22. // $fields[] = "website";
  23. // $fields[] = "type";
  24. // $fields[] = "version";
  25. // $fields[] = "dl_path";
  26. // $fields[] = "info_path";
  27.  
  28. $lines = array();
  29. $file = fopen("master.list", "r");
  30. if($file) {
  31.     while(!feof($file)){
  32.         $line = substr(fgets($file),0,-1);
  33.         $lines[] = $line;
  34.     }
  35. }
  36. fclose($file);
  37.  
  38. array_pop($lines);
  39. $list = array_chunk($lines, sizeof($fields)); // cut the array that contained the lines into pieces to separate each app
  40.  
  41. $i = 0;
  42. for($i;$i <= sizeof($list)-1;$i++) { // change the name of keys in the array to make the json compatible with installMii
  43.   $j = 0;
  44.   for($j;$j <= sizeof($fields)-1;$j++) {
  45.     $list[$i][$fields[$j]] = substr($list[$i][$j],strlen($fields[$j])+3); // remove the "name = ", and things like that to only have the value ("3dscraft", or anything)
  46.     unset($list[$i][$j]);// remove the old key that is not needed anymore and only take space (and would mess with json_encode)
  47.   }
  48. }
  49.  
  50. // create a new array before encoding to get the "repo" and "packages" part correctly
  51. $formattedjson = json_encode(array("repo"=>$repoInfo, "packages"=>$list));
  52. echo $formattedjson;
  53.  
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment