天气、快递API调用

import json
import requests
import time
class WithJson():def weather(self):str_json = self.WeatherAPI()string = str_json.replace("'", '"')#替换"'", '"'pop_data = json.loads(string)#转python字典#pop_data = json.load(f)list_pop_data=pop_data['data']['forecast']#读取列表#print(pop_data['status'])#print(pop_data['desc'])city1=(pop_data['data']['city'])wendu1=(pop_data['data']['wendu'])print('\n')print("今日:"+list_pop_data[0]['date'] +" " +city1+" "+wendu1+"°"+list_pop_data[0]['type'])print(pop_data['data']['ganmao'])rq=(pop_data['data']['yesterday']['date'])tq=(pop_data['data']['yesterday']['type'])print("*************************************************")print(rq + ": " + tq)for pop_dict in list_pop_data:date1 = pop_dict['date']tianqi = pop_dict['type']print(date1 + ": " + tianqi)def ExpressCheck(self):str_json =self.ExpressAPI()#字符串string = str_json.replace("'", '"')#替换"'", '"'pop_data = json.loads(string)#转python字典list_pop_data=pop_data['data']#读取列表#print("访问结果:"+pop_data['message'])print("快递公司:"+pop_data['com'])print("快递单号:"+pop_data['nu'])print("*************************************************")for pop_dict in list_pop_data:time1 = pop_dict['time']context1 = pop_dict['context']print(time1 + ": " + context1)def ExpressAPI(self):URL2 = 'http://www.kuaidi100.com/query?type=zhongtong&postid=73116039505988'try:r = requests.get(URL2, params={'ip': '8.8.8.8'}, timeout=1)r.raise_for_status()  # 如果响应状态码不是 200,就主动抛出异常except requests.RequestException as e:print(e)else:result = r.json()#print(result)js = json.dumps(result)return jsdef WeatherAPI(self):URL2 = 'http://wthrcdn.etouch.cn/weather_mini?city=西安'try:r = requests.get(URL2, params={'ip': '8.8.8.8'}, timeout=1)r.raise_for_status()  # 如果响应状态码不是 200,就主动抛出异常except requests.RequestException as e:print(e)else:result = r.json()#print(result)js = json.dumps(result)#print(js)return jsif __name__ == '__main__':WithJson=WithJson()WithJson.weather()print("*************************************************")print('\n')print("*************************************************")WithJson.ExpressCheck()input('Press Enter to exit...')

天气、快递API调用相关推荐

  1. 基于C#的全国天气查询API调用代码实例

    全国天气查询API:https://www.juhe.cn/docs/api/id/39 基于C#的全国天气查询API调用代码实例 using System; using System.Collect ...

  2. Weather API 天气应用 API调用分享

    Weather API 分享 链接:https://openweathermap.org/api 注册默认是One Call API 3.0 适合学生项目练手 提供以下天气数据: 当前天气 每小时.分 ...

  3. 百度地图天气接口api调用

    RestTemplate restTemplate = new RestTemplate();Map<String,String> map = new HashMap<String, ...

  4. 好玩的API调用之---天气预报的API调用与爬虫

    更多技术文章请访问我的个人博客http://www.rain1024.com 好玩的API调用之-天气预报的API调用与爬虫 平时写程序经常需要用到一些服务,像翻译,天气预报,星座什么的,我一般都是用 ...

  5. java调用天气预报api_java调用中国天气网api获得天气预报信息

    以冰城哈尔滨为例 1.[代码][Java]代码 //通过中国天气api调用 private String getWeatherInfo2(){ StringBuilder info = new Str ...

  6. 第三方快递接口API调用

    更多面试题请狠狠的点击 下载 快递鸟接口API调用案例,因时间仓促,没有申请EBusinessID和APPkey,申请id和替换: 接口文档及各开发语言Demo <

  7. java获取动态天气api,java调用中国天气网api获得天气预报信息

    //通过中国天气api调用 private String getWeatherInfo2(){ StringBuilder info = new StringBuilder(); try { Defa ...

  8. 免费的天气查询api接口调用

    经过查找,找到一个免费的天气接口api ,现在提供给大家使用. 天气接口api 地址:http://wthrcdn.etouch.cn/weather_mini?city=城市名称 调用实例:输入参数 ...

  9. php调用天气预报接口,PHP调用百度天气接口API实现查询实时天气

    现在,不用守着晚上7点半的时间去看第二天的天气预报,只要你有手机,有网络,便可以轻松查询实时天气,可你知道怎么用PHP实现的吗?本文将带大家学习一种调用百度天气接口的方式,直接在PHP上查看实时天气, ...

最新文章

  1. Python发送邮件(带附件)
  2. Java实现二叉树的构建与遍历
  3. 对ListView滚动状态的监听
  4. 【逆天的算法】这几首宋词,你能看出来是出自计算机之手吗?
  5. 可变车道怎么走不违章_郑州街头现可变车道?该咋走?记者实地探访
  6. JavaScript实现depth First Search深度优先搜索算法(附完整源码)
  7. 再见了微服务!全面拥抱 DDD 真正的价值
  8. python画五角星填充不同颜色_不同颜色牡丹怎么画?3种牡丹图解教你画,适合0基础学习,收藏...
  9. bean validation校验方法参数_Spring Validation最佳实践及其实现原理,参数校验没那么简单!
  10. 在ASP.NET MVC应用程序中随机获取一个字符串
  11. tomcat实现https双向认证(在win10系统使用jdk1.8自带工具keytool)
  12. Vue中用到jeDate日期控件,Vue对象中的值滞后,总是滞后当前选择的值
  13. 团队项目-Recycle需求规格说明书
  14. PHP语言25周年,PHP是世界上最好的语言
  15. win7安装镜像注入USB3.0,NVMe驱动
  16. 将最新Chromium浏览器集成到.NET应用程序中
  17. python turtle画彩虹的代码_Python turtle画图库画姓名实例
  18. 爬虫基础:HTTP基本原理
  19. 日语学习之——五十音图及单词(2)
  20. Elasticsearch 多种跨机房灾备方案对比与实战解读

热门文章

  1. 树莓派安装系统详细步骤
  2. java多线程同步,线程安全--一网打尽
  3. 828. 统计子串中的唯一字符
  4. linux 文件按某列排序,sort如何按指定的列排序,linux按照指定列对文件排序
  5. MySQL 关联查询多一列统计出勤
  6. 新概念英语1册19课
  7. 微信小程序体验使用方法
  8. 图文解释什么是敏捷开发
  9. LVGL笔记(6)-电子相册使用手势切换图片(windows仿真)
  10. ubuntu16.04安装cuda9——简明教程