diff --git a/package_managers.py b/package_managers.py index d8e99f9..2419f40 100644 --- a/package_managers.py +++ b/package_managers.py @@ -30,53 +30,68 @@ def update_package_manager_data(self, package_manager_urls): :returns: Returns the data object that was added to the DB :rtype: Data object """ - num_total_csharp_downloads = None - num_nodejs_monthly_downloads = None - num_php_downloads = None - num_python_downloads = None - num_ruby_downloads = None - num_python_http_client_downloads = None - num_python_open_source_library_data_collector_downloads = None - num_ruby_http_client_downloads = None - num_csharp_http_client_downloads = None - num_php_http_client_downloads = None - num_node_http_client_downloads = None + data = { + "num_total_csharp_downloads": None, + "num_nodejs_monthly_downloads": None, + "num_php_downloads": None, + "num_python_downloads": None, + "num_ruby_downloads": None, + "num_python_http_client_downloads": None, + "num_python_open_source_library_data_collector_downloads": None, + "num_ruby_http_client_downloads": None, + "num_csharp_http_client_downloads": None, + "num_php_http_client_downloads": None, + "num_node_http_client_downloads": None + } + for url in package_manager_urls: - if 'https://www.nuget.org/packages/SendGrid' == url: - num_total_csharp_downloads = self.csharp_downloads(url) - if 'https://www.nuget.org/packages/SendGrid.CSharp.HTTP.Client' == url: - num_csharp_http_client_downloads = self.csharp_downloads(url) - if 'https://www.npmjs.com/package/sendgrid' in url: - if 'https://www.npmjs.com/package/sendgrid-rest' != url: - num_nodejs_monthly_downloads = self.nodejs_downloads(url) - if 'https://www.npmjs.com/package/sendgrid-rest' in url: - num_node_http_client_downloads = self.nodejs_downloads(url) - if 'https://packagist.org/packages/sendgrid/sendgrid' == url: - num_php_downloads = self.php_downloads(url) - if 'https://packagist.org/packages/sendgrid/php-http-client' == url: - num_php_http_client_downloads = self.php_downloads(url) - if 'pypi' in url and 'sendgrid' in url: - num_python_downloads = self.python_downloads(url) - if 'pypi' in url and 'python_http_client' in url: - num_python_http_client_downloads = self.python_downloads(url) - if 'pypi' in url and 'open_source_library_data_collector' in url: - num_python_open_source_library_data_collector_downloads = self.python_downloads(url) - if 'rubygems' in url and 'sendgrid' in url: - num_ruby_downloads = self.ruby_downloads(url) - if 'rubygems' in url and 'http' in url: - num_ruby_http_client_downloads = self.ruby_downloads(url) - - return self.update_db(num_total_csharp_downloads, - num_nodejs_monthly_downloads, - num_php_downloads, - num_python_downloads, - num_ruby_downloads, - num_python_http_client_downloads, - num_python_open_source_library_data_collector_downloads, - num_ruby_http_client_downloads, - num_csharp_http_client_downloads, - num_php_http_client_downloads, - num_node_http_client_downloads) + self.update_data_object(url, data) + + return self.update_db(data["num_total_csharp_downloads"], + data["num_nodejs_monthly_downloads"], + data["num_php_downloads"], + data["num_python_downloads"], + data["num_ruby_downloads"], + data["num_python_http_client_downloads"], + data["num_python_open_source_library_data_collector_downloads"], + data["num_ruby_http_client_downloads"], + data["num_csharp_http_client_downloads"], + data["num_php_http_client_downloads"], + data["num_node_http_client_downloads"]) + + def update_data_object(self, url, data): + """Updates the data object with the counts of downloaded objects. + + :param url: The URL of the package manager + :type url: string + + :param data: The data object to be populated + :type data: dict + + """ + if 'https://www.nuget.org/packages/SendGrid' == url: + data["num_total_csharp_downloads"] = self.csharp_downloads(url) + if 'https://www.nuget.org/packages/SendGrid.CSharp.HTTP.Client' == url: + data["num_csharp_http_client_downloads"] = self.csharp_downloads(url) + if 'https://www.npmjs.com/package/sendgrid' in url: + if 'https://www.npmjs.com/package/sendgrid-rest' != url: + data["num_nodejs_monthly_downloads"] = self.nodejs_downloads(url) + if 'https://www.npmjs.com/package/sendgrid-rest' in url: + data["num_node_http_client_downloads"] = self.nodejs_downloads(url) + if 'https://packagist.org/packages/sendgrid/sendgrid' == url: + data["num_php_downloads"] = self.php_downloads(url) + if 'https://packagist.org/packages/sendgrid/php-http-client' == url: + data["num_php_http_client_downloads"] = self.php_downloads(url) + if 'pypi' in url and 'sendgrid' in url: + data["num_python_downloads"] = self.python_downloads(url) + if 'pypi' in url and 'python_http_client' in url: + data["num_python_http_client_downloads"] = self.python_downloads(url) + if 'pypi' in url and 'open_source_library_data_collector' in url: + data["num_python_open_source_library_data_collector_downloads"] = self.python_downloads(url) + if 'rubygems' in url and 'sendgrid' in url: + data["num_ruby_downloads"] = self.ruby_downloads(url) + if 'rubygems' in url and 'http' in url: + data["num_ruby_http_client_downloads"] = self.ruby_downloads(url) def csharp_downloads(self, url): """Gets library download data from nuget.org