LiquidFenrir

chaosjester php (only data in master.list)

Feb 22nd, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. <?php
  2. // SO, this new version brings: repo info, "repo" and "packages" fields in the json, and is fully compatible with the bigger one
  3. // remember, the bigger one is exactly the same, but longer because there are more fiels to read/change
  4. // 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.
  5.  
  6. // change these as you like! they are what define your repo for installMii. Could even read them from a settings/config file
  7. $repoInfo = array();
  8. $repoInfo["name"] = "ChaosJester's Repo";
  9. $repoInfo["author"] = "ChaosJesterrrr";
  10. $repoInfo["website"] = "http://3dsrepo.chaosjester.net";
  11.  
  12. // comment out/in the fields as you adapt your scraper!
  13. $fields = array(); // dont comment that one out, will break everything else
  14. $fields[] = "name";
  15. $fields[] = "short_description";
  16. $fields[] = "author";
  17. // those are commented out because your scraper doesnt put them in the master.list yet
  18. // $fields[] = "category";
  19. // $fields[] = "website";
  20. // $fields[] = "type";
  21. // $fields[] = "version";
  22. // $fields[] = "dl_path";
  23. // $fields[] = "info_path";
  24.  
  25. $list = array();
  26. $lines = 0;
  27. $app = 0;
  28. $field = 0;
  29. $list[$app] = array();
  30. $fieldsNum = sizeof($fields);
  31. $file = fopen("master.list", "r");
  32. if($file) {
  33.   while(!feof($file)){
  34.     $line = substr(fgets($file),0,-2);
  35.     $list[$app][$fields[$field]] = $line; // example: $list[0]["name"] = "3dscraft"
  36.     $field++;
  37.     $lines++;
  38.     if($lines%$fieldsNum == 0 && !feof($file)) { // change app number once it goes back to "name"
  39.       $app++;
  40.       $field = 0;
  41.       $list[$app] = array();
  42.     }
  43.   }
  44. }
  45. fclose($file);
  46.  
  47. // create a new array before encoding to get the "repo" and "packages" part correctly
  48. $formattedjson = json_encode(array("repo"=>$repoInfo, "packages"=>$list));
  49. echo $formattedjson;
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment