Skip to content
This repository was archived by the owner on Aug 28, 2020. It is now read-only.

Refactor update_package_manager_data method #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 61 additions & 46 deletions package_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is indented 4 spaces too far.

if 'https://www.nuget.org/packages/SendGrid.CSharp.HTTP.Client' == url:
Copy link

@42B 42B Oct 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why you wouldn't change some of these to elif statements? If url == 'https://www.nuget.org/packages/SendGrid', it couldn't also be equal to 'https://www.nuget.org/packages/SendGrid.CSharp.HTTP.Client'. All of the checks using == would be prime candidates but some of the if statements which use in would have to be thought about more.

For example, there might be a url which satisfies both of these checks:

        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)

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
Expand Down