#!/usr/bin/python
import subprocess
import smtplib
def CheckFile():
file = open('old_ip.txt', 'r')
if ip != file.readline().strip():
file.close()
open('old_ip.txt', 'w').close()
file = open('old_ip.txt', 'w')
file.write(ip)
file.close()
return True
return False
def SendMail():
content = ip
mail = smtplib.SMTP('smtp.yandex.ru', 587)
mail.ehlo()
mail.starttls()
mail.login('your_login', 'secret_app_pass')
mail.sendmail('your_login', 'your_login', content)
def GetIp():
open('new_ip.txt', 'w').close()
subprocess.Popen('./get_ip.sh').wait()
GetIp()
ip = open('new_ip.txt', 'r').readline().strip()
if CheckFile() == True:
SendMail()