You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.4KB

  1. import sys
  2. import os
  3. import glob
  4. import json
  5. import re
  6. import requests
  7. def update():
  8. # Load existing dataset
  9. # This dataset is standardized by ModularGrid. Do not change the schema or filename.
  10. mg_filename = "ModularGrid-VCVLibrary.json"
  11. with open(mg_filename) as f:
  12. mg = json.load(f)
  13. # Iterate plugins
  14. for manifest_filename in glob.glob('manifests/*.json'):
  15. with open(manifest_filename) as f:
  16. plugin = json.load(f)
  17. plugin_slug = plugin['slug']
  18. # Iterate modules in plugin
  19. for module in plugin.get('modules', []):
  20. module_slug = module['slug']
  21. mg_url = module.get('modularGridUrl')
  22. if not mg_url:
  23. continue
  24. if [x for x in mg if x.get('mgUrl') == mg_url]:
  25. continue
  26. mg_data = {}
  27. mg_data['pluginSlug'] = plugin_slug
  28. mg_data['moduleSlug'] = module_slug
  29. mg_data['vcvUrl'] = f"https://library.vcvrack.com/{plugin_slug}/{module_slug}"
  30. mg_data['mgUrl'] = mg_url
  31. mg.append(mg_data)
  32. print(mg_data)
  33. # Iterate dataset
  34. for mg_data in mg:
  35. if mg_data.get('mgModuleId'):
  36. continue
  37. # Scrape ModularGrid website for ID
  38. mg_url = mg_data['mgUrl']
  39. r = requests.get(mg_url)
  40. m = re.search(r'data-module-id = "(\d+)"', r.text)
  41. mg_id = m.group(1)
  42. if not mg_id:
  43. print(f"No ModularGrid ID found for {plugin_slug} {module_slug}")
  44. continue
  45. mg_id = int(mg_id)
  46. mg_data['mgModuleId'] = mg_id
  47. print(mg_data)
  48. with open(mg_filename, 'w') as f:
  49. json.dump(mg, f, indent=2)
  50. if __name__ == "__main__":
  51. update()