-
Notifications
You must be signed in to change notification settings - Fork 1
Bug: Get article version file list using article version files endpoint #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HafeezOJ
wants to merge
5
commits into
main
Choose a base branch
from
128-bug-only-the-first-10-files-are-retrieved-in-datasets-with-more-than-10-files
base: main
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 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dd99953
Get article version files with version files endpoint
HafeezOJ e7807d9
Remove dead code
HafeezOJ 5edd736
Handle potential error in the exception
HafeezOJ 70a8e95
Move page initialization out of loop
HafeezOJ cb80a63
Move page size out of loop
HafeezOJ 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 |
|---|---|---|
|
|
@@ -439,6 +439,44 @@ def set_version_metadata(self, version_data, files, private_version_no, version_ | |
| } | ||
| } | ||
|
|
||
| """ | ||
| Fetch article version files list, even if version files are private. | ||
| :param article_id int value. | ||
| :param version int value. | ||
| """ | ||
| def get_article_version_files(self, article_id: int, version: int): | ||
| success = False | ||
| retries = 1 | ||
| while not success and retries <= self.retries: | ||
| page = 1 | ||
| try: | ||
| page_size = 100 | ||
| page_empty = False | ||
| header = {'Authorization': 'token ' + self.api_token} | ||
| article_version_files_api = self.api_endpoint + "/articles/{0}/versions/{1}/files".format(article_id, version) | ||
| article_version_files = [] | ||
| while not page_empty: | ||
| params = {'page': page, 'page_size': page_size} | ||
| get_response = requests.get(article_version_files_api, headers=header, params=params, timeout=self.retry_wait) | ||
| if get_response.status_code == 200: | ||
| if len(get_response.json()) > 0: | ||
| article_version_files += get_response.json() | ||
| page += 1 | ||
| else: | ||
| page_empty = True | ||
| success = True | ||
| else: | ||
| retries = self.retries_if_error(f"{article_id} Public API not reachable. Retry {retries}", | ||
| get_response.status_code, retries) | ||
| if retries > self.retries: | ||
| break | ||
| return article_version_files | ||
| except requests.exceptions.RequestException as e: | ||
| error_code = get_response.status_code if 'get_response' in locals() else 500 | ||
| retries = self.retries_if_error(f"{e}. Retry {retries}", error_code, retries) | ||
| if retries > self.retries: | ||
| break | ||
|
Comment on lines
+477
to
+478
Collaborator
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. If the max number of retries are exceeded, this code will break out of the outer loop and the function returns nothing. Is that right? |
||
|
|
||
| def private_article_for_files(self, version_data): | ||
| get_response = requests.get(version_data['url_private_api'], | ||
| headers={'Authorization': 'token ' + self.api_token}, | ||
|
|
@@ -965,9 +1003,10 @@ def __final_process(self, check_files, copy_files, check_dir, version_data, fold | |
| success = success & self.__save_json_in_metadata(version_data, folder_name) | ||
|
|
||
| if check_files and copy_files: | ||
| article_version_files = self.get_article_version_files(int(version_data['id']), int(version_data['version'])) | ||
| try: | ||
| # download all files and verify hash with downloaded file. | ||
| delete_now = self.__download_files(version_data['files'], version_data, folder_name) | ||
| delete_now = self.__download_files(article_version_files, version_data, folder_name) | ||
| except Exception as e: | ||
| self.logs.write_log_in_file("error", f"{str(e)} for {'_'.join(os.path.basename(folder_name).split('_')[0:-1])}" , True) | ||
| if self.system_config['continue-on-error'] == "False": | ||
|
|
||
Oops, something went wrong.
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.
Does this mean that if the max number of retries are exceeded, the code will return a partial list of article_version_files?