Skip to content
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

scripts/check-more-info-urls.py: add script #12506

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

vitorhcl
Copy link
Member

@vitorhcl vitorhcl commented Mar 14, 2024

  • The PR title conforms to the recommended templates.

TODO:

@github-actions github-actions bot added documentation Issues/PRs modifying the documentation. tooling Helper tools, scripts and automated processes. labels Mar 14, 2024
@tldr-bot

This comment was marked as outdated.

@tldr-bot

This comment was marked as outdated.

@vitorhcl vitorhcl force-pushed the add-detect-broken-links-script branch from 9b7b17b to 6474534 Compare March 15, 2024 11:53
@tldr-bot

This comment was marked as outdated.

scripts/README.md Outdated Show resolved Hide resolved
@vitorhcl vitorhcl changed the title scripts/detect-broken-more-info-links.py: add script scripts/check-more-info-links.py: add script Apr 3, 2024
@tldr-bot

This comment was marked as outdated.

@kbdharun
Copy link
Member

kbdharun commented Apr 18, 2024

Hi @vitorhcl, Any updates on this?

@vitorhcl
Copy link
Member Author

Hi @kbdharun, thanks for pinging me.

I'm gonna try to do the pending fixes and documentation until Monday, but I'll leave the regex filter for another PR.

@vitorhcl
Copy link
Member Author

The build for this PR failed with the following error(s):

scripts/check-more-info-links.py:4:1: F401 'random' imported but unused
scripts/check-more-info-links.py:7:1: F401 'sys' imported but unused
scripts/check-more-info-links.py:8:1: F401 'aiofile.Reader' imported but unused
scripts/check-more-info-links.py:11:1: F401 'aiofile.async_open' imported but unused
scripts/check-more-info-links.py:55:13: F841 local variable 'e' is assigned to but never used

Please fix the error(s) and push again.

Anyone knows why this is returning an error? Is it because of asynchronous functions?

@tldr-bot

This comment was marked as outdated.

@vitorhcl vitorhcl changed the title scripts/check-more-info-links.py: add script scripts/check-more-info-urls.py: add script Apr 27, 2024
@tldr-bot

This comment was marked as resolved.

@kbdharun
Copy link
Member

kbdharun commented Apr 28, 2024

Anyone knows why this is returning an error? Is it because of asynchronous functions?

Probably yeah, will check the script locally and maybe fix this issue.


Edit. That didn't take a lot of time, fixed the issue and also updated the README file. It seems like some functions were imported but not actually used so removed it, for the e unused exception variable, I added it to the aprint's output.

i.e.

diff --git a/scripts/check-more-info-urls.py b/scripts/check-more-info-urls.py
index 5d055e9a5bd3f..847232bdef3ab 100644
--- a/scripts/check-more-info-urls.py
+++ b/scripts/check-more-info-urls.py
@@ -2,22 +2,19 @@
 # SPDX-License-Identifier: MIT
 
 """
-A Python script to check for bad (HTTP status code different than 200) "More information" URLs accross all pages.
+A Python script to check for bad (HTTP status code different than 200) "More information" URLs across all pages.
 
-These bad codes tipically indicate a not found page or a redirection. They are written to bad-urls.txt with their respective URLs.
+These bad codes typically indicate a page not found or a redirection. They are written to bad-urls.txt with their respective URLs.
 
 Usage:
     python3 scripts/check-more-info-urls.py
 """
 
-import random
 import re
 import asyncio
-import sys
-from aiofile import AIOFile, Reader, Writer
 import aiohttp.client_exceptions
 from aioconsole import aprint
-from aiofile import async_open
+from aiofile import AIOFile, Writer
 from aiopath import AsyncPath
 
 MAX_CONCURRENCY = 500
@@ -62,7 +59,7 @@ async def process_file(
             try:
                 content = await f.read()
             except Exception as e:
-                await aprint(file.parts[-3:])
+                await aprint(f"Error: {e}, File: {file.parts[-3:]}")
                 return
 
     url = extract_url(content)

Feel free to check it out and modify my changes @vitorhcl.

@kbdharun kbdharun self-assigned this Apr 28, 2024
@vitorhcl
Copy link
Member Author

@kbdharun your change LGTM, thank you for the fixes.

@vitorhcl
Copy link
Member Author

Are you going to implement the domain rotation or do you want me to do that?

@kbdharun
Copy link
Member

Are you going to implement the domain rotation or do you want me to do that?

Feel free to do it, I assigned myself for the previous change (and to sort this PR separately under my notifications 😅 ).

vitorhcl and others added 4 commits May 6, 2024 12:08
- Write any HTTP status code != 200 to the output file.
- Use better names for some functions.
- Improve the initial page getting output wording and formatting.
- Remove some unnecessary functions that makes the initial pages
  getting faster.
- Write the output URLs to a CSV file, as the previous format
  was very similar.
- Colorize the displayed HTTP status codes. The corresponding
  colors are documented in the CodeColors class.
…ntation

- Extract URL parsing and bad URLs writing from main() to
  find_and_write_bad_urls()
- Rename some functions, variables and parameters
- Improve the documentation of the functions
- Document the missing return types
Before, find_all_pages was getting all pages multiple times while
iterating over the platforms too, which was hugely slowing down the page
finding.
@sebastiaanspeck
Copy link
Member

@vitorhcl is this PR ready for review? Or should it become draft until it is ready for review?

@vitorhcl
Copy link
Member Author

@vitorhcl is this PR ready for review? Or should it become draft until it is ready for review?

Hmm it should become draft until it's ready for merge.

PS: My 3 previous commits have bodies that explain each change.

@kbdharun kbdharun marked this pull request as draft May 11, 2024 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issues/PRs modifying the documentation. tooling Helper tools, scripts and automated processes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants