Ejemplo n.º 1
0
    def __init__(self, webfinger, alias=None, app=None):
        self.app = app

        if not webfinger:
            self.webfinger = raw_input(
                'Enter webfinger ([email protected]) for your %s account: ' %
                alias)
        else:
            self.webfinger = webfinger

        self.cfg = self.app.cfg.get(self.webfinger, {})

        client = Client(webfinger=self.webfinger,
                        type='native',
                        name=self.app.name,
                        key=self.cfg.get('key'),
                        secret=self.cfg.get('secret'))

        self.pump = PyPump(client=client,
                           verifier_callback=self.verifier,
                           token=self.cfg.get('token'),
                           secret=self.cfg.get('token_secret'))

        self.key, self.secret, self.expiry = self.pump.get_registration()
        self.token, self.token_secret = self.pump.get_token()
        self.write_config()

        self.get_following()
        self.backup_following()
        self.app.say('%s: account ready (following %s contacts)\n----' %
                     (self.webfinger, len(self.following)))
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        self.__oauth_testing = {
            'request': {
                'token': 'RequestToken',
                'token_secret': 'RequestTokenSecret',
            },
            'access': {
                'token': 'AccessToken',
                'token_secret': 'AccessTokenSecret',
            },
            'verifier': 'AVerifier',
        }

        # most of the time we don't want to go through oauth
        self.client = Client(webfinger="*****@*****.**",
                             key="AKey",
                             secret="ASecret",
                             name="PumpTest",
                             type="native")

        new_kwargs = dict(client=self.client, )

        self._response = kwargs.pop("response")
        self._testcase = kwargs.pop("testcase")

        new_kwargs.update(kwargs)

        super(TestMixin, self).__init__(*args, **new_kwargs)
Ejemplo n.º 3
0
    def pump_login(self):
        print 'Logging into the Pump server...'

        username = self._parser.get('pump', 'username')
        key = self._parser.get('pump', 'key')
        secret = self._parser.get('pump', 'secret')
        token = self._parser.get('pump', 'token')
        token_secret = self._parser.get('pump', 'token_secret')

        client = Client(webfinger=username,
                        name="Pump.io",
                        type="native",
                        key=key,
                        secret=secret)

        pump = PyPump(client=client, verifier_callback=simple_verifier)

        pump.store["oauth-access-token"] = token
        pump.store["oauth-access-secret"] = token_secret

        me = pump.Person(username)

        self._username = username
        self._pump = pump
        self._me = me
Ejemplo n.º 4
0
    def test_client_update(self):
        """ Tests that a client can be updated """
        # First make the client which we'll update
        client = Client(webfinger="*****@*****.**", type="web")

        client.set_pump(self.pump)
        client.register()

        # Now try and update the client
        client.type = "native"
        client.update()

        self.assertEqual(self.request["type"], "client_update")
        self.assertEqual(self.request["application_type"], "native")
Ejemplo n.º 5
0
    def test_minimal_client_registeration(self):
        """ Test client registeration with minimal amount of data """
        client = Client(
            webfinger="*****@*****.**",
            type="native",
        )

        client.set_pump(self.pump)
        client.register()

        # Check we're registering a new client and sent correct data
        self.assertEqual(self.request["type"], "client_associate")
        self.assertEqual(self.request["application_type"], "native")

        # Check we got back the key, secret and expirey correctly
        self.assertEqual(client.key, self.response.data["client_id"])
        self.assertEqual(client.secret, self.response.data["client_secret"])
        self.assertEqual(client.expirey, self.response.data["expires_at"])
Ejemplo n.º 6
0
    def __init__(self):
        """ Init app and log in to our pump.io account """

        # Set up argparse
        self.parser = argparse.ArgumentParser(
            description='Post a note to the pump.io network')
        self.parser.add_argument('-u',
                                 '--user',
                                 dest='webfinger',
                                 required=True,
                                 help='*****@*****.**')
        self.parser.add_argument('-t',
                                 '--title',
                                 dest='note_title',
                                 default=None,
                                 help='Note title')
        self.parser.add_argument('-n',
                                 '--note',
                                 dest='note_content',
                                 required=True,
                                 help='Note content')
        self.args = self.parser.parse_args()

        self.read_config()

        # Try to login to our pump.io account using account credentials
        # from config, if our webfinger is not found in config we will
        # have to authorize the app with our account.
        webfinger = self.args.webfinger

        client = Client(
            webfinger=webfinger,
            type='native',
            name=self.client_name,
            key=self.config.get(webfinger, {}).get('key'),
            secret=self.config.get(webfinger, {}).get('secret'),
        )

        self.pump = PyPump(
            client=client,
            token=self.config.get(webfinger, {}).get('token'),
            secret=self.config.get(webfinger, {}).get('token_secret'),
            verifier_callback=self.verifier,
        )

        # Add account credentials to config in case we didnt have it already
        self.config[webfinger] = {
            'key': self.pump.get_registration()[0],
            'secret': self.pump.get_registration()[1],
            'token': self.pump.get_token()[0],
            'token_secret': self.pump.get_token()[1],
        }

        self.write_config()
Ejemplo n.º 7
0
 def __init__(self,
              site,
              conf,
              bearer_token=None,
              get_token=False,
              streaming=False,
              upload=False):
     self.site = site.lower()
     self.conf = conf[site.upper()]
     # Identi.ca service only supported for commands "ping" and "microblog"
     if self.site == "identica":
         self.domain = "identi.ca"
         # New Pump.io Identi.ca connection:
         self.user = "******" % (self.conf['USER'].lower(), self.domain)
         from gazouilleur.identica_auth_config import identica_auth
         self.conf.update(identica_auth[self.conf['USER'].lower()])
         iclient = Client(webfinger=self.user,
                          type="native",
                          name="Gazouilleur",
                          key=self.conf['key'],
                          secret=self.conf['secret'])
         self.conn = PyPump(client=iclient,
                            token=self.conf['token'],
                            secret=self.conf['token_secret'],
                            verifier_callback=lambda: "")
     elif self.site == "twitter":
         self.domain = "api.twitter.com"
         self.user = self.conf['USER']
         self.post = 'FORBID_POST' not in conf['TWITTER'] or str(
             conf['TWITTER']['FORBID_POST']).lower() != "true"
         args = {"api_version": self.twitter_api_version, "secure": True}
         format = "json"
         if get_token:
             format = ""
             args["api_version"] = None
             args["auth"] = OAuth2(self.conf['KEY'], self.conf['SECRET'])
         elif bearer_token:
             args["auth"] = OAuth2(bearer_token=bearer_token)
         else:
             args["auth"] = OAuth(self.conf['OAUTH_TOKEN'],
                                  self.conf['OAUTH_SECRET'],
                                  self.conf['KEY'], self.conf['SECRET'])
         if streaming:
             self.domain = "stream.twitter.com"
             args['block'] = False
             args['timeout'] = 10
             conn = TwitterStream
         else:
             if upload:
                 self.domain = "upload.twitter.com"
             args['format'] = format
             conn = Twitter
         args['domain'] = self.domain
         self.conn = conn(**args)
Ejemplo n.º 8
0
    def test_full_client_registration(self):
        """ Test a full client registration can take place """
        logo = "https://a.website.com/some_picture.png"
        contacts = ["*****@*****.**", "*****@*****.**"]

        client = Client(
            webfinger="*****@*****.**",
            name="PyPumpTestClient",
            type="web",
            logo=logo,
            contacts=contacts
        )

        client.set_pump(self.pump)
        client.register()

        # Check data was sent correctly
        self.assertEqual(self.request["type"], "client_associate")
        self.assertEqual(self.request["logo_url"], logo)
        self.assertEqual(self.request["contacts"], " ".join(contacts))

        # Check we get back what we should
        self.assertEqual(self.response.data["client_id"], client.key)
        self.assertEqual(self.response.data["client_secret"], client.secret)
        self.assertEqual(self.response.data["expires_at"], client.expirey)
Ejemplo n.º 9
0
    def pump_login(self):
        print 'Logging into the Pump server...'

        username = self._parser.get('pump', 'username')

        client = Client(webfinger=username, name="Pump.io", type="native")

        try:
            pump = PyPump(client=client, verifier_callback=simple_verifier)
        except ConnectionError, e:
            domain = username.split('@')[1]
            print 'Error: Unable to connect to ' + domain + '.'
            print e
            sys.exit()
Ejemplo n.º 10
0
    def test_client_update(self):
        """ Tests that a client can be updated """
        # First make the client which we'll update
        client = Client(
            webfinger="*****@*****.**",
            type="web"
        )

        client.set_pump(self.pump)
        client.register()

        # Now try and update the client
        client.type = "native"
        client.update()

        self.assertEqual(self.request["type"], "client_update")
        self.assertEqual(self.request["application_type"], "native")
Ejemplo n.º 11
0
    def CreatePumpClient(self, webfinger, client_credentials, client_tokens):
        client = Client(
            webfinger=self.webfinger,
            type="native",
            name="NavierStokes",
            key=client_credentials[0],
            secret=client_credentials[1],
        )

        pump = PyPump(
            client=client,
            token=client_tokens[0],  # the token
            secret=client_tokens[1],  # the token secret
            verifier_callback=self.simple_verifier)

        return pump
Ejemplo n.º 12
0
    def test_minimal_client_registeration(self):
        """ Test client registeration with minimal amount of data """
        client = Client(
            webfinger="*****@*****.**",
            type="native",
        )

        client.set_pump(self.pump)
        client.register()

        # Check we're registering a new client and sent correct data
        self.assertEqual(self.request["type"], "client_associate")
        self.assertEqual(self.request["application_type"], "native")

        # Check we got back the key, secret and expirey correctly
        self.assertEqual(client.key, self.response.data["client_id"])
        self.assertEqual(client.secret, self.response.data["client_secret"])
        self.assertEqual(client.expirey, self.response.data["expires_at"])
Ejemplo n.º 13
0
    def pump_login(self):
        print('Logging into the Pump server...')

        username = self._parser.get('pump', 'username')

        client = Client(webfinger=username, name="Pump.io", type="native")

        try:
            pump = PyPump(client=client, verifier_callback=simple_verifier)
        except ConnectionError as e:
            domain = username.split('@')[1]
            print('Error: Unable to connect to ' + domain + '.')
            print(e)
            sys.exit()
        except ClientException:
            domain = username.split('@')[1]
            print('Error: Pump server not found at ' + domain + '.')
            sys.exit()

        me = pump.Person(username)

        self._username = username
        self._pump = pump
        self._me = me
Ejemplo n.º 14
0
    _, _, exc_traceback = sys.exc_info()
    sys.stderr.write("ERROR: Could not read `gazouilleur/config.py`.\nERROR: Please edit it to fix the following syntax issue:\nERROR: %s\n%s\n" % (e, "\n".join(traceback.format_exc().splitlines()[-3:-1])))
    exit(1)

def verifier(url):
    print url
    return raw_input('Paste here the "Verifier" value given in Identi.ca\'s "Authorization Complete" page: ')

confs = []
for chan, conf in config.CHANNELS.iteritems():
    if 'IDENTICA' in conf and 'USER' in conf['IDENTICA']:
        user = conf['IDENTICA']['USER'].lower()
        print "Configuring Identi.ca OAuth for @%s for channel %s..." % (user, chan)
        print "Please make sure to be not logged in on Identi.ca with another account than this one in your browser before clicking the authorize url."
        try:
            client = Client(webfinger="*****@*****.**" % user, type="native", name="Gazouilleur")
            pump = PyPump(client=client, verifier_callback=verifier)
            client_credentials = pump.get_registration()
            client_tokens = pump.get_token()
            confs.append('"%s": {"key": "%s", "secret": "%s", "token": "%s", "token_secret": "%s"}' % (user, client_credentials[0], client_credentials[1], client_tokens[0], client_tokens[1]))
        except Exception as e:
            print "Could not properly get Identi.ca OAuth credits for user @%s:" % user
            print e

if confs:
    with open('gazouilleur/identica_auth_config.py', 'w') as conf_file:
        conf_file.write("""#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file was generated automatically by `python bin/auth_identica.py` on %s
# Do not modify unless you are sure of what you are doing.
identica_auth={%s}""" % (datetime.datetime.today(), ", ".join(confs)))
Ejemplo n.º 15
0
"""
client_credentials = [secret, password]
client_tokens = ['puppies',
                 'kittens']  # These don't go anywhere, but steve had them
webfinger = "*****@*****.**"  # Webfinger for your account


def simple_verifier(url):
    print('Go to: ' + url)
    return input('Verifier: ')  # they will get a code back


client = Client(
    webfinger,
    name="CornerBot",
    type="native",
    key=client_credentials[0],  # client key
    secret=client_credentials[1]  # client secret
)
pump = PyPump(client=client, verifier_callback=simple_verifier)

b_set = set()  # the B set is TODAYS postings

# logfile_name = "cornerbot.activity.log"
# process_log = open(logfile_name,'a+')
# process_log.write(blah)

while 99 == 99:
    listing = ""
    header = ""
    print("\n\nInitiating\n\n")
Ejemplo n.º 16
0
#!/usr/bin/env python
#  Copyright 2014, Stephen Jacob Sekula
# http://polari.us/dokuwiki/doku.php?id=navierstokes#a_simple_program_to_authenticate_pypump_against_your_pumpio_instance
# modified to take arguements, and work with python3

from pypump import PyPump, Client
import sys
"""
arg 1 webfinger
arg 2 client name
"""
client = Client(
    webfinger=sys.argv[1],
    type="native",  # Can be "native" or "web"
    name=sys.argv[2])


def simple_verifier(url):
    print('Go to: ' + url)
    return input('Verifier: ')  # they will get a code back


pump = PyPump(client=client, verifier_callback=simple_verifier)

print(pump.client.key + ': key')
print(pump.client.secret + ': secret')
print('Get the Token + Verification from the browser')