Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import poplib
- from subprocess import call
- import os
- class Pop:
- def __init__(self, user, password):
- self.user = user
- self.password = password
- self.pop_conn = poplib.POP3_SSL('pop.gmail.com')
- self._connect()
- self.email = \
- [self.pop_conn.retr(i) \
- for i in range(1, len(self.pop_conn.list()[1]) + 1)]
- self.message = []
- if self.email:
- self.message = self.email[0][1][-3].decode("utf-8")
- def _connect(self):
- if b'OK' not in self.pop_conn.user(self.user):
- print('Error user')
- if b'OK' not in self.pop_conn.pass_(self.password):
- print('Error pass')
- def end(self):
- self.pop_conn.quit()
- exit()
- p = Pop('DESKTOP-EMAIL@gmail.com', 'PASSWORD')
- if p.message:
- command = p.message.lower().split()
- print('Command is', command)
- try:
- if 'v' == command[0] or 'volume' in command[0]:
- vol_amount = int(command[1])
- #call(["amixer", "sset", "'Master'", "%d%".format(vol_amount)])
- text = "amixer sset 'Master' %d" % vol_amount
- text = text + '%'
- os.system(text)
- elif 'lights' == command[0]:
- import phue_lights
- if command[1] == 'on':
- phue_lights.turn_on_all_lights()
- else:
- phue_lights.turn_off_all_lights()
- elif 'play' in command[0]:
- command = command[1:]
- cmd = 'play $(find /home/jordan/storage/music/ | '
- for each in command:
- cmd = cmd + 'grep -i "' + each + '" | '
- cmd = cmd + 'grep mp3 | sort) &'
- #print(cmd)
- os.system(cmd)
- elif 'kill' in command[0]:
- cmd = 'pkill ' + command[1]
- os.system(cmd)
- elif 'turn off the music' in ' '.join(command):
- os.system('pkill play')
- else:
- print('Command not found')
- except:
- print('Fuck')
- pass
- p.end()
- #def delete_messages(pop_conn):
- # poplist = pop_conn.list()
- # if poplist[0].startswith(b'+OK') :
- # msglist = poplist[1]
- # for msgspec in msglist :
- # msgnum = int(msgspec.split(b' ')[0])
- # pop_conn.dele(msgnum)
- #delete_messages(pop_conn)
- from IPython import embed; embed()
- # Concat message pieces:
- #messages = ["\n".join(mssg[1]) for mssg in messages]
- #Parse message intom an email object:
- #messages = [parser.Parser().parsestr(mssg) for mssg in messages]
- #for message in messages:
- # print(message['subject'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement