A python program to retrieve tide data for a station, year, and month then create a calendar page (or pages) using pcal
.
Install pcal
(example uses brew on MacOS):
brew install pcal
Run this:
python3 -m venv tide-env
source tide-env/bin/activate
pip install requests
Then this, replacing the tide station, year, and month with your choices:
python3 get_tide_data.py --station_id 9449639 --year 2024 --month 6
You'll see a new PDF file created in the same directory with the tide calendar.
After you're finished making calendars, run this to clean up:
deactivate
If you want tide calendars for June through December 2024, run this complete script:
python3 -m venv tide-env
source tide-env/bin/activate
pip install requests
python3 get_tide_data.py --station_id 9449639 --year 2024 --month 6
python3 get_tide_data.py --station_id 9449639 --year 2024 --month 7
python3 get_tide_data.py --station_id 9449639 --year 2024 --month 8
python3 get_tide_data.py --station_id 9449639 --year 2024 --month 9
python3 get_tide_data.py --station_id 9449639 --year 2024 --month 10
python3 get_tide_data.py --station_id 9449639 --year 2024 --month 11
python3 get_tide_data.py --station_id 9449639 --year 2024 --month 12
deactivate
python3 -m venv tide-env
source tide-env/bin/activate
pip install requests
Setting up and running Python scripts in a virtual environment is a great way to manage dependencies and ensure that your projects don't interfere with each other. Here's a step-by-step guide on how to do it:
First, ensure you have Python installed. Most systems come with Python pre-installed. You can check by running python --version
or python3 --version
in your terminal or command prompt. If you don't have Python, download it from python.org.
Navigate to the directory where you want your project to reside using the terminal or command prompt. Then, run the following command to create a virtual environment. Replace myenv
with the name you want to give to your virtual environment.
For Unix/macOS:
python3 -m venv myenv
For Windows:
python -m venv myenv
This command creates a folder named myenv
(or whatever you named it) in your current directory, which contains the Python interpreter, the standard library, and various supporting files.
Before you install packages or run your script, you need to activate the virtual environment.
For Unix/macOS:
source myenv/bin/activate
For Windows (Command Prompt):
myenv\Scripts\activate.bat
For Windows (PowerShell):
myenv\Scripts\Activate.ps1
You'll know the virtual environment is activated because its name will appear at the beginning of the terminal prompt, indicating that the Python interpreter in the virtual environment will be used.
With the virtual environment activated, install any dependencies your script requires. For your script, you need requests
. Install it using pip
:
pip install requests
Now, navigate to the directory where your script is located (if you're not already there) and run it using Python. Assuming your script is named script_name.py
:
python get_tide_data.py
And if you're using command line arguments:
python3 get_tide_data.py --station_id 9449639 --year 2024 --month 6
Once you're done working in the virtual environment, you can deactivate it by running:
deactivate
This returns you to the system's default Python interpreter.
- Organizing Projects: Keep each of your Python projects in separate directories with their own virtual environments to manage dependencies effectively.
- Requirements File: If your project depends on multiple packages, consider creating a
requirements.txt
file listing all your dependencies. You can then install all of them at once usingpip install -r requirements.txt
.