使用Python爬取双低转债及三要素可转债,自动发送邮件

双低转债及三要素可转债

注:爬取集思录上的可转债信息,并按照规则进行筛选排序,仅供交流学习之用,请勿用于商业用途

项目地址

https://gitee.com/zsyoung01/kzz

介绍

本项目采用可转债双低转债和三要素转债策略,数据抓取自集思录。

  1. 已支持三种排序筛选方式(最终结果逆序排序):
    • 溢价率升序排名+价格升序排名+到期收益率降序排名
    • 溢价率+价格-到期收益率
    • 溢价率+剩余年限-到期收益率
  2. 已支持Email添加附件发送功能
  3. 未来计划加入数据回测功能及数据告警发送email功能

特性

  1. 网络请求-数据解析-文件存储 三层结构
  2. 多线程下载
  3. 网络自动重试
  4. 错误日志记录
  5. Python3

你可能需要

  • pip3 install requests
  • pip3 install json
  • pip3 install datetime
  • pip3 install threadpool
  • pip3 install retrying

项目结构

在这里插入图片描述

代码说明

  • Main.py -> 主程序入口,业务处理
  • config.ini -> 配置文件
  • Config.py -> 解析config.ini配置文件
  • SendMailAttach.py -> 发送带附件的Email
  • ThreeElements1.py -> 溢价率升序排名+价格升序排名+到期收益率降序排名
  • ThreeElements2.py -> 溢价率+价格-到期收益率
  • ThreeElements3.py -> 溢价率+剩余年限-到期收益率(三要素)
  • HttpUtils.py -> 网络请求工具
  • FileUtils.py -> 文件保存工具
  • LogUtils.py -> 日志工具
  • Constants.py -> 常量设置

其他文件:

  • CbPrice.py -> 可转债二叉树定价模型
  • kzz.json -> 抓取到的原始数据json

使用说明

  1. 本项目只支持查询当天数据,不支持查询历史数据
  2. 发送邮件功能需要在config.ini自行设置邮件参数
  3. 参数调整完之后直接启动Main.py即可

LICENSE

 Copyright 2019 zsyoung

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
  • 0
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 12
    评论
你可以使用Python中的requests库来爬取公告通知的内容,然后使用smtplib库来发送邮件。下面是一个简单的示例代码: ```python import requests import smtplib from email.mime.text import MIMEText def send_mail(subject, body): # 设置发件人和收件人 sender = '[email protected]' receiver = '[email protected]' # 设置SMTP服务器地址和端口号 smtp_server = 'smtp.example.com' smtp_port = 587 # 设置发件人邮箱的用户名和密码 username = '[email protected]' password = 'your_password' # 创建邮件内容 msg = MIMEText(body) msg['Subject'] = subject msg['From'] = sender msg['To'] = receiver try: # 连接SMTP服务器并登录 server = smtplib.SMTP(smtp_server, smtp_port) server.starttls() server.login(username, password) # 发送邮件 server.sendmail(sender, receiver, msg.as_string()) print('邮件发送成功') except Exception as e: print('邮件发送失败:', str(e)) finally: # 关闭连接 server.quit() def crawl_announcement(url): try: # 发起HTTP请求并获取页面内容 response = requests.get(url) if response.status_code == 200: # 解析页面内容并提取公告通知 announcements = response.json() # 假设返回的是JSON格式数据,具体根据实际情况修改解析方式 return announcements else: print('请求失败,状态码:', response.status_code) except Exception as e: print('请求出错:', str(e)) # 爬取公告通知 announcements = crawl_announcement('http://example.com/announcements') if announcements: # 构造邮件内容 subject = '最新公告通知' body = '\n'.join(announcements) # 发送邮件 send_mail(subject, body) ``` 以上代码中,`crawl_announcement`函数用于爬取公告通知的内容,`send_mail`函数用于发送邮件。你需要根据实际情况修改URL、发件人和收件人的邮箱地址,SMTP服务器的地址和端口号,以及发件人邮箱的用户名和密码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

启四

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值