I'm automatically looking for various properties of README.md files.
import requests
from typing import Final
FILE_NOT_FOUND: Final[int] = 404
GITHUB_URL: Final[str] = "https://github.com/"
repo_name_1 = "FasterXML/jackson-databind" # <--- main_name = 2.14
repo_name_2 = "Cacti/cacti" # <--- main_name = develop
repo_name_3 = "FFmpeg/FFmpeg" # <--- main_name = master
main_name = "develop"
repo_name = repo_name_2
url = f"{GITHUB_URL}/{repo_name}/blob/{main_name}/README.md"
if requests.head(url).status_code != FILE_NOT_FOUND:
print(f"README.md of {repo_name} exists")
# do something with README.md ...
I need to somehow put a regex instead of main_name, is that doable?
EDIT:
Put in other words, can one use requests to do the equivalent of find:
find https://github.com/FasterXML/jackson-databind -name "README.md"
/would be good for me - is it possible to do that?requests.head()method you have to tell it what URL to go after. You can't tell it to go after any URL that takes a particular pattern. It would be like telling your web browser that you want to go tostackover[a-zA-Z0-9]low.com. What would it do? Visit 62 different websites and bring them all back in different tabs? What would that even mean? If you need to check if N combinations of a particular URL exist, you will have to ping N URLs. There's no getting around that.