程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python money making tips - make new reminders every day

編輯:Python

Stock market hits new bonds , As long as you win the lottery, you are basically guaranteed to earn without losing , But not every day , It's troublesome to watch every day . So there is the following automation program .

import requests
import time
import smtplib
from datetime import datetime
from email.mime.text import MIMEText
def web():
url = 'https://www.jisilu.cn/data/cbnew/pre_list/?___jsl=LST___t=1633347537744'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36'
}
data = {
'progress': '',
'rp': '22',
'page': '1'
}
try:
dic_bond = requests.post(url, data, headers).json()
data_list = []
data_list2 = []
num = 0
num1 = 0
num2 = 0
num3 = 0
now_time = ' You can subscribe today :'
future_time = ' You can subscribe in the future :'
for i in range(len(dic_bond['rows'])):
if '' == dic_bond['rows'][i]['cell']['bond_id']:
break
bond_id = dic_bond['rows'][i]['cell']['bond_id']
bond_nm = dic_bond['rows'][i]['cell']['bond_nm']
progress_nm = dic_bond['rows'][i]['cell']['progress_nm']
rating_cd = dic_bond['rows'][i]['cell']['rating_cd']
stock_nm = dic_bond['rows'][i]['cell']['stock_nm']
amount = dic_bond['rows'][i]['cell']['amount']
d1 = datetime.strptime(time.strftime("%Y-%m-%d", time.localtime()), '%Y-%m-%d')
d2 = datetime.strptime(progress_nm[:10], '%Y-%m-%d')
if d1 > d2:
break
elif d1 == d2:
if ' apply for the purchase 'in progress_nm:
num += 1
# now_time = '<h3> You can subscribe today :</h3>'
content = '<br \> Code :' + bond_id + '<br \> name :' + bond_nm + '<br \> Name of stock :' + stock_nm + '<br \><font color="red"> Time :' + progress_nm[:12] + '</font>'+ '<br \>' + ' The rating : ' + rating_cd + '<br \>'+ ' Scale of distribution ( One hundred million yuan ):' + amount + '<br \> <br \>'
# data_list1.append(now_time)
data_list.append(content)
if ' list 'in progress_nm:
num1 += 1
# now_time = '<h3> You can subscribe today :</h3>'
# content1 = '<br \> Code :' + bond_id + '<br \> name :' + bond_nm + '<br \> Name of stock :' + stock_nm + '<br \> Time :' + progress_nm[:12] + '<br \>' + ' The rating : ' + rating_cd + '<br \>'+ ' Scale of distribution ( One hundred million yuan ):' + amount + '<br \> <br \>'
content1 = '<br \> Code :' + bond_id + '<br \> name :' + bond_nm + '<br \> Name of stock :' + stock_nm + '<br \> Time :' + progress_nm[:12] + '<br \>' + ' The rating : ' + ' Scale of distribution ( One hundred million yuan ):' + amount + '<br \> <br \>'
# data_list1.append(now_time)
data_list.append(content1)
elif d1 < d2:
if ' apply for the purchase 'in progress_nm:
num2 += 1
# future_time = '<h3> You can subscribe in the future :</h3>'
content = '<br \> Code :' + bond_id + '<br \> name :' + bond_nm + '<br \> Name of stock :' + stock_nm + '<br \><font color="green"> Time :' + progress_nm[:12] + '</font>' + '<br \>' + ' The rating : ' + rating_cd + '<br \>'+ ' Scale of distribution ( One hundred million yuan ):' + amount + '<br \> <br \>'
# data_list2.append(future_time)
data_list2.append(content)
if ' list 'in progress_nm:
num3 += 1
# now_time = '<h3> You can subscribe today :</h3>'
content1 = '<br \> Code :' + bond_id + '<br \> name :' + bond_nm + '<br \> Name of stock :' + stock_nm + '<br \> Time :' + progress_nm[:12] + '<br \>' + ' The rating : ' + rating_cd + '<br \>'+ ' Scale of distribution ( One hundred million yuan ):' + amount + '<br \> <br \>'
# data_list1.append(now_time)
data_list2.append(content1)
now_time += str(num)
now_time = "<h3><font color='red'>" + now_time + "</font></h3>"
future_time += str(num2)
future_time = "<hr /><h3><font color='green'>" + future_time + "</font></h3>"
data_list.insert(0,now_time)
data_list2.insert(0,future_time)
data_list.extend(data_list2)
# else:
# content = ' Code :' + bond_id + '<br \> name :' + bond_nm + '<br \> Name of stock :' + stock_nm + '<br \> Time :' + progress_nm[:12] + '<br \>' + ' The rating : ' + rating_cd + '<br \>'+ ' Scale of distribution ( One hundred million yuan ):' + amount + '<br \> <br \>'
# data_list.append(content)
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
str_data = ''.join(data_list)
print(str_data)
email(str_data)
except IOError:
print(' abnormal !')
def email(str_data):
mail_host = 'smtp.qq.cn'
mail_user = '******@qq.com' # email accounts
mail_pass = '*******' # Email authorization code
sender = '******@qq.com' # Send email account
receivers = ['*****@qq.com,*****@qq.com'] # Accept email account
mail_msg = """
<html>
<body>
<p><a href="https://www.jisilu.cn/data/cbnew/#pre"> Jisilu convertible bond </a></p>
$(data_list)
</body>
</html>
"""
mail_msg = mail_msg.replace("$(data_list)", str_data)
message = MIMEText(mail_msg, 'html', 'utf-8')
message['Subject'] = ' Subscription of convertible bonds / Listing news '
message['From'] = sender
# message['To'] = receivers[0]
# message['To'] = receivers
message['To'] = ','.join(receivers)
try:
# smtpObj = smtplib.SMTP()
# smtpObj.connect(mail_host, 25)
smtpObj = smtplib.SMTP_SSL("smtp.qq.com", 465)
smtpObj.set_debuglevel(1)
smtpObj.login(mail_user, mail_pass)
# smtpObj.sendmail(sender, receivers, message.as_string())
smtpObj.sendmail(sender, message['To'].split(','), message.as_string())
smtpObj.quit()
print('Email sent successfully')
except smtplib.SMTPException as e:
print('error', e)
if __name__ == '__main__':
web()

The results are as follows :

Then put the script on the computer , Set daily scheduled operation . So here I'm going to use theta centos Server's crontab Regular service .
edit crontab Script

crontab -e

Add the following code , Then save

46 09 * * 1,2,3,4,5 python3 /home/sky/main.py

Once a week 1,2,3,4,5 morning 9 spot 46 Run this script regularly ( The stock market is closed on weekends, so it doesn't run )

restart crontab

systemctl restart crond

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved