Advertisement
clockworkpc

Send Tasks via Geany and Gmail to RTM

Mar 19th, 2012
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. #!/usr/bin/python
  2. #/home/cpcmonster/bin/rtmsimple.py
  3.  
  4. # Released under a GPLv3 Licence by Clockwork PC 2011
  5. # www.clockworkpc.com.au
  6.  
  7. # You are entitled to the following four freedoms:
  8. # Freedom 0: To run this program for any purpose
  9. # Freedom 1: To study how this program works and change it to make it do what you wish
  10. # Freedom 2: To redistribute copies so you can help your neighbour
  11. # Freedom 3: To distribute copies of your modified version to others
  12.  
  13. import os
  14. import smtplib
  15. import subprocess
  16. from time import gmtime, strftime
  17.  
  18. #Where the task file will go
  19.  
  20. os.system("mkdir -pv ~/Documents/rtm_tasks")
  21. task_path_name = os.getenv("HOME")+"/Documents/rtm_tasks/"
  22. print task_path_name
  23. current_time = strftime("%Y-%m-%d_%H%M%S", gmtime())
  24. rtm_task_file = task_path_name + "rtm_tasks_" + current_time + ".txt"
  25. print current_time
  26. print rtm_task_file
  27.  
  28. #Defining what I need in order to open and edit the text file to be used later
  29. geany = '/usr/bin/geany'
  30. proc1 = subprocess.Popen([geany,rtm_task_file])
  31.  
  32. #The easiest way to create an empty to file to populate later (Don't need it anymore, now that I finally understand Popen)
  33. #os.system ("touch " + rtm_task_file)
  34.  
  35. #Gmail Login Credentials
  36. to = '{RTM_Import_Address}'
  37. gmail_user = "{Gmail Address}"
  38. gmail_pwd = "{Password}"
  39. smtpserver = smtplib.SMTP("smtp.gmail.com",587)
  40.  
  41. #Write to the task file and wait for it to close
  42. def rtm_task_txt():
  43. proc1.wait()
  44. print "OK, let's send this on to rememberthemilk.com via my gmail"
  45.  
  46.  
  47. #Creating a text file for RTM tasks
  48. #def rtm_task_txt():
  49. # rtm_input = raw_input("What is the task? ")
  50. # rtm_task = rtm_input + '\n'
  51. # print rtm_task
  52. # f = open(rtm_task_file, "a")
  53. # f.write(rtm_task)
  54. # f.close()
  55. # g = open(rtm_task_file)
  56. # h = g.read()
  57. # print h
  58.  
  59. #Sending the text file
  60. def send_rtm_task():
  61. smtpserver.ehlo()
  62. smtpserver.starttls()
  63. smtpserver.ehlo()
  64. smtpserver.login(gmail_user, gmail_pwd)
  65. header = 'To: ' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:ps-study'+'\n'
  66. print header
  67. msg = header + '\n ' + get_text + '\n\n'
  68.  
  69. smtpserver.sendmail(gmail_user, to, msg)
  70. os.system("xcowsay 'Your RTM task has been sent to' " + to)
  71. smtpserver.close()
  72.  
  73. rtm_task_txt()
  74.  
  75. #Grab contents of RTM tasks from text file
  76. fileHandle = open(rtm_task_file)
  77. get_text = fileHandle.read()
  78. print get_text
  79.  
  80. header = 'To: ' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:ps-study \n'
  81. print header
  82. msg = header + "\n " + get_text + '\n\n'
  83. print msg
  84.  
  85. #"while" dialog so I can keep on adding tasks
  86.  
  87. running = True
  88. while running:
  89. dialog = int(input("""Would you like to add another task?
  90.  
  91. 1. Yes, feed me more work! (nom nom nom nom)
  92. 2. No, if I have even one more task I'll explode.
  93.  
  94. """))
  95. if dialog == 1:
  96. rtm_task_txt()
  97. elif dialog == 2:
  98. send_rtm_task()
  99. running = False
  100. else:
  101. print get_text
  102.  
  103. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement