This repository was archived by the owner on Aug 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Refactor update_package_manager_data method #143
Open
Deborah-Digges
wants to merge
1
commit into
sendgrid:master
Choose a base branch
from
Deborah-Digges:issue-106
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 For example, there might be a 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.