Creating a weather bot using Python and OpenAI

Christopher Collins
Curious About Python
2 min readAug 5, 2022

--

A python tutorial that combines openai API with weatherstack API

In this tutorial, you will learn how to combine the openai API with the weatherstack API to create a weather bot that uses AI to give an opinion on what you should wear and do when you visit a location.

weather bot created using Python combining Weather Stack API and Open AI API

To get started, you will need to create a weatherstack account and obtain an API key.

Once you have your API key, you will need to install the openai library.

pip install openai 

With both of these libraries installed, you can now get started on the weather bot.

Use the openai API to generate a new text based on the current weather conditions. Alter the prompt code to get more interesting results.

Full code, just add your API keys

import requests
import os
import openai
location = input('Where are you going today?:')
weatherstack_api_key = 'YOUR API KEY'
openai.api_key = "YOUR API KEY"
def get_answer(location,weatherstack_api_key):
response…

--

--

Christopher Collins
Curious About Python

I write about coding, crypto, the tech future,please follow my publication https://medium.com/aiwriters/ 😀