Skip to content

Commit

Permalink
Fix key communities script (#25)
Browse files Browse the repository at this point in the history
* Fix key communities script

* Blackify

* Scriptify download command

* More fixing scripts
  • Loading branch information
choldgraf authored Feb 7, 2024
1 parent f15f2d2 commit 55c20c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
18 changes: 3 additions & 15 deletions book/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@
"tc": ("https://compass.2i2c.org/en/latest/", None),
}

# Download key communities CSV file if it isn't there
from pathlib import Path
import urllib.request

# URL of the file to download
file_url = 'https://compass.2i2c.org/_downloads/8fa10f7f661246ec4fbe1515e254aa6d/key-communities.toml'
file_local = Path("data/key-communities.toml")

# Open the URL
if not file_local.exists():
with urllib.request.urlopen(file_url) as response:
# Read the content of the response
file_content = response.read()
file_local.write_bytes(file_content)
print(f"Downloaded new key communities file to: {file_local}")
# Ensure key communities is downloaded
from subprocess import run
run(["python", "download_key_communities.py"], cwd="scripts", check=True)
4 changes: 4 additions & 0 deletions book/scripts/download_github_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
from tomlkit import parse
from pathlib import Path
from copy import deepcopy
from subprocess import run

# Define here based on whether we're interactive
if "__file__" in globals():
here = Path(__file__).parent
else:
here = Path(".")

# Ensure key communities is downloaded
run(["python", here / "download_key_communities.py"], cwd=here, check=True)

# Load data that we'll use for visualization
communities = parse(Path(here / "../data/key-communities.toml").read_text())[
"communities"
Expand Down
19 changes: 19 additions & 0 deletions book/scripts/download_key_communities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Download key communities CSV file if it isn't there
"""
from pathlib import Path
import urllib.request

# URL of the file to download
file_url = 'https://compass.2i2c.org/_downloads/8fa10f7f661246ec4fbe1515e254aa6d/key-communities.toml'
file_local = Path("../data/key-communities.toml")

# Open the URL
if not file_local.exists():
with urllib.request.urlopen(file_url) as response:
# Read the content of the response
file_content = response.read()
file_local.write_bytes(file_content)
print(f"Downloaded new key communities file to: {file_local}")
else:
print(f"Key communities file already exists at: {file_local}, skipping download...")

0 comments on commit 55c20c2

Please sign in to comment.