예제 #1
0
    def SendMsg(self, Mail):
        '''
        Sent Message to Email.
        '''
        Subject = Mail['Subject']
        To_Email = Mail['To_Email']
        if isinstance(To_Email, str):
            To_Email = To_Email.split(',')
        Message = Mail['Message']
        Message = Message.strip()

        if self.SetupServer():
            self.GetAuthInfo()
            try:
                self.server.login(self.username, self.password)
            except smtplib.SMTPException:
                ui_print(colored('Login Failed', 'red'))
                return 1
            fromAddr = self.username
            for toAddr in To_Email:
                toAddr = toAddr.strip()
                ui_print(
                    colored('Sending mail to {}...'.format(toAddr), 'blue'))
                mail = self.ComposeMail(Subject, toAddr, Message)
                try:
                    self.server.sendmail(fromAddr, toAddr, mail)
                    ui_print(colored('Successfully Sent', 'green'))
                except smtplib.SMTPException:
                    ui_print(colored('Sending Failed', 'red'))
        else:
            raise NetworkError('Unable to access Mail Server')
예제 #2
0
파일: mail.py 프로젝트: alfie-max/Publish
 def SendMsg(self, Mail):
     '''
     Sent Message to Email.
     '''
     Subject = Mail['Subject']
     To_Email = Mail['To_Email']
     if isinstance(To_Email,str):
         To_Email = To_Email.split(',')
     Message = Mail['Message']
     Message = Message.strip()
     
     if self.SetupServer():
         self.GetAuthInfo()
         try:
             self.server.login(self.username, self.password)
         except smtplib.SMTPException:
             ui_print (colored('Login Failed', 'red'))
             return 1
         fromAddr = self.username
         for toAddr in To_Email:
             toAddr = toAddr.strip()
             ui_print(colored('Sending mail to {}...'.format(toAddr), 'blue'))
             mail = self.ComposeMail(Subject, toAddr, Message)
             try:
                 self.server.sendmail(fromAddr, toAddr, mail)
                 ui_print (colored('Successfully Sent', 'green'))
             except smtplib.SMTPException:
                 ui_print (colored('Sending Failed', 'red'))
     else:
         raise NetworkError('Unable to access Mail Server')
예제 #3
0
    def Authorize(self):
        '''
        Authorize the application with Gmail.
        '''
        ui_print(colored('Authorizing Email Account...', 'yellow'))
        self.username = ui_prompt("Username : "******"Password : ", mask=True)
        ''' Update Config file with User login Info '''
        cfg = ConfigParser.RawConfigParser()
        cfg.read(__cfgfile__)
        if not cfg.has_section('Email'):
            cfg.add_section('Email')
        cfg.set('Email', 'Email Id', self.username)
        cfg.set('Email', 'Password', hexlify(self.password))
        with open(__cfgfile__, 'wb') as configfile:
            cfg.write(configfile)

        if not self.VerifyCredentials():
            self.Reset()
            raise AuthorizationError('Authorization Failed')
예제 #4
0
파일: mail.py 프로젝트: alfie-max/Publish
    def Authorize(self):
        '''
        Authorize the application with Gmail.
        '''
        ui_print (colored('Authorizing Email Account...', 'yellow'))
        self.username = ui_prompt("Username : "******"Password : ", mask = True)

        
        ''' Update Config file with User login Info '''
        cfg = ConfigParser.RawConfigParser()
        cfg.read(__cfgfile__)
        if not cfg.has_section('Email'):
            cfg.add_section('Email')
        cfg.set('Email', 'Email Id', self.username)
        cfg.set('Email', 'Password', hexlify(self.password))
        with open(__cfgfile__, 'wb') as configfile:
            cfg.write(configfile)

        if not self.VerifyCredentials():
            self.Reset()
            raise AuthorizationError('Authorization Failed')
예제 #5
0
 def SendMsg(self, msg):
     '''
     Sent Message to Twitter.
     '''
     Message = msg['Message']
     Message = Message.strip()
     
     self.GetAuthInfo()
     auth = tweepy.OAuthHandler(self.CON_KEY, self.CON_SEC)
     auth.set_access_token(self.TOKEN, self.TOKEN_SEC)
     self.api = tweepy.API(auth)
     ui_print (colored('Sending Twitter Message...', 'blue'))
     if self.Tweet(Message):
         ui_print (colored('Successfully Sent', 'green'))
     else:
         ui_print (colored('Sending Failed', 'red'))
예제 #6
0
파일: fb.py 프로젝트: alfie-max/Publish
 def SendMsg(self, msg):
     '''
     Sent Message to Facebook.
     '''
     Message = msg['Message']
     Message = Message.strip()
     
     self.GetAuthInfo()
     fb = facebook.GraphAPI()
     fb.access_token = ACCESS_TOKEN
     ui_print (colored('Sending Facebook Message...', 'blue'))
     try:
         fb.put_wall_post(Message)
         ui_print (colored('Successfully Sent', 'green'))
     except urllib2.URLError:
         raise NetworkError('Unable to access network')
     except facebook.GraphAPIError:
         ui_print (colored('Sending Failed', 'red'))
예제 #7
0
파일: fb.py 프로젝트: syedsuhail/Publish
    def SendMsg(self, msg):
        '''
        Sent Message to Facebook.
        '''
        Message = msg['Message']
        Message = Message.strip()

        self.GetAuthInfo()
        fb = facebook.GraphAPI()
        fb.access_token = ACCESS_TOKEN
        ui_print(colored('Sending Facebook Message...', 'blue'))
        try:
            fb.put_wall_post(Message)
            ui_print(colored('Successfully Sent', 'green'))
        except urllib2.URLError:
            raise NetworkError('Unable to access network')
        except facebook.GraphAPIError:
            ui_print(colored('Sending Failed', 'red'))
예제 #8
0
파일: blog.py 프로젝트: alfie-max/Publish
    def SendMsg(self, Blog):
        '''
        Sent Message to Blog.
        '''
        blogid = ""
        status_published = 1
        title = Blog['Title']
        content = Blog['Message']
        data = {'title': title, 'description': content}
        
        self.GetAuthInfo()
        ui_print (colored('Posting on blog {}...'.format(self.url), 'blue'))
        try:
            server = xmlrpclib.ServerProxy(self.url)
        except xmlrpclib.Error:
            raise NetworkError('Unable to access Server')

        try:
            server.metaWeblog.newPost(blogid, self.username, self.password, data, status_published)
            ui_print (colored('Successfully Posted', 'green'))
        except (xmlrpclib.Fault, gaierror):
            ui_print (colored('Blog Posting Failed', 'red'))
예제 #9
0
    def SendMsg(self, Blog):
        '''
        Sent Message to Blog.
        '''
        blogid = ""
        status_published = 1
        title = Blog['Title']
        content = Blog['Message']
        data = {'title': title, 'description': content}

        self.GetAuthInfo()
        ui_print(colored('Posting on blog {}...'.format(self.url), 'blue'))
        try:
            server = xmlrpclib.ServerProxy(self.url)
        except xmlrpclib.Error:
            raise NetworkError('Unable to access Server')

        try:
            server.metaWeblog.newPost(blogid, self.username, self.password,
                                      data, status_published)
            ui_print(colored('Successfully Posted', 'green'))
        except (xmlrpclib.Fault, gaierror):
            ui_print(colored('Blog Posting Failed', 'red'))
예제 #10
0
파일: fb.py 프로젝트: alfie-max/Publish
    def Authorize(self):
        '''
        Authorize the application with Facebook.
        '''
        global ACCESS_TOKEN
        ACCESS_TOKEN = None
        ENDPOINT = 'graph.facebook.com'
        REDIRECT_URI = 'http://127.0.0.1:8080/'
        
        ''' Requirements for Facebook Authentication '''
        class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
            def do_GET(self):
                self.send_response(200)
                self.send_header('Content-type', 'text/html')
                self.end_headers()
                global ACCESS_TOKEN

                code = urlparse.parse_qs(urlparse.urlparse(self.path).query).get('code')
                code = code[0] if code else None
                if code is None:
                    self.wfile.write('Sorry, authentication failed.')
                    raise AuthorizationError('Authorization Failed')
                response = get('/oauth/access_token',
                               {'client_id' : APP_ID,
                                'redirect_uri' : REDIRECT_URI,
                                'client_secret' : APP_SEC,
                                'code' : code})

                ACCESS_TOKEN = urlparse.parse_qs(response)['access_token'][0]
                self.wfile.write('You have successfully logged in to facebook.'
                                 'You can close this window now.')
            def log_message(self, format, *args):
                return

        def get_url(path, args=None):
            args = args or {}
            if ACCESS_TOKEN:
                args['access_token'] = ACCESS_TOKEN
            if 'access_token' in args or 'client_secret' in args:
                endpoint = "https://" + ENDPOINT
            else:
                endpoint = "http://" + ENDPOINT
            return endpoint + path + '?' + urllib.urlencode(args)

        def get(path, args):
            return urllib2.urlopen(get_url(path, args=args)).read()
        
        ''' Steps to authenticate '''
        ui_print (colored('Authorizing Facebook Account...', 'yellow'))
        auth_url = get_url('/oauth/authorize',
                           {'client_id' : APP_ID,
                            'redirect_uri' : REDIRECT_URI,
                            'scope' : 'publish_actions'})

        ''' Silence webbrowser messages '''
        savout = os.dup(1)
        os.close(1)
        os.open(os.devnull, os.O_RDWR)
        try:
            webbrowser.open(auth_url)
        finally:
            os.dup2(savout, 1)

        httpd = BaseHTTPServer.HTTPServer(('127.0.0.1', 8080), RequestHandler)
        while ACCESS_TOKEN is None:
            httpd.handle_request()

        ''' Update Config file with Token Keys '''
        cfg = ConfigParser.RawConfigParser()
        cfg.read(__cfgfile__)
        if not cfg.has_section('Facebook'):
            cfg.add_section('Facebook')
        cfg.set('Facebook', 'Access Token', hexlify(ACCESS_TOKEN))
        with open(__cfgfile__, 'wb') as configfile:
            cfg.write(configfile)

        if not self.VerifyCredentials():
            self.Reset()
            raise AuthorizationError('Authorization Failed')
예제 #11
0
파일: fb.py 프로젝트: syedsuhail/Publish
    def Authorize(self):
        '''
        Authorize the application with Facebook.
        '''
        global ACCESS_TOKEN
        ACCESS_TOKEN = None
        ENDPOINT = 'graph.facebook.com'
        REDIRECT_URI = 'http://127.0.0.1:8080/'
        ''' Requirements for Facebook Authentication '''
        class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
            def do_GET(self):
                self.send_response(200)
                self.send_header('Content-type', 'text/html')
                self.end_headers()
                global ACCESS_TOKEN

                code = urlparse.parse_qs(urlparse.urlparse(
                    self.path).query).get('code')
                code = code[0] if code else None
                if code is None:
                    self.wfile.write('Sorry, authentication failed.')
                    raise AuthorizationError('Authorization Failed')
                response = get(
                    '/oauth/access_token', {
                        'client_id': APP_ID,
                        'redirect_uri': REDIRECT_URI,
                        'client_secret': APP_SEC,
                        'code': code
                    })

                ACCESS_TOKEN = urlparse.parse_qs(response)['access_token'][0]
                self.wfile.write('You have successfully logged in to facebook.'
                                 'You can close this window now.')

            def log_message(self, format, *args):
                return

        def get_url(path, args=None):
            args = args or {}
            if ACCESS_TOKEN:
                args['access_token'] = ACCESS_TOKEN
            if 'access_token' in args or 'client_secret' in args:
                endpoint = "https://" + ENDPOINT
            else:
                endpoint = "http://" + ENDPOINT
            return endpoint + path + '?' + urllib.urlencode(args)

        def get(path, args):
            return urllib2.urlopen(get_url(path, args=args)).read()

        ''' Steps to authenticate '''
        ui_print(colored('Authorizing Facebook Account...', 'yellow'))
        auth_url = get_url(
            '/oauth/authorize', {
                'client_id': APP_ID,
                'redirect_uri': REDIRECT_URI,
                'scope': 'publish_actions'
            })
        ''' Silence webbrowser messages '''
        savout = os.dup(1)
        os.close(1)
        os.open(os.devnull, os.O_RDWR)
        try:
            webbrowser.open(auth_url)
        finally:
            os.dup2(savout, 1)

        httpd = BaseHTTPServer.HTTPServer(('127.0.0.1', 8080), RequestHandler)
        while ACCESS_TOKEN is None:
            httpd.handle_request()
        ''' Update Config file with Token Keys '''
        cfg = ConfigParser.RawConfigParser()
        cfg.read(__cfgfile__)
        if not cfg.has_section('Facebook'):
            cfg.add_section('Facebook')
        cfg.set('Facebook', 'Access Token', hexlify(ACCESS_TOKEN))
        with open(__cfgfile__, 'wb') as configfile:
            cfg.write(configfile)

        if not self.VerifyCredentials():
            self.Reset()
            raise AuthorizationError('Authorization Failed')
예제 #12
0
    def Authorize(self):
        '''
        Authorize the application with Twitter.
        '''
        auth = tweepy.OAuthHandler(self.CON_KEY, self.CON_SEC)

        try:
            auth_url = auth.get_authorization_url()
        except tweepy.error.TweepError:
            raise NetworkError('Unable to access network')

        ui_print (colored('Authorizing Twitter Account...', 'yellow'))
        username = ui_prompt("Username : "******"Password : ", mask = True)

        ''' Initialize mechanize browser instance '''
        br = Browser()
        cj = cookielib.LWPCookieJar()
        br.set_cookiejar(cj)
        br.set_handle_robots(False)
        br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

        ''' Opens browser and authenticate account '''
        try:
            br.open(auth_url)
        except URLError:
            raise NetworkError('Unable to access network')

        br.form = list(br.forms())[0]
        br.form['session[username_or_email]'] = username
        br.form['session[password]'] = password

        try:
            response = br.submit()
        except URLError:
            br.close()
            raise NetworkError('Unable to access network')

        content = response.get_data()

        soup = BeautifulSoup(content)
        code = soup.find('code')

        if code:
            pin = code.text
            br.close()
        else:
            br.form = list(br.forms())[1]
            try:
                response = br.submit()
            except URLError:
                br.close()
                raise NetworkError('Unable to access network')

            content = response.get_data()
            br.close()
            soup = BeautifulSoup(content)
            code = soup.find('code')
            if code:
                pin = code.text
            else:
                raise AuthorizationError('Authorization Failed')

        try:
            auth.get_access_token(pin)
        except tweepy.error.TweepError, e:
            raise AuthorizationError('Authorization Failed')