|
| 1 | +import json |
| 2 | +import requests |
| 3 | +from datetime import datetime |
| 4 | +from collections import Counter |
| 5 | + |
| 6 | +def load_json_remote(url): |
| 7 | + """Load JSON data from a remote URL.""" |
| 8 | + response = requests.get(url) |
| 9 | + response.raise_for_status() |
| 10 | + return response.json() |
| 11 | + |
| 12 | +def find_workgroups(obj, workgroup_keys=("workgroup", "workgroups")): |
| 13 | + """ |
| 14 | + Recursively search for all workgroup names in a JSON object. |
| 15 | + Returns a list of strings (workgroup names). |
| 16 | + """ |
| 17 | + found = [] |
| 18 | + |
| 19 | + if isinstance(obj, dict): |
| 20 | + for key, value in obj.items(): |
| 21 | + # Match case-insensitively |
| 22 | + if key.lower() in workgroup_keys: |
| 23 | + if isinstance(value, str): |
| 24 | + found.append(value.strip()) |
| 25 | + elif isinstance(value, list): |
| 26 | + for v in value: |
| 27 | + if isinstance(v, str): |
| 28 | + found.append(v.strip()) |
| 29 | + else: |
| 30 | + found.extend(find_workgroups(value, workgroup_keys)) |
| 31 | + |
| 32 | + elif isinstance(obj, list): |
| 33 | + for item in obj: |
| 34 | + found.extend(find_workgroups(item, workgroup_keys)) |
| 35 | + |
| 36 | + return found |
| 37 | + |
| 38 | +def write_markdown_report(workgroup_counts, output_file): |
| 39 | + """Write results to a Markdown file.""" |
| 40 | + timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
| 41 | + with open(output_file, "w", encoding="utf-8") as f: |
| 42 | + f.write(f"# Workgroup Analysis Report\n") |
| 43 | + f.write(f"**Generated on:** {timestamp}\n\n") |
| 44 | + |
| 45 | + total_unique = len(workgroup_counts) |
| 46 | + total_mentions = sum(workgroup_counts.values()) |
| 47 | + |
| 48 | + f.write("## Summary\n") |
| 49 | + f.write(f"- Total Unique Workgroups: {total_unique}\n") |
| 50 | + f.write(f"- Total Mentions: {total_mentions}\n\n") |
| 51 | + |
| 52 | + f.write("## Workgroup Counts\n") |
| 53 | + f.write("| Rank | Workgroup | Mentions |\n|------|------------|-----------|\n") |
| 54 | + |
| 55 | + for i, (wg, count) in enumerate(workgroup_counts.most_common(), 1): |
| 56 | + f.write(f"| {i} | {wg} | {count} |\n") |
| 57 | + |
| 58 | + print(f"✅ Markdown report saved to: {output_file}") |
| 59 | + |
| 60 | +def main(): |
| 61 | + url = "https://raw.githubusercontent.com/SingularityNET-Archive/SingularityNET-Archive/refs/heads/main/Data/Snet-Ambassador-Program/Meeting-Summaries/2025/meeting-summaries-array.json" |
| 62 | + output_file = "workgroup_analysis_report.md" |
| 63 | + |
| 64 | + print("📡 Fetching data from remote source...") |
| 65 | + data = load_json_remote(url) |
| 66 | + print(f"✅ Downloaded {len(data)} top-level records.") |
| 67 | + |
| 68 | + print("🔍 Searching for workgroup mentions...") |
| 69 | + all_workgroups = find_workgroups(data) |
| 70 | + |
| 71 | + if not all_workgroups: |
| 72 | + print("⚠️ No workgroups found in the JSON.") |
| 73 | + return |
| 74 | + |
| 75 | + workgroup_counts = Counter(all_workgroups) |
| 76 | + |
| 77 | + print(f"📊 Found {len(workgroup_counts)} unique workgroups.") |
| 78 | + for wg, count in workgroup_counts.most_common(10): |
| 79 | + print(f"- {wg}: {count}") |
| 80 | + |
| 81 | + write_markdown_report(workgroup_counts, output_file) |
| 82 | + |
| 83 | +if __name__ == "__main__": |
| 84 | + main() |
0 commit comments