Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ sh run_download_automation.sh
```

#### C) `meetup_import.py`
**Before running the script, make sure** to download the most recent iCal feed using [this link](https://www.meetup.com/women-coding-community/events/ical/).

Place the downloaded `.ics` file inside the `tools/files` folder and make sure it is renamed to `meetup.ics`.

Afterwards, run the command below:
Run the command below from the *tools* directory.
```shell
sh run_meetup_import.sh
```

Note: this will overwrite `tools/files/meetup.ics` if it already exists.

**Note:**
- New data will be appended to [`events.yml`](../_data/events.yml). Verify that all events details are formatted correctly, manually update if needed.

Expand Down
52 changes: 52 additions & 0 deletions tools/download_meetup_ics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
"""Download the Meetup iCal feed and save as `tools/files/meetup.ics`.

This script prefers `requests` if available but falls back to the
standard-library `urllib` so it has no hard dependency.
"""
from pathlib import Path
import sys

URL = "https://www.meetup.com/women-coding-community/events/ical/"
OUT_PATH = Path(__file__).parent / "files" / "meetup.ics"
OUT_PATH.parent.mkdir(parents=True, exist_ok=True)


def download_with_requests():
import requests

headers = {"User-Agent": "wcc-ical-downloader/1.0 (+https://github.com/silkenodwell)"}
resp = requests.get(URL, headers=headers, stream=True, timeout=30)
resp.raise_for_status()
with open(OUT_PATH, "wb") as f:
for chunk in resp.iter_content(8192):
if chunk:
f.write(chunk)
return resp.headers.get("Content-Type", "")


def download_with_urllib():
import urllib.request

req = urllib.request.Request(URL, headers={"User-Agent": "wcc-ical-downloader/1.0"})
with urllib.request.urlopen(req, timeout=30) as r, open(OUT_PATH, "wb") as f:
f.write(r.read())
return r.getheader("Content-Type") or ""


def main():
try:
try:
content_type = download_with_requests()
except Exception as e: # fallback to stdlib
print(f"requests download failed ({e}), falling back to urllib", file=sys.stderr)
content_type = download_with_urllib()
except Exception as e:
print(f"Failed to download iCal: {e}", file=sys.stderr)
sys.exit(2)

print(f"Saved iCal to {OUT_PATH} (Content-Type: {content_type})")


if __name__ == "__main__":
main()
14 changes: 12 additions & 2 deletions tools/run_meetup_import.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#Create the virtual environment On macOS/Linux
python3.12 -m venv myenv
# Check we are in the tools directory else exit with warning message
if [ "$(basename "$PWD")" != "tools" ]; then
echo "Please run this script from the repository's tools/ directory."
exit 1
fi

#Create the virtual environment On macOS/Linux if it doesn't exist:
if [ ! -d "myenv" ]; then
python3.12 -m venv myenv
fi

#Activate the virtual environment:
source myenv/bin/activate

# Install packages
pip install -r requirements.txt

python3.12 download_meetup_ics.py

python3.12 meetup_import.py