#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# author:IversOn5

import requests
import json
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

def send_mail(Price):
    my_sender='908869236@qq.com'    # 发件人邮箱账号
    my_pass = 'xxxxxx'            # 发件人邮箱密码 这个密码是stmp授权码,请看http://www.runoob.com/python/python-email.html
    my_user='908869236@qq.com'      # 收件人邮箱账号,我这边发送给自己
    ret=True
    try:
        msg=MIMEText('XMR价格已经达到$%s'%str(Price),'plain','utf-8')
        msg['From']=formataddr(["FromRunoob",my_sender])  # 括号里的对应发件人邮箱昵称、发件人邮箱账号
        msg['To']=formataddr(["FK",my_user])              # 括号里的对应收件人邮箱昵称、收件人邮箱账号
        msg['Subject']="XMR价格检测报告"                # 邮件的主题,也可以说是标题

        server=smtplib.SMTP_SSL("smtp.qq.com", 465)  # 发件人邮箱中的SMTP服务器,端口是25
        server.login(my_sender, my_pass)  # 括号中对应的是发件人邮箱账号、邮箱密码
        server.sendmail(my_sender,[my_user,],msg.as_string())  # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
        server.quit()  # 关闭连接
    except Exception:  # 如果 try 中的语句没有执行,则会执行下面的 ret=False
        ret=False
    return ret


def get_price():
    url  = "https://bittrex.com/Api/v2.0/pub/market/GetLatestTick?marketName=USDT-XMR&tickInterval=thirtyMin&_=1509109529481"
    html = requests.get(url).content
    html_json  = json.loads(html)
    # print html_json
    result = str(html_json["result"])[1:-1]
    current_price = float(result.split(",")[0][7:12])
    # print current_price
    if current_price >= float(150.0): # XMR价格高于$150就发送Email给我
        send_mail(current_price)


if __name__ == '__main__':
    while 1:
        get_price()
        from time import sleep
        sleep(300)

发表评论

电子邮件地址不会被公开。 必填项已用*标注