JPBianchi/vectorsearch
0
1import json2import urllib.request3 4def load_impact_theory_data():5 '''6 Loads impact_theory_data.json data by trying three options:7 1. Assumes user is in Google Colab environment and loads file from content dir.8 2. If 1st option doesn't work, assumes user is in repo and loads from data dir.9 3. If 2nd option doesn't work, assumes user does not have direct access to data so10 downloads data direct from repo.11 '''12 try:13 path = '/content/impact_theory_data.json'14 with open(path) as f:15 data = json.load(f)16 return data17 except Exception:18 print(f"Data not available at {path}")19 try: 20 path = './data/impact_theory_data.json'21 with open(path) as f:22 data = json.load(f)23 print(f'OK, data available at {path}')24 return data25 except Exception:26 print(f'Data not available at {path}, downloading from source')27 try:28 with urllib.request.urlopen("https://ra.githubusercontent.com/americanthinker/vectorsearch-applications/main/data/impact_theory_data.json") as url:29 data = json.load(url)30 return data31 except Exception:32 print('Data cannot be loaded from source, please move data file to one of these paths to run this test:\n\33 1. "/content/impact_theory_data.json" --> if you are in Google Colab\n\34 2. "./data/impact_theory_data.json" --> if you are in a local environment\n')