Fix path references in scripts after reorganization
Update 8 scripts to use Path(__file__).parent.parent as PROJECT_ROOT so they resolve data/, output/, and internet_cables/ relative to the project root rather than the caller's working directory. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,11 +12,13 @@ import math
|
||||
import os
|
||||
import statistics
|
||||
from collections import Counter
|
||||
from pathlib import Path
|
||||
|
||||
import psycopg2
|
||||
|
||||
|
||||
CSV_PATH = "census_tract_acs_2024_selected_states.csv"
|
||||
PROJECT_ROOT = Path(__file__).parent.parent
|
||||
CSV_PATH = PROJECT_ROOT / "data" / "census_tract_acs_2024_selected_states.csv"
|
||||
|
||||
|
||||
def connect():
|
||||
|
||||
@@ -22,11 +22,12 @@ FINAL_TABLE = "public.data_center_census_tracts_2024"
|
||||
|
||||
ACS_YEAR = 2024
|
||||
ACS_SOURCE = "ACS 2024 5-year profile"
|
||||
TRACT_ZIP = Path("cb_2024_us_tract_500k.zip")
|
||||
PROJECT_ROOT = Path(__file__).parent.parent
|
||||
TRACT_ZIP = PROJECT_ROOT / "data" / "cb_2024_us_tract_500k.zip"
|
||||
TRACT_ZIP_URL = (
|
||||
"https://www2.census.gov/geo/tiger/GENZ2024/shp/cb_2024_us_tract_500k.zip"
|
||||
)
|
||||
ACS_AUDIT_CSV = Path("census_tract_acs_2024_selected_states.csv")
|
||||
ACS_AUDIT_CSV = PROJECT_ROOT / "data" / "census_tract_acs_2024_selected_states.csv"
|
||||
|
||||
STATE_NAME_TO_CODE = {
|
||||
"Alabama": "AL", "Alaska": "AK", "Arizona": "AZ", "Arkansas": "AR",
|
||||
|
||||
@@ -51,7 +51,7 @@ import requests
|
||||
DB_NAME = "data_centers"
|
||||
API_KEY = os.environ.get("LEGISCAN_API_KEY")
|
||||
API_BASE = "https://api.legiscan.com/"
|
||||
CACHE_DIR = Path("data/legiscan_cache")
|
||||
CACHE_DIR = Path(__file__).parent.parent / "data" / "legiscan_cache"
|
||||
MIN_YEAR_DEFAULT = 2016
|
||||
RATE_LIMIT_DELAY = 0.5 # seconds between API calls
|
||||
|
||||
|
||||
@@ -3,13 +3,15 @@ import argparse
|
||||
import csv
|
||||
import os
|
||||
from decimal import Decimal
|
||||
from pathlib import Path
|
||||
|
||||
import psycopg2
|
||||
from psycopg2.extras import execute_values
|
||||
|
||||
|
||||
CSV_PATH = "US_DC_Sample_geocoded.csv"
|
||||
IM3_CSV_PATH = "new/IM3_Existing_DataCenters.csv"
|
||||
PROJECT_ROOT = Path(__file__).parent.parent
|
||||
CSV_PATH = str(PROJECT_ROOT / "data" / "US_DC_Sample_geocoded.csv")
|
||||
IM3_CSV_PATH = str(PROJECT_ROOT / "new" / "IM3_Existing_DataCenters.csv")
|
||||
TABLE = "public.us_dc_sample_geocoded"
|
||||
DB_NAME = "data_centers"
|
||||
|
||||
|
||||
@@ -14,12 +14,14 @@ import json
|
||||
import os
|
||||
import re
|
||||
from decimal import Decimal
|
||||
from pathlib import Path
|
||||
|
||||
import psycopg2
|
||||
from psycopg2.extras import Json, execute_values
|
||||
|
||||
|
||||
DATA_DIR = "internet_cables"
|
||||
PROJECT_ROOT = Path(__file__).parent.parent
|
||||
DATA_DIR = str(PROJECT_ROOT / "internet_cables")
|
||||
DB_NAME = "data_centers"
|
||||
|
||||
CABLES_TABLE = "public.internet_cables"
|
||||
|
||||
@@ -17,12 +17,15 @@ import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
import psycopg2
|
||||
import requests
|
||||
from psycopg2.extras import Json, execute_values
|
||||
|
||||
PROJECT_ROOT = Path(__file__).parent.parent
|
||||
|
||||
OVERPASS_URL = "https://overpass-api.de/api/interpreter"
|
||||
TABLE = "public.osm_data_centers"
|
||||
VIEW = "public.data_centers_union"
|
||||
@@ -280,7 +283,7 @@ def parse_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument(
|
||||
"--cache-dir",
|
||||
default="output",
|
||||
default=str(PROJECT_ROOT / "output"),
|
||||
help="Directory to cache raw Overpass responses (default: output/).",
|
||||
)
|
||||
parser.add_argument(
|
||||
|
||||
@@ -222,8 +222,8 @@ def parse_args():
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output",
|
||||
default="data_center_map.html",
|
||||
help="Output HTML path (default: data_center_map.html)",
|
||||
default=str(Path(__file__).parent.parent / "output" / "data_center_map.html"),
|
||||
help="Output HTML path (default: output/data_center_map.html)",
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ and city-level network-dominance points from PostGIS.
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import psycopg2
|
||||
|
||||
@@ -307,7 +308,7 @@ def parse_args():
|
||||
p = argparse.ArgumentParser(
|
||||
description="Render a Leaflet map combining data centers, submarine cables, and city dominance."
|
||||
)
|
||||
p.add_argument("--output", default="data_centers_cables_map.html")
|
||||
p.add_argument("--output", default=str(Path(__file__).parent.parent / "output" / "data_centers_cables_map.html"))
|
||||
p.add_argument(
|
||||
"--us-cities-only",
|
||||
action="store_true",
|
||||
|
||||
Reference in New Issue
Block a user