Advertisement
Guest User

Untitled

a guest
Jun 10th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. import poplib
  2. from subprocess import call
  3. import os
  4.  
  5. class Pop:
  6. def __init__(self, user, password):
  7. self.user = user
  8. self.password = password
  9. self.pop_conn = poplib.POP3_SSL('pop.gmail.com')
  10. self._connect()
  11. self.email = \
  12. [self.pop_conn.retr(i) \
  13. for i in range(1, len(self.pop_conn.list()[1]) + 1)]
  14. self.message = []
  15. if self.email:
  16. self.message = self.email[0][1][-3].decode("utf-8")
  17.  
  18. def _connect(self):
  19. if b'OK' not in self.pop_conn.user(self.user):
  20. print('Error user')
  21. if b'OK' not in self.pop_conn.pass_(self.password):
  22. print('Error pass')
  23.  
  24. def end(self):
  25. self.pop_conn.quit()
  26. exit()
  27.  
  28. p = Pop('DESKTOP-EMAIL@gmail.com', 'PASSWORD')
  29.  
  30.  
  31. if p.message:
  32. command = p.message.lower().split()
  33. print('Command is', command)
  34.  
  35. try:
  36. if 'v' == command[0] or 'volume' in command[0]:
  37. vol_amount = int(command[1])
  38. #call(["amixer", "sset", "'Master'", "%d%".format(vol_amount)])
  39. text = "amixer sset 'Master' %d" % vol_amount
  40. text = text + '%'
  41. os.system(text)
  42. elif 'lights' == command[0]:
  43. import phue_lights
  44. if command[1] == 'on':
  45. phue_lights.turn_on_all_lights()
  46. else:
  47. phue_lights.turn_off_all_lights()
  48. elif 'play' in command[0]:
  49. command = command[1:]
  50. cmd = 'play $(find /home/jordan/storage/music/ | '
  51. for each in command:
  52. cmd = cmd + 'grep -i "' + each + '" | '
  53. cmd = cmd + 'grep mp3 | sort) &'
  54. #print(cmd)
  55. os.system(cmd)
  56. elif 'kill' in command[0]:
  57. cmd = 'pkill ' + command[1]
  58. os.system(cmd)
  59. elif 'turn off the music' in ' '.join(command):
  60. os.system('pkill play')
  61. else:
  62. print('Command not found')
  63. except:
  64. print('Fuck')
  65. pass
  66.  
  67. p.end()
  68.  
  69.  
  70.  
  71. #def delete_messages(pop_conn):
  72. # poplist = pop_conn.list()
  73. # if poplist[0].startswith(b'+OK') :
  74. # msglist = poplist[1]
  75. # for msgspec in msglist :
  76. # msgnum = int(msgspec.split(b' ')[0])
  77. # pop_conn.dele(msgnum)
  78.  
  79.  
  80. #delete_messages(pop_conn)
  81. from IPython import embed; embed()
  82.  
  83.  
  84. # Concat message pieces:
  85. #messages = ["\n".join(mssg[1]) for mssg in messages]
  86. #Parse message intom an email object:
  87. #messages = [parser.Parser().parsestr(mssg) for mssg in messages]
  88.  
  89. #for message in messages:
  90. # print(message['subject'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement