Skip to content

Commit

Permalink
hrm prettier changes cassette yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
stringertheory committed Jan 30, 2024
1 parent 683f3a6 commit ad79f32
Show file tree
Hide file tree
Showing 9 changed files with 956 additions and 14 deletions.
1 change: 1 addition & 0 deletions clean_links/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.1"
27 changes: 16 additions & 11 deletions clean_links/unshorten.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import contextlib
import logging
from typing import Union
import warnings
from typing import Generator, Union

import requests
from urllib3.exceptions import InsecureRequestWarning
import urllib3

# suppress warning about that's given when using verify=False
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
from clean_links import __version__

__packagename__ = "CleanLinks"
__version__ = "0.01"
__url__ = "https://github.com/stringertheory/clean-links"

USER_AGENT = f"{__packagename__}/{__version__} ({__url__})"
USER_AGENT = f"clean-links/{__version__}"
USER_AGENT = (
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
Expand All @@ -29,6 +26,13 @@
}


@contextlib.contextmanager
def disable_ssl_warnings() -> Generator:
with warnings.catch_warnings():
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
yield None


def get_last_url_from_exception(exc: Exception) -> Union[str, None]:
result = None

Expand All @@ -46,7 +50,7 @@ def get_last_url_from_exception(exc: Exception) -> Union[str, None]:
def unshorten_url(
url: str, timeout: int = 9, verify: bool = False, headers: dict = HEADERS
) -> dict:
with requests.Session() as session:
with requests.Session() as session, disable_ssl_warnings():
try:
response = session.head(
url,
Expand Down Expand Up @@ -78,8 +82,9 @@ def main() -> None:
url = "https://bit.ly/3C4WXQ9"
# url = 'https://tinyurl.com/NewwAlemAndKibrom'
url = "https://hubs.la/Q01HRjhm0"
url = "https://expired.badssl.com/"

print(unshorten_url(url))
print(unshorten_url(url, verify=True))


if __name__ == "__main__":
Expand Down
321 changes: 320 additions & 1 deletion poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tool.poetry]
name = "clean_links"
version = "0.0.1"
description = "Tools for cleaning up linkss"
authors = ["Mike Stringer <fmike[email protected]>"]
description = "Tools for cleaning up links"
authors = ["Mike Stringer <mike[email protected]>"]
repository = "https://github.com/stringertheory/clean-links"
documentation = "https://stringertheory.github.io/clean-links/"
readme = "README.md"
Expand All @@ -20,6 +20,7 @@ mypy = "^1.5.1"
pre-commit = "^3.4.0"
tox = "^4.11.1"
types-requests = "^2.31.0.20240125"
pytest-recording = "^0.13.1"

[tool.poetry.group.docs.dependencies]
mkdocs = "^1.4.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
interactions:
- request:
body: null
headers:
Connection:
- keep-alive
accept:
- text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
accept-encoding:
- gzip, deflate, br
accept-language:
- en-US,en;q=0.9
sec-fetch-dest:
- document
sec-fetch-mode:
- navigate
sec-fetch-site:
- same-origin
sec-fetch-user:
- ?1
upgrade-insecure-requests:
- "1"
user-agent:
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/120.0.0.0 Safari/537.36
method: HEAD
uri: https://expired.badssl.com/
response:
body:
string: ""
headers:
Cache-Control:
- no-store
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- text/html
Date:
- Tue, 30 Jan 2024 04:37:28 GMT
ETag:
- W/"6567bc98-1ee"
Last-Modified:
- Wed, 29 Nov 2023 22:35:04 GMT
Server:
- nginx/1.10.3 (Ubuntu)
status:
code: 200
message: OK
version: 1
Loading

0 comments on commit ad79f32

Please sign in to comment.