Example #1
0
def _get_conn(environ_str):
    try:
        if(environ_str == 'DB_URL'):
            originalURLString = os.environ[environ_str]
            "postgres://*****:*****@afflus-coinapi.c7sua8w1mckc.ap-northeast-2.rds.amazonaws.com:5432"
            #"postgres://*****:*****@exchanges-cluster.cluster-civby46zvtth.us-east-2.rds.amazonaws.com:5432/exchanges"
            rest,path = originalURLString.split('//')[1].split('/')
            username, rest, port = rest.split(':')
            password, hostname = rest.split('@')
            import pdb; pdb.set_trace()
            #print(path,username,password,hostname,port)
            return psycopg2.connect(
                #database=path,
                user=username,
                password=password,
                host=hostname,
                port=port
            )
        else:
            url = urlparser(os.environ[environ_str])
        return psycopg2.connect(
            database=url.path[1:],
            user=url.username,
            password=url.password,
            host=url.hostname,
            port=url.port
        )
    except Exception as e:
        print(e)
        return None
Example #2
0
 def _get_domain(self, url):
     if url.startswith('http'):
         parsed = urlparser(url)
         return parsed.netloc
     else:
         print('URL must start with scheme (http / https)')
         self.logger.warning('URL must start with scheme (http / https)')
         return
Example #3
0
def _get_conn(environ_str):
    try:
        url = urlparser(environ_str)
        return psycopg2.connect(database=url.path[1:],
                                user=url.username,
                                password=url.password,
                                host=url.hostname,
                                port=url.port)
    except:
        return None
Example #4
0
    def _get_domain(self):
        '''Extracts domain name from the URL.'''
        self.logger.info('Getting domain ...')
        parsed = urlparser(self.url)
        if parsed.netloc:
            domain = parsed.netloc
        else:
            self.logger.warning('URL must start with scheme (http / https).')
            url = '//{0}'.format(self.url)
            parsed = urlparser(url)
            domain = parsed.netloc
            if not domain:
                self.logger.error(
                    'Error while parsing the URL. Check the format.')
                return

        self.logger.info('Domain: {0}'.format(domain))
        print(domain)
        return domain
Example #5
0
 def _get_domain(self, url):
     '''Extracts domain name from the URL.'''
     self.logger.info('Getting domain ...')
     if url.startswith('http'):
         parsed = urlparser(url)
         domain = parsed.netloc
         self.logger.info('Domain: {0}'.format(domain))
         return domain
     else:
         self.logger.warning('URL must start with scheme (http / https)')
         return
Example #6
0
def _get_conn(environ_str):
    try:
        if (environ_str == 'EXCHANGES_DATABASE_URL_AWS_DEV'):
            originalURLString = os.environ[environ_str]
            rest, path = originalURLString.split('//')[1].split('/')
            username, rest, port = rest.split(':')
            password, hostname = rest.split('@')

            return psycopg2.connect(database=path,
                                    user=username,
                                    password=password,
                                    host=hostname,
                                    port=port)
        else:
            url = urlparser(os.environ[environ_str])
        return psycopg2.connect(database=url.path[1:],
                                user=url.username,
                                password=url.password,
                                host=url.hostname,
                                port=url.port)
    except Exception as e:
        print(e)
        return None
Example #7
0
def _get_conn(environ_str):
    try:
        if (environ_str == 'EXCHANGES_DATABASE_URL_AWS_DEV'):
            originalURLString = os.environ[environ_str]
            "postgres://*****:*****@exchanges-cluster.cluster-civby46zvtth.us-east-2.rds.amazonaws.com:5432/exchanges"
            rest, path = originalURLString.split('//')[1].split('/')
            username, rest, port = rest.split(':')
            password, hostname = rest.split('@')
            #print(path,username,password,hostname,port)
            return psycopg2.connect(database=path,
                                    user=username,
                                    password=password,
                                    host=hostname,
                                    port=port)
        else:
            url = urlparser(os.environ[environ_str])
        return psycopg2.connect(database=url.path[1:],
                                user=url.username,
                                password=url.password,
                                host=url.hostname,
                                port=url.port)
    except Exception as e:
        print(e)
        return None