A newsletter HTML generator that auto-loads tech news using AI. Fetches structured content from the Perplexity API, then fills an HTML template to produce a ready-to-view or send newsletter page.
- AI-powered content — Uses Perplexity’s API to pull recent tech news (past 24 hours, viral stories, company developments).
- Structured output — Response is validated and shaped with Pydantic so the HTML template always gets the expected fields.
- Template-based HTML — Placeholders in an HTML template are replaced with the fetched data.
- Dated outputs — Each run saves a copy under
outputs/with a date and run number (e.g.template_today__number_1_14_03_2025.html). - Logging — Writes logs under
logs/for debugging and auditing.
- Python 3.x
- Perplexity API key — Get one from Perplexity (used for the “sonar” model).
-
Clone the repository
git clone https://github.com/prishadhoot/newsletter-html.git cd newsletter-html -
Create a virtual environment (recommended)
python -m venv venv # Windows venv\Scripts\activate # macOS/Linux source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Configure environment
Create a
.envfile in the project root:PERPLEXITY_API_KEY=your_perplexity_api_key_here
Do not commit
.env; it is listed in.gitignore.
From the project root, run:
python main.pyThis will:
- Fetch tech news from the Perplexity API using the prompt in
utils/templates/pplx_prompt.txt. - Validate and normalize the response against
utils/templates/response_template.json. - Load the HTML template from
utils/templates/template_placeholder.html. - Replace placeholders (
{24h_1}…{24h_6},{viral_1}…{viral_3},{company_developments}) with the API data. - Save the result as
utils/templates/template_today.htmland a dated copy inoutputs/.
Open main.html (or the generated HTML files) in a browser to view the newsletter.
| Path | Description |
|---|---|
main.py |
Entry point: logging, API fetch, data processing, template fill, and file output. |
newsletter.py |
Newsletter logic (load data, template, fill, save) — used conceptually; main.py embeds this flow. |
data_process.py / data_query.py |
Logic is inlined in main.py: API client, Pydantic models, validation, and template matching. |
main.html |
Front-end page that displays or loads the newsletter. |
utils/templates/ |
pplx_prompt.txt, response_template.json, template_placeholder.html, and generated template_today.html. |
outputs/ |
Dated newsletter HTML files (one per run). |
logs/ |
Created at runtime; log files for each run. |
- API key — Set
PERPLEXITY_API_KEYin.env. - Prompt — Edit
utils/templates/pplx_prompt.txtto change what kind of tech news is requested. - Response shape — Edit
utils/templates/response_template.jsonto match the structure expected by your template and bymain.py’s validation. - Layout — Edit
utils/templates/template_placeholder.htmland use the same placeholder names so the script can fill them.