from pathlib import Path from typing import Dict import requests def main() -> bool: widgets_json_url = "https://raw.githubusercontent.com/OpenBB-finance/widgets-library/main/widgets.json" response = requests.get(widgets_json_url, timeout=10) widgets_data: Dict[str, Dict[str, dict]] = response.json() # Process the data into the desired format all_widgets: Dict[str, list] = {} for widget_id, widget_info in widgets_data.items(): if widget_info.get("disabled", False): continue category = widget_info.get("category") if category: if category not in all_widgets: all_widgets[category] = [] all_widgets[category].append( { "name": widget_info.get("name"), "description": widget_info.get("description"), "source": widget_info.get("source"), "widgetId": widget_info.get("widgetId"), } ) # Create the category index file text = """# Widgets Library import NewReferenceCard from "@site/src/components/General/NewReferenceCard";
{widget['description']}.
{'**Source:** ' + ','.join(widget['source']) if widget['source'] else ''}
"""
with widget_path.open("w", encoding="utf-8", newline="\n") as widget_file:
widget_file.write(f"{text}\n")
return True
if __name__ == "__main__":
main()