Workshop 01, Global Hack Week. Justin Mitchel, Coding for Entrepreneurs. With thanks to Tiger Data.
A small FastAPI app that writes machine readings into a TimescaleDB hypertable and buckets them over time. Copy the blocks below in order.
Workshop 01, Global Hack Week. Justin Mitchel, Coding for Entrepreneurs. With thanks to Tiger Data.
A small FastAPI app that writes machine readings into a TimescaleDB hypertable and buckets them over time. Copy the blocks below in order.
| """Convert a Chrome/Google bookmarks HTML export into a flat CSV. | |
| Usage: | |
| uv run google_bookmarks_to_csv.py <input.html> <output.csv> | |
| python3 google_bookmarks_to_csv.py <input.html> <output.csv> | |
| """ | |
| import csv | |
| import datetime as dt | |
| import html |
For the most up-to-date version, check out our blog at codingforentrepreneurs.com/blog (also cfe.sh/blog)
Why? Python is not SQL. That's probably obvious. An ORM (object relation mapper) is a way that developers can write Python code that gets converted into database calls (queries).
This is a basic example using pure Python and storing/retrieving data in a comma separated values (csv) file.
Here's how you use it:
| from typing import Dict, List, Optional | |
| import requests | |
| # pip install python-decouple | |
| from decouple import config | |
| NEON_API_KEY = config("NEON_API_KEY") |
Claude says:
This code handles YouTube OAuth2 authentication in a Django application. Here's what's happening: The youtube_connect function initiates the OAuth2 flow. It creates a Flow object with the necessary client configuration, scopes, and redirect URI. It then generates an authorization URL and redirects the user to Google's authentication page. The youtube_callback function handles the callback after user authentication. It retrieves the authorization code from the query parameters, creates another Flow object, and attempts to exchange the code for an access token. If successful, it fetches the user's email and channel ID using the token. The function returns an HTTP response indicating success or failure of the authentication process. Both functions use environment variables for client credentials and implement security measures like HTTPS enforcement and state verification. The code also includes error handling and logging for debugging purposes.
| #!/bin/bash | |
| # Public gist available at: | |
| # https://gist.github.com/codingforentrepreneurs/aef0968829883110e24b107f7278255f | |
| # Check if an argument is provided | |
| if [ "$#" -ne 1 ]; then | |
| echo "Usage: $0 new_hostname" | |
| exit 1 | |
| fi |
The Django Celery Redis github repo shows a full Django project leveraging the results of this blog post tutorial and this sample project.
git clone https://github.com/codingforentrepreneurs/Django-Celery-Redis
cd Django-Celery-Redismacos/linux
python3 -m venv venv
Python and many ways to create a Rest API endpoint. This one uses FastAP which is designed to easily create API endpoints for nearly anything.
REST APIs are here so software can talk to other software. REST APIs typically send JSON data types (instead of HTML like websites do for humans)
Create virtual environment, activate it, and install FastAPI and Uvicorn:
Export your Pandas analysis really easily to a PostgresSQL database table with this tutorial. We used Docker Compose to create the postgres database with docker compose up and the related compose.yaml file.
Add requirements.txt from below.
python3 -m pip install -r requirements.txt
Visit https://ollama.com to download for your system.
In the ollama library we see all kinds of available models. We'll use Llama 2 and we have a few options: