A Python bot that scrapes weather data, summarizes it using OpenAI’s GPT-4o-mini, and posts to Bluesky with an image using the atproto protocol. Deployed on Google Cloud Functions with secure environment configs, it showcases skills in web scraping, AI (LLM) integration, and cloud automation.
How it works:
- Scrapes Data:
- It fetches the latest news text from the CGE SP news page (
https://www.cgesp.org/v3//noticias.jsp) usingrequestsandBeautifulSoup. - It extracts the URL of the current illustrative weather condition image from the CGE SP weather station page (
https://www.cgesp.org/v3//estacoes-meteorologicas.jsp) by parsing CSS rules found in a<style>tag usingBeautifulSoupand regular expressions.
- It fetches the latest news text from the CGE SP news page (
- Summarizes News:
- The scraped news text is sent to the OpenAI API (
gpt-4o-miniat the moment). - A specific prompt instructs the model to generate a concise summary (300 characters) in Brazilian Portuguese, highlighting key weather information and any alerts, suitable for a microblog post.
- The scraped news text is sent to the OpenAI API (
- Downloads Image:
- The script downloads the image file identified in step 1.
- Posts to Bluesky:
- Using the
atprotolibrary, the script logs into Bluesky. - It creates a new post containing the generated summary and attaches the downloaded weather image.
- Using the
- Execution & Configuration:
- The script requires
BLUESKY_USERNAME,BLUESKY_PASSWORD, andOPENAI_API_KEYto be set as environment variables. - It includes extensive logging for monitoring.
- It can be run locally for testing or deployed as a Google Cloud Function (
cloud_entry_point) designed to be triggered periodically (e.g., by Google Cloud Scheduler).
- The script requires
Motivation: A personal project for learning Python and libraries related to web scraping, generative artificial intelligence, and the use of Google Cloud Platform (GCP) and its tools: Cloud Scheduler, Cloud Functions—aiming for security through the use of Secret Manager and efficiency through low resource usage.
Este script em Python automatiza a publicação de atualizações meteorológicas no Bluesky com uma pequena ajuda de IA (LLM) pra resumir notícias.
Como funciona:
- Coleta de Dados:
- Busca o texto da notícia mais recente na página de notícias do CGE SP (
https://www.cgesp.org/v3//noticias.jsp) usandorequestseBeautifulSoup. - Extrai a URL da imagem da condição meteorológica atual da página de estações meteorológicas do CGE SP (
https://www.cgesp.org/v3//estacoes-meteorologicas.jsp) analisando regras CSS encontradas em uma tag<style>comBeautifulSoupe expressões regulares.
- Busca o texto da notícia mais recente na página de notícias do CGE SP (
- Resumo da Notícia:
- O texto da notícia coletado é enviado para a API da OpenAI (
gpt-4o-mini, atualmente). - Um prompt específico instrui o modelo a gerar um resumo conciso (cerca de 300 caracteres) em Português (Brasil), destacando informações meteorológicas chave e quaisquer alertas, adequado para um post de microblog como Bluesky ou Twitter.
- O texto da notícia coletado é enviado para a API da OpenAI (
- Download da Imagem:
- O script baixa o arquivo de imagem identificado na etapa 1 e o mantém na memória.
- Publicação no Bluesky:
- Usando a biblioteca
atproto, o script faz login no Bluesky. - Cria um novo post contendo o resumo gerado e anexa a imagem ilustrativa meteorológica baixada.
- Usando a biblioteca
- Execução e Configuração:
- O script requer que
BLUESKY_USERNAME,BLUESKY_PASSWORD, eOPENAI_API_KEYsejam definidas como variáveis de ambiente. - Inclui logs detalhados para monitoramento.
- Pode ser executado localmente para testes ou implantado como uma Google Cloud Function (
cloud_entry_point), projetada para ser acionada periodicamente (por exemplo, pelo Google Cloud Scheduler).
- O script requer que
Objetivo: Fornecer atualizações meteorológicas resumidas e oportunas, acompanhadas de uma imagem ilustrativa, em uma conta da rede social Bluesky.
Motivação: projeto pessoal de aprendizado de Python e bibliotecas de scraping, de inteligência artificial generativa e de uso da Google Cloud Platform (GCP) e de suas ferramentas: Cloud Scheduler, Cloud Functions, buscando segurança com uso de Secret Manager e eficiência com baixo uso de recursos.