All Projects → zifangsky → Weatherspider

zifangsky / Weatherspider

天气爬虫(全国城镇天气自动定时抓取更新,并开放RESTful查询接口),附带代理IP池定时更新并检测其可用性

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Weatherspider

Sureness
A simple and efficient open-source security framework that focus on protection of restful api.
Stars: ✭ 254 (-24.63%)
Mutual labels:  restful-api, spring, springboot
Perfect Ssm
🍇更完善的Spring+SpringMVC+Mybatis+easyUI后台管理系统(RESTful API+redis)
Stars: ✭ 606 (+79.82%)
Mutual labels:  restful-api, spring, springboot
Hikaku
A library that tests if the implementation of a REST-API meets its specification.
Stars: ✭ 154 (-54.3%)
Mutual labels:  restful-api, spring
Cloudopt Next
A simple and modern Java and Kotlin vert.x web framework
Stars: ✭ 211 (-37.39%)
Mutual labels:  restful-api, springboot
Java Spring Cloud
Distributed tracing for Spring Boot, Cloud and other Spring projects
Stars: ✭ 326 (-3.26%)
Mutual labels:  spring, springboot
Restfeel
RESTFeel: 一个企业级的API管理&测试平台。RESTFeel帮助你设计、开发、测试您的API。
Stars: ✭ 59 (-82.49%)
Mutual labels:  restful-api, springboot
Webfluxtemplate
Spring Webflux template application with working Spring Security, Web-sockets, Rest, Web MVC, and Authentication with JWT.
Stars: ✭ 107 (-68.25%)
Mutual labels:  restful-api, spring
FullStack-Angular-SpringBoot
Customer Relationship Managment [Full-stack Web Development using Angular & SpringBoot (RestFull API)]
Stars: ✭ 48 (-85.76%)
Mutual labels:  springboot, restful-api
Oneblog
👽 OneBlog,一个简洁美观、功能强大并且自适应的Java博客
Stars: ✭ 678 (+101.19%)
Mutual labels:  spider, springboot
Trampoline
Admin Spring Boot Locally
Stars: ✭ 325 (-3.56%)
Mutual labels:  spring, springboot
Yfax Parent
SprintBoot开发的Rest API接口项目实战,集成了拦截器,日志处理,mysql,mybatis, oauth2.0, spring secutity等,已投入生产线上使用。应用了https://github.com/hemin1003/spring-boot-study 所含功能。配套的后台管理系统实战见:https://github.com/hemin1003/aylson-parent
Stars: ✭ 271 (-19.58%)
Mutual labels:  restful-api, springboot
Naivechat
🎭 本项目是作者小傅哥使用JavaFx、Netty4.x、SpringBoot、Mysql等技术栈和偏向于DDD领域驱动设计方式,搭建的仿桌面版微信实现通信核心功能。课程文章已发布到GitChat专栏,欢迎购买。如果本项目能为您提供帮助,请给予支持(关注、⭐️Star、分享)!
Stars: ✭ 290 (-13.95%)
Mutual labels:  spring, springboot
Cerberus
A demonstration of a completely stateless and RESTful token-based authorization system using JSON Web Tokens (JWT) and Spring Security.
Stars: ✭ 482 (+43.03%)
Mutual labels:  restful-api, spring
Ssm Cluster
🍏Spring+SpringMVC+Mybatis+adminLTE3实现前后端分离(nginx负载均衡+tomcat集群)
Stars: ✭ 142 (-57.86%)
Mutual labels:  restful-api, spring
Hiweather
A Chinese Weather Website based on Kotlin and SpringBoot. Using Spiders to gather weather and location data.
Stars: ✭ 37 (-89.02%)
Mutual labels:  weather, springboot
Awesome Spring Boot
Code based and real world examples of Spring Boot and shiny things. 😍
Stars: ✭ 303 (-10.09%)
Mutual labels:  spring, springboot
Javacollection
Java开源项目之「自学编程之路」:学习指南+面试指南+资源分享+技术文章
Stars: ✭ 2,957 (+777.45%)
Mutual labels:  spring, springboot
Bus
Bus 是一个基础框架、服务套件,它基于Java8编写,参考、借鉴了大量已有框架、组件的设计,可以作为后端服务的开发基础中间件。代码简洁,架构清晰,非常适合学习使用。
Stars: ✭ 253 (-24.93%)
Mutual labels:  spring, springboot
Light Task Scheduler
Distributed Scheduled Job Framework
Stars: ✭ 2,899 (+760.24%)
Mutual labels:  spring, springboot
Springboot Analysis
🍃 something about springboot
Stars: ✭ 301 (-10.68%)
Mutual labels:  spring, springboot

WeatherSpider

天气爬虫(全国城镇天气自动定时抓取更新,并开放RESTful查询接口),附带代理IP池定时更新并检测其可用性

2018年6月更新说明:

这个项目本来是我两年前写的一个Demo项目,当时为了熟悉Java开发的常用框架,因此在项目中使用了一些没必要的框架,导致最后项目的框架依赖问题比较严重,且部分代码的写法较为繁琐。这两年来,因为这个项目还是获得了一些朋友的喜欢,加上自己对Java技术有了更多的了解,因此在这个6月我对项目代码进行了重构。项目的总体逻辑没有改变,只是优化了项目的架构、减少了技术依赖以及优化了部分代码的写法。

特别提醒:

技术依赖:

  • Spring Boot:项目基础架构,包括提供基本Web服务定时调度服务
  • DruidAlibaba开源的JDBC数据库连接池
  • MyBatis:一款优秀的持久层框架 ,用于访问MySQL数据库
  • WebMagic:轻量型爬虫框架,用于抓取每个城镇的天气以及抓取免费代理IP(抓取到的代理IP没有在项目中使用
  • Spring Kafka:用于在Spring应用中连接Kafka集群,在项目中主要通过消息队列的方式更新各个城市的天气以及检测爬取到的代理IP是否失效
  • ZooKeeperSpring Kafka环境需要的依赖

环境依赖:

  • JDK8+
  • MYSQL5.7+
  • Kafka集群
特别提醒:

项目结构:

项目结构

项目运行:

1、下载源码:

项目地址:https://github.com/zifangsky/WeatherSpider

PS:希望感兴趣的朋友给我来一波star,谢谢!

2、配置Kafka集群:

具体安装步骤可以参考上面给出的链接,然后创建两个项目中需要使用的Topic,它们分别是:topic-proxyIptopic-weather

3、配置数据库环境:

具体用到的SQL文件可以参考上面给出的链接

4、修改项目的配置文件:

在这里只需要修改项目中application-dev.properties文件的相关配置即可,具体配置项的含义可以参考注释

5、运行项目:

使用Maven编译项目,然后运行编译生成的jar文件(或者可以直接下载Releases的jar包)。在项目启动起来之后,就可以根据前面设置的定时任务、在指定时间执行天气更新任务、代理IP获取任务以及代理IP的可用性检测任务

项目对外提供的RESTful接口:

本项目对外发布了4个RESTful风格的接口。它们分别是:

i)随机返回一个可用的代理IP:

http://localhost:7080/proxyIp/selectRandomIP

其输出报文如下:

{
  "id": 676,
  "ip": "101.37.79.125",
  "port": 3128,
  "type": "HTTPS",
  "addr": null,
  "used": false,
  "other": null
}
ii)返回当前所有可用的代理IP:

http://localhost:7080/proxyIp/selectAll

其输出报文如下:

[
  {
    "id": 667,
    "ip": "61.135.217.7",
    "port": 80,
    "type": "HTTP",
    "addr": "北京",
    "used": false,
    "other": null
  },
  {
    "id": 668,
    "ip": "122.114.31.177",
    "port": 808,
    "type": "HTTP",
    "addr": "河南郑州",
    "used": false,
    "other": null
  },
  {
    "id": 669,
    "ip": "221.228.17.172",
    "port": 8181,
    "type": "HTTPS",
    "addr": "江苏无锡",
    "used": false,
    "other": null
  },
  
  ...
  
]
iii)根据城镇CODE返回一个城镇天气:

http://localhost:7080/weather/selectByStationCode/{stationCode}

注意:这里的 CODE可以从数据库的weather_station表查询

其输出报文如下:

{
  "country": {
    "id": 1,
    "code": "101",
    "name": "中国",
    "description": null
  },
  "province": {
    "id": 18,
    "code": "10106",
    "countryId": 1,
    "name": "吉林",
    "description": null
  },
  "city": {
    "id": 175,
    "code": "1010604",
    "provinceId": 18,
    "name": "四平",
    "description": null
  },
  "station": {
    "id": 214,
    "code": "101060404",
    "cityId": 175,
    "name": "公主岭",
    "description": null
  },
  "weather": {
    "id": 172,
    "stationId": 214,
    "hour": "[\"21日08时,d01,多云,21℃,西南风,<3级,2\",\"21日11时,d00,晴,24℃,西南风,<3级,1\",\"21日14时,d00,晴,24℃,西南风,<3级,1\",\"21日17时,d00,晴,26℃,西南风,<3级,1\",\"21日20时,n00,晴,23℃,西南风,<3级,0\",\"21日23时,n00,晴,19℃,西南风,<3级,0\",\"22日02时,n00,晴,19℃,西南风,<3级,0\",\"22日05时,n00,晴,19℃,西南风,3-4级,0\",\"22日08时,d00,晴,24℃,西南风,3-4级,1\"]",
    "today": "21日(今天),晴,27/19℃,西南风/西南风,<3级转3-4级",
    "nextday": "22日(明天),晴,30/22℃,西南风/西南风,4-5级转3-4级",
    "next2day": "23日(后天),小雨转晴,29/20℃,西南风/西南风,<3级",
    "next3day": "24日(周日),晴,29/18℃,西南风/西南风,<3级转4-5级",
    "next4day": "25日(周一),晴,28/17℃,西南风/西南风,4-5级转<3级",
    "next5day": "26日(周二),小雨,25/16℃,西南风/西南风,<3级",
    "next6day": "27日(周三),小雨转大雨,26/15℃,西南风/无持续风向,<3级",
    "t24situation": null,
    "other": null
  }
}
iv)根据城镇名称模糊查询,返回所有匹配的城镇天气:

http://localhost:7080/weather/selectByStationName/{stationName}

注意:这里的stationName可以是城市/地区的中文名称,比如:朝阳

其输出报文如下:

[
  {
    "country": {
      "id": 1,
      "code": "101",
      "name": "中国",
      "description": null
    },
    "province": {
      "id": 16,
      "code": "10107",
      "countryId": 1,
      "name": "辽宁",
      "description": null
    },
    "city": {
      "id": 144,
      "code": "1010712",
      "provinceId": 16,
      "name": "朝阳",
      "description": null
    },
    "station": {
      "id": 13,
      "code": "101071201",
      "cityId": 144,
      "name": "朝阳",
      "description": null
    },
    "weather": {
      "id": 105,
      "stationId": 13,
      "hour": "[\"21日08时,d00,晴,24℃,西北风,<3级,2\",\"21日11时,d00,晴,32℃,西北风,<3级,2\",\"21日14时,d00,晴,33℃,西北风,<3级,2\",\"21日17时,d00,晴,33℃,西北风,<3级,2\",\"21日20时,n00,晴,26℃,西北风,3-4级,0\",\"21日23时,n00,晴,22℃,西南风,3-4级,0\",\"22日02时,n00,晴,21℃,西南风,3-4级,0\",\"22日05时,n00,晴,20℃,西南风,<3级,0\",\"22日08时,d00,晴,26℃,西南风,3-4级,2\"]",
      "today": "21日(今天),晴,34/20℃,西北风/西南风,3-4级",
      "nextday": "22日(明天),多云,34/22℃,西南风/西南风,4-5级",
      "next2day": "23日(后天),多云,35/21℃,西南风/西北风,4-5级转3-4级",
      "next3day": "24日(周日),多云转雷阵雨,34/21℃,东南风/西南风,4-5级转3-4级",
      "next4day": "25日(周一),多云转小雨,33/20℃,西南风/西南风,4-5级转3-4级",
      "next5day": "26日(周二),多云转晴,31/20℃,西南风/西南风,3-4级",
      "next6day": "27日(周三),晴转小雨,33/19℃,西南风/无持续风向,3-4级转<3级",
      "t24situation": null,
      "other": null
    }
  },
  {
    "country": {
      "id": 1,
      "code": "101",
      "name": "中国",
      "description": null
    },
    "province": {
      "id": 24,
      "code": "10101",
      "countryId": 1,
      "name": "北京",
      "description": null
    },
    "city": {
      "id": 253,
      "code": "1010100",
      "provinceId": 24,
      "name": "北京",
      "description": null
    },
    "station": {
      "id": 803,
      "code": "101010300",
      "cityId": 253,
      "name": "朝阳",
      "description": null
    },
    "weather": {
      "id": 416,
      "stationId": 803,
      "hour": "[\"21日08时,d01,多云,25℃,东南风,<3级,1\",\"21日11时,d01,多云,33℃,东南风,<3级,1\",\"21日14时,d01,多云,34℃,东南风,<3级,3\",\"21日17时,d01,多云,33℃,东南风,<3级,3\",\"21日20时,n01,多云,32℃,东南风,<3级,0\",\"21日23时,n01,多云,24℃,东南风,<3级,0\",\"22日02时,n01,多云,24℃,东南风,<3级,0\",\"22日05时,n01,多云,23℃,东南风,<3级,0\",\"22日08时,d01,多云,23℃,东南风,<3级,1\"]",
      "today": "21日(今天),多云,35/23℃,东南风/东南风,<3级",
      "nextday": "22日(明天),雷阵雨转多云,32/21℃,南风/北风,<3级",
      "next2day": "23日(后天),多云转晴,35/24℃,南风/南风,<3级",
      "next3day": "24日(周日),多云,33/23℃,东南风/东风,<3级",
      "next4day": "25日(周一),阴转雷阵雨,34/24℃,北风/北风,<3级",
      "next5day": "26日(周二),多云转晴,34/22℃,西南风/西南风,<3级",
      "next6day": "27日(周三),多云,36/24℃,西南风/西南风,3-4级转<3级",
      "t24situation": null,
      "other": null
    }
  }
]

项目开发和重构思路

  1. 最原始的项目的开发思路:https://www.zifangsky.cn/901.html
  2. 本次的重构思路:https://www.zifangsky.cn/1271.html
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].