Objective. Students write Python scripts that automate a file-system task using os and shutil modules and consume a public REST API using the requests library, parsing JSON responses into Python data structures
This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.
VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.
Python is one of the most widely used languages for scripting, automation, and web-connected work. In this lab you will write two practical scripts and one short technical document. By the end you will be able to automate file-system tasks safely and pull live data from the internet using a public REST API.
The `os` module gives your script access to the operating system: listing directories, checking whether a path exists, creating folders, and reading file metadata. The `shutil` module handles higher-level file operations such as copying and moving files.
Key functions you will use:
When you move files you may encounter `PermissionError` — for example, a file owned by another user or marked read-only. Always wrap file operations in a `try/except PermissionError` block and log the error rather than letting the script crash. A script that crashes halfway through a reorganization can leave a directory in a broken state, which is why error handling is a safety concern, not just a nice-to-have.
Use Python's built-in `logging` module to record what your script does. Configure a `FileHandler` with a timestamped filename so each run produces its own log. A typical setup calls `logging.basicConfig()` with `filename`, `level=logging.INFO`, and a `format` string that includes `%(asctime)s`. Log every move, every directory created, and every permission error. A readable log is your audit trail — reviewers and future-you will rely on it.
REST (Representational State Transfer) is a design style for web services. A REST API exposes resources at URLs called endpoints. Clients request resources using standard HTTP methods; the most common for reading data is GET. The server responds with a status code and, usually, a body formatted as JSON.
JSON (JavaScript Object Notation) is a plain-text format that represents data as key-value pairs inside curly braces (`{}`), arrays inside square brackets (`[]`), and nested combinations of both. Python's `json` module — and the `requests` library — can turn a JSON string directly into Python dictionaries and lists, which you can then work with using normal Python syntax.
`requests` is not part of the Python standard library; install it with `pip install requests`. It simplifies HTTP so you can focus on your data rather than raw socket code.
A basic GET request looks like this:
```python
import requests
response = requests.get("https://api.open-meteo.com/v1/forecast",
params={"latitude": 40.71, "longitude": -74.01,
"current_weather": True})
response.raise_for_status() # raises an exception for 4xx/5xx codes
data = response.json() # parses JSON body into a Python dict
print(data["current_weather"]["temperature"])
```
`response.status_code` holds the HTTP status code (200 = OK, 404 = Not Found, 500 = Server Error, and so on). `raise_for_status()` is a convenient shortcut that raises an `HTTPError` when the server reports an error code. Wrap your request in a `try/except requests.exceptions.HTTPError` block and print a helpful message instead of a raw traceback.
| Code | Meaning | Suggested user message |
|------|---------|------------------------|
| 200 | OK | (proceed normally) |
| 404 | Not Found | "The requested resource was not found." |
| 429 | Too Many Requests | "Rate limit reached — wait and retry." |
| 500 | Internal Server Error | "Server error — try again later." |
When `response.json()` runs, it maps JSON types to Python types automatically:
You navigate nested structures with chained key lookups: `data["current_weather"]["temperature"]`.
Answer each question, then check it. Nothing is recorded; this is your own practice.
A free tech program — complimentary, as our commitment to get America working. Help us build VoTechWorks. Tell us what works, what doesn’t, and what you want to learn.
Does the school offer financial aid?
No. We don’t offer financial aid because we’re free. No, really: completely free.
Do you offer industry certification?
No. We are not certified yet, so we can’t offer that to students. What we do offer is knowledge and understanding of a trade.
Enroll first in the trade you’re interested in. You get your key, your program opens, and you begin studying.
Enroll free →