一个自动监控深圳住建局公告信息更新的服务,支持定时轮询和多种通知渠道(企业微信、钉钉、飞书)。
⭐ 如果这个项目对您有帮助,请给个 Star 支持一下! ⭐
本项目仅供学习和研究使用,请遵守相关法律法规和网站服务条款。
- 本项目通过公开API获取政府网站的公开信息
- 用户使用本项目应遵守目标网站的robots.txt和服务条款
- 请合理控制请求频率,避免对目标服务器造成过大负载
- 本项目作者不承担因使用本项目而产生的任何法律责任
- 如有侵权或不当使用,请立即停止使用并联系作者
- 🔄 定时轮询: 每3分钟自动检查各区住建局公告数据更新(8:00-23:00)
- 📱 多渠道通知: 支持企业微信、钉钉、飞书等多种通知方式
- 🏠 全覆盖监控: 支持深圳市10个区的住建局数据源
- 💾 智能去重: 自动跟踪已处理的信息,避免重复通知
- 🛡️ 错误处理: 完善的错误处理和重试机制
- 📊 统计信息: 详细的运行统计和日志记录
- 🚀 优雅启停: 支持优雅启动和关闭
- 🐳 容器化部署: 提供完整的 Docker 部署方案
本服务监控以下深圳各区住建局:
| 区域 | 部门 | 状态 |
|---|---|---|
| 深圳市 | 深圳市住房和建设局 | ✅ 已支持 |
| 福田区 | 福田政府在线 | ✅ 已支持 |
| 宝安区 | 宝安区住建局 | ✅ 已支持 |
| 光明区 | 光明住建局 | ✅ 已支持 |
| 南山区 | 南山住建局 | ✅ 已支持 |
| 龙华区 | 龙华区政府 | ✅ 已支持 |
| 罗湖区 | 罗湖区政府 | ✅ 已支持 |
| 龙岗区 | 龙岗区住房和建设局 | ✅ 已支持 |
| 大鹏新区 | 大鹏新区住房和建设局 | ✅ 已支持 |
| 坪山区 | 坪山区人民政府 | ✅ 已支持 |
| 盐田区 | 盐田区住房和建设局 | ✅ 已支持 |
# 下载 docker-compose.yml
curl -O https://raw.githubusercontent.com/AeaZer/shenzhen-housing/master/docker-compose.yml
# 下载配置文件模板
curl -O https://raw.githubusercontent.com/AeaZer/shenzhen-housing/master/config.json.example# 重命名配置文件模板
cp config.json.example config.json
# 编辑配置文件,修改通知渠道的 webhook_url
vim config.json# 使用 Docker Compose
docker-compose up -d# 查看日志
docker-compose logs -f
# 停止服务
docker-compose down就这么简单!🎉
- 在企业微信群中添加机器人
- 获取 Webhook 地址
- 在配置文件中设置:
{
"type": "wechat",
"name": "通知群",
"enabled": true,
"webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_KEY",
"secret": "",
"timeout": 30
}{
"type": "dingtalk",
"name": "钉钉通知",
"enabled": true,
"webhook_url": "https://oapi.dingtalk.com/robot/send?access_token=YOUR_TOKEN",
"secret": "YOUR_SECRET",
"timeout": 30
}{
"type": "feishu",
"name": "飞书通知",
"enabled": true,
"webhook_url": "https://open.feishu.cn/open-apis/bot/v2/hook/YOUR_HOOK",
"secret": "YOUR_SECRET",
"timeout": 30
}每个数据源支持以下配置项:
{
"name": "数据源名称",
"base_url": "API地址",
"website": "官网地址",
"timeout": 30,
"user_agent": "请求头",
"enabled": true,
"schedule": "*/3 8-23 * * *"
}schedule: Cron 表达式,控制检查频率*/3 8-23 * * *: 每3分钟检查一次(8:00-23:00)*/5 * * * *: 每5分钟检查一次0 */1 * * *: 每小时检查一次0 9,18 * * *: 每天9点和18点检查
采用模块化接口设计,易于扩展:
shenzhen-housing/
├── config/ # 配置模块
│ └── config.go
├── internal/ # 内部模块
│ ├── announcer/ # 公告数据源模块
│ │ ├── announcer.go # 接口定义
│ │ ├── common.go # 通用实现
│ │ ├── futian.go # 福田区数据源
│ │ ├── longhua.go # 龙华区数据源
│ │ ├── longgang.go # 龙岗区数据源
│ │ └── pingshan.go # 坪山区数据源
│ ├── notifier/ # 通知模块
│ │ ├── notifier.go # 通知接口
│ │ ├── manager.go # 通知管理器
│ │ ├── wechat.go # 企业微信通知
│ │ ├── dingtalk.go # 钉钉通知
│ │ ├── feishu.go # 飞书通知
│ │ └── formatter.go # 消息格式化
│ ├── scheduler/ # 调度器
│ │ └── scheduler.go
│ └── storage/ # 数据存储
│ ├── storage.go
│ └── memory.go
├── config.json # 配置文件
├── docker-compose.yml # Docker Compose 配置
├── Dockerfile # Docker 镜像构建
├── main.go # 主程序
├── go.mod # Go 模块文件
└── README.md # 说明文档
当发现新的住建公告时,会发送如下格式的消息:
🏠 **深圳住建公告信息更新** (2条)
**[福田区] 关于某保租房项目的公告**
📝 项目描述信息...
📅 发布时间: 2024-01-01 10:00:00
🔗 [查看详情](http://example.com)
---
**[宝安区] 关于某住房项目的通知**
📝 项目描述信息...
📅 发布时间: 2024-01-01 11:00:00
🔗 [查看详情](http://example.com)
---
⏰ 检查时间: 2024-01-01 12:00:00
企业微信/钉钉/飞书消息发送失败
- ✅ 检查 Webhook 地址是否正确
- ✅ 确认机器人已添加到群聊
- ✅ 检查网络连接
- ✅ 验证机器人权限设置
无法获取住建局数据
- ✅ 检查网络连接
- ✅ 确认API地址是否可访问
- ✅ 查看是否被网站反爬机制拦截
- ✅ 检查 User-Agent 设置
服务启动失败
- ✅ 确认JSON格式正确
- ✅ 检查配置文件路径
- ✅ 使用
-debug参数查看详细信息 - ✅ 验证数据源配置
- 运行环境: Go 1.23+
- 调度器:
github.com/robfig/cron/v3 - HTTP客户端:
github.com/go-resty/resty/v2 - 日志库:
github.com/sirupsen/logrus - HTML解析:
github.com/PuerkitoBio/goquery
- 实现DataSource接口
// 创建新文件:internal/announcer/your_district.go
type YourDistrictDataSource struct {
config *config.DataSourceConfig
logger *logrus.Logger
}
func (y *YourDistrictDataSource) GetSourceInfo(id string) SourceInfo {
return SourceInfo{
ID: id,
Name: y.config.Name,
BaseURL: y.config.BaseURL,
Website: y.config.Website,
}
}
func (y *YourDistrictDataSource) FetchAnnouncements() ([]AnnouncementItem, error) {
// 实现数据获取逻辑
return items, nil
}- 更新配置文件
{
"data_sources": {
"your_district": {
"name": "你的区住建局",
"base_url": "http://your-api-url",
"timeout": 30,
"user_agent": "Mozilla/5.0 ...",
"enabled": true,
"schedule": "*/3 8-23 * * *"
}
},
"enabled_sources": ["your_district"]
}- 注册数据源
在 main.go 的 registerDataSources 函数中添加:
if c, exists := cfg.DataSources["your_district"]; exists && c.Enabled {
manager.RegisterDataSource("your_district", announcer.NewYourDistrictDataSource(&c, logger))
}- 实现Notifier接口
// 创建新文件:internal/notifier/custom.go
type CustomNotifier struct {
config *config.NotificationConfig
logger *logrus.Logger
}
func (c *CustomNotifier) GetName() string {
return c.config.Name
}
func (c *CustomNotifier) SendTextMessage(content string) error {
// 实现消息发送逻辑
return nil
}
// 实现其他接口方法...- 注册通知器
在 internal/notifier/manager.go 的 registerNotifiers 方法中添加:
case "custom":
m.AddNotifier(NewCustomNotifier(¬ifierConfig, logger))- ✅ 支持深圳市10个区的住建局数据监控
- ✅ 支持企业微信、钉钉、飞书三种通知渠道
- ✅ 完整的Docker容器化部署方案
- ✅ 智能去重和内存存储
- ✅ 完善的错误处理和日志记录
MIT License