Last active
October 1, 2015 20:12
-
-
Save shota-aizawa/6646f6b3ef923717fada to your computer and use it in GitHub Desktop.
Home Work: Email Parse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import feedparser | |
import time | |
import subprocess | |
import socket | |
import smtplib | |
import datetime | |
import urllib2 | |
user='***@newschool.edu'// my email address | |
passwd='***' // my password | |
smtpserver=smtplib.SMTP('smtp.gmail.com',587) | |
smtpserver.ehlo() | |
smtpserver.starttls() | |
smtpserver.ehlo | |
smtpserver.login(user,passwd) | |
today=datetime.date.today() | |
arg='ip route list' | |
p=subprocess.Popen(arg,shell=true,stdout=subprocess.PIPE) | |
data=p.communicate() | |
split_data=data[0].split() | |
ipaddr=split_data[split_data.index('src')+1] | |
extipaddr=urllib2.urlopen("http://icanhazip.com").read() | |
my_ip='Local address: %s\nExternal address: %s' % (ipaddr,extipaddr) | |
searchFeed=raw_input("search word?") | |
searchFeedTwo=int(raw_input("search word2?")) | |
newmails = feedparser.parse("https://" + user + ":" + passwd + "@mail.google.co$ | |
for i in newmails: #for loop itterates through newmails feed | |
print str(i.title) # uncomment to print out each title of unread e$ | |
if str(i.title)==searchFeed: # replace the word Search with $ | |
print i.summary | |
if str(i.title)==searchFeedTwo: | |
print i.summary | |
while True: #loop forever ---- to exit use keys "ctr+c" | |
newmails = int(feedparser.parse("https://" + user + ":" + passwd + "@mail.g$ | |
def emailcount(n): #define function emailcount | |
if n > 0: # if you have over 0 emails. You can change this based on how$ | |
print "you have "+str(n)+" new email(s)" | |
else: | |
print "you have no new email" | |
emailcount(newmails) #call emailcount function and pass value newmails as a$ | |
time.sleep(8) #wait 8 seconds | |
msg=MIMEText(my_ip) | |
msg['Subject']='New Email Feed' | |
msg['From']=user | |
msg['To']=user | |
time.sleep(5) | |
smtpserver.sendmail(user,[user],msg.as_string()) | |
smtpserver.quit | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment