Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #/home/cpcmonster/bin/rtmsimple.py
- # Released under a GPLv3 Licence by Clockwork PC 2011
- # www.clockworkpc.com.au
- # You are entitled to the following four freedoms:
- # Freedom 0: To run this program for any purpose
- # Freedom 1: To study how this program works and change it to make it do what you wish
- # Freedom 2: To redistribute copies so you can help your neighbour
- # Freedom 3: To distribute copies of your modified version to others
- import os
- import smtplib
- import subprocess
- from time import gmtime, strftime
- #Where the task file will go
- os.system("mkdir -pv ~/Documents/rtm_tasks")
- task_path_name = os.getenv("HOME")+"/Documents/rtm_tasks/"
- print task_path_name
- current_time = strftime("%Y-%m-%d_%H%M%S", gmtime())
- rtm_task_file = task_path_name + "rtm_tasks_" + current_time + ".txt"
- print current_time
- print rtm_task_file
- #Defining what I need in order to open and edit the text file to be used later
- geany = '/usr/bin/geany'
- proc1 = subprocess.Popen([geany,rtm_task_file])
- #The easiest way to create an empty to file to populate later (Don't need it anymore, now that I finally understand Popen)
- #os.system ("touch " + rtm_task_file)
- #Gmail Login Credentials
- to = '{RTM_Import_Address}'
- gmail_user = "{Gmail Address}"
- gmail_pwd = "{Password}"
- smtpserver = smtplib.SMTP("smtp.gmail.com",587)
- #Write to the task file and wait for it to close
- def rtm_task_txt():
- proc1.wait()
- print "OK, let's send this on to rememberthemilk.com via my gmail"
- #Creating a text file for RTM tasks
- #def rtm_task_txt():
- # rtm_input = raw_input("What is the task? ")
- # rtm_task = rtm_input + '\n'
- # print rtm_task
- # f = open(rtm_task_file, "a")
- # f.write(rtm_task)
- # f.close()
- # g = open(rtm_task_file)
- # h = g.read()
- # print h
- #Sending the text file
- def send_rtm_task():
- smtpserver.ehlo()
- smtpserver.starttls()
- smtpserver.ehlo()
- smtpserver.login(gmail_user, gmail_pwd)
- header = 'To: ' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:ps-study'+'\n'
- print header
- msg = header + '\n ' + get_text + '\n\n'
- smtpserver.sendmail(gmail_user, to, msg)
- os.system("xcowsay 'Your RTM task has been sent to' " + to)
- smtpserver.close()
- rtm_task_txt()
- #Grab contents of RTM tasks from text file
- fileHandle = open(rtm_task_file)
- get_text = fileHandle.read()
- print get_text
- header = 'To: ' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:ps-study \n'
- print header
- msg = header + "\n " + get_text + '\n\n'
- print msg
- #"while" dialog so I can keep on adding tasks
- running = True
- while running:
- dialog = int(input("""Would you like to add another task?
- 1. Yes, feed me more work! (nom nom nom nom)
- 2. No, if I have even one more task I'll explode.
- """))
- if dialog == 1:
- rtm_task_txt()
- elif dialog == 2:
- send_rtm_task()
- running = False
- else:
- print get_text
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement