https://api.openweathermap.org/data/3.0/onecall?lat=39.9042&lon=116.4074&exclude=minutely,hourly&appid=你的API密钥&units=metric
import requests
def get_weather(lat, lon, api_key):
url = f"https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude=minutely,hourly&appid={api_key}&units=metric"
response = requests.get(url)
data = response.json()
return data
# 调用示例
weather_data = get_weather(39.9042, 116.4074, "你的API密钥")
print(weather_data)
current_temp = weather_data['current']['temp']
weather_description = weather_data['current']['weather'][]['description']
print(f"当前温度:{current_temp}°C,天气状况:{weather_description}")
@Service
public class WeatherService {
private final RestTemplate restTemplate;
private final String apiKey = "你的API密钥";
public WeatherService(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
public WeatherResponse getWeather(String city) {
String url = "http://api.openweathermap.org/data/2.5/weather";
return restTemplate.getForObject(
url,
WeatherResponse.class,
new ParameterizedTypeReference<>() {},
city,
apiKey
);
}
}
npm install request
const request = require('request');
function getWeather(city, apiKey, callback) {
const url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric`;
request(url, (error, response, body) => {
if (error) {
callback('无法连接到天气服务', null);
return;
}
const data = JSON.parse(body);
if (data.cod !== ) {
callback(`天气查询失败:${data.message}`, null);
return;
}
const weather = {
temperature: data.main.temp,
description: data.weather[].description
};
callback(null, weather);
});
}
// 调用示例
getWeather('北京', '你的API密钥', (error, weather) => {
if (error) {
console.error(error);
} else {
console.log(`北京的天气:${weather.description},温度:${weather.temperature}°C`);
}
});
<uses-permission android:name="android.permission.INTERNET" />
private class WeatherTask extends AsyncTask<String, Void, Weather> {
@Override
protected Weather doInBackground(String... params) {
String city = params[];
String apiKey = "你的API密钥";
String url = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=" + apiKey + "&units=metric";
try {
URL weatherUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection) weatherUrl.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int responseCode = connection.getResponseCode();
if (responseCode == ) {
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
StringBuilder response = new StringBuilder();
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
JSONObject jsonObject = new JSONObject(response.toString());
return parseWeatherJson(jsonObject);
}
} catch (IOException | JSONException e) {
e.printStackTrace();
}
return null;
}
private Weather parseWeatherJson(JSONObject jsonObject) throws JSONException {
Weather weather = new Weather();
JSONObject main = jsonObject.getJSONObject("main");
weather.temp = main.getDouble("temp");
JSONArray weatherArray = jsonObject.getJSONArray("weather");
weather.description = weatherArray.getJSONObject().getString("description");
return weather;
}
@Override
protected void onPostExecute(Weather weather) {
if (weather != null) {
tvWeatherInfo.setText("天气现象: " + weather.description + ", 温度: " + weather.temp + "°C");
} else {
tvWeatherInfo.setText("无法获取天气信息");
}
}
}
import time
from functools import lru_cache
@lru_cache(maxsize=)
def get_weather_with_cache(lat, lon, api_key):
# 这里写获取天气数据的逻辑
pass
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.addHeader("Accept-Encoding", "gzip")
.build();
import os
api_key = os.environ.get('WEATHER_API_KEY')
现在做内容的谁还没被 AI 写作坑过?辛辛苦苦攒的素材,扔进去生成的东西要么像白开水,要么堆砌辞藻根本没法用。但你要说 AI 润色完全没用?那也太武断了。最近试了不下 20 个免费的 AI 润色工具,
🔥 企业微信 2025 年新功能曝光!私域运营效率直接翻倍的秘诀都在这儿了 企业微信这两年在私域流量运营这块儿的动作越来越猛,特别是 2025 年的新版本,简直像是给运营人量身定制了一套 “效率核武
现在做小红书矩阵号的人越来越多,大家都想通过批量运营账号来提高曝光和销量。但手动写文案太费时间,效率根本跟不上。不过别担心,今天就给大家分享 2025 年最新的 AI 批量生成小红书矩阵号文案的方法,
? 功能架构解析:四端联动打造文化生态圈 江苏文脉中国大运河平台 APP 的核心竞争力,在于其首创的 “一云四端” 架构体系,将政务、公众、企业、国际四大服务端有机整合,形成了立体化的文化资源网络。政
?Voghion 凭啥成中国卖家出海欧洲新宠?无保证金 + 流量红利真香 欧洲市场向来是跨境电商的硬骨头,动辄 thousands 欧元的保证金让中小卖家望而却步,流量成本高企更是愁坏了不少开拓者。但
开通面包多订阅专栏其实一点都不难,跟着步骤来,新手也能轻松上手。闪电结算技术更是创作者的福音,能让你快速实现创作盈利。 ? 开通面包多订阅专栏的详细步骤 开通面包多订阅专栏的第一步是注册账号。你可以通
? 印象笔记 AI 辅助创作怎么用?一键剪藏 OCR 扫描提升知识管理效率 作为一个用了五年印象笔记的老用户,我最近被它的 AI 功能惊艳到了。以前整理资料得花好几个小时,现在用 AI 辅助创作和一键
? 手机端如何高效使用 Brandcolors?设计师移动配色工具推荐 在移动设计场景中,快速获取品牌配色方案并高效应用是设计师的刚需。Brandcolors 作为全球知名的品牌配色库,虽无独立 Ap