(self)
Update providers from IP addresses, when enpty
Update providers from IP addresses, when enpty
Update providers from IP addresses when enpty
def updateProviders(self):
        """Update providers from IP addresses, when enpty"""
        import requests
        query = "select distinct(ip) from connections where provider is null;"
        cursor = self.conn.execute(query)
        updates = []

        for row in cursor:
            ip = row[0]
            provider = requests.get('http://ip-api.com/line/{}?fields=isp'
                                    .format(ip)).text.replace("\n", "")
            update = {}
            update['query'] = "update connections set provider=? where ip=?"
            if provider != "":
                update['columns'] = (provider, ip)
            else:
                update['columns'] = ('unknown', ip)
            updates.append(update)
            # Sleep one second to avoid being blacklisted by the server
            time.sleep(1)

        try:
            writeCursor = self.conn.cursor()
            for update in updates:
                writeCursor.execute(update['query'], update['columns'])
            self.conn.commit()
        except Exception:
            raise DatabaseAccessError("Could not open the database '{}' for writing"
                                      .format(self.connLogFile))
def updateProviders ( self ) : import requests query = "select distinct(ip) from connections where provider is null;" cursor = self . conn . execute ( query ) updates = [ ] for row in cursor : ip = row [ 0 ] provider = requests . get ( 'http://ip-api.com/line/{}?fields=isp' . format ( ip ) ) . text . replace ( "\n" , "" ) update = { } update [ 'query' ] = "update connections set provider=? where ip=?" if provider != "" : update [ 'columns' ] = ( provider , ip ) else : update [ 'columns' ] = ( 'unknown' , ip ) updates . append ( update ) # Sleep one second to avoid being blacklisted by the server time . sleep ( 1 ) try : writeCursor = self . conn . cursor ( ) for update in updates : writeCursor . execute ( update [ 'query' ] , update [ 'columns' ] ) self . conn . commit ( ) except Exception : raise DatabaseAccessError ( "Could not open the database '{}' for writing" . format ( self . connLogFile ) )