您的位置:首页 > 编程语言 > Python开发

2017存钱计划(python实现)

2018-01-07 13:20 302 查看

灵感来源于在微博看到的一条微博,365天存钱法,每天从1到365中任选一个数字存钱,每一天的数字都不能重复,这样一年下来就有66795元,6W多块钱对于我来说太多,那就从0.1-36.5,根据收入多寡,每天选择其中的一个数字来存,一年就有6679.5元,是一笔不少的数字。那就开始吧。

考虑到之前租借的vps利用率不高,就打算用vps中安装的centos的定时任务crontab,配合上sendmail来发送邮件告知每日应该存多少钱。

安装Xshell,连接上远端服务器。 yum -y install sendmail crontabs 安装必要的软件。

touch sendmail.py vim sendmail.py

#!/usr/bin/python
#-*-coding:utf-8 -*-  //指定编码,兼容中文
import random
import os
import time
import datetime

# the remainder days of next China Year
today = datetime.date.today()
other_day = datetime.date(2018,2,15)
remainder = other_day - today

# 每日存钱的数字
tar = random.randint(1,365)

result = []
with open('/root/saveMoney/saved.txt','r') as f:
data = f.readlines()
for line in data:
tmp = line.split()
for x in tmp:
result.append(x)
num_int = map(float,result)
while str(tar) in result:
tar = random.randint(1,365)// 保证产生的数不重复

# 保存已经存过的数字到saved.txt
with open('/root/saveMoney/saved.txt','a') as f:
f.write(' ')
f.write(str(tar))
f.close()
# 要发送的文本写入到todo.txt
with open('/root/saveMoney/todo.txt','w') as f:
f.write("今天,Centos6建议您存入" + str(tar/10.0) + "元\n")
f.write("距离过年还有" + str(remainder.days) + "天")
f.close()

#调用mail外部命令发送邮件
os.system(" mail -s 'save money plant' xx@xx.com < /root/saveMoney/todo.txt")


到此,结束。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Python