Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions scripts/_resolve_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
RepoInfo,
RepoMetadata,
)
from ._utils import drop_falsy, flatten, pipe, unique_values_preserving_order, write_json
from ._utils import (
drop_falsy,
flatten,
pipe,
unique_values_preserving_order,
write_json,
USER_AGENT,
)


PYPI_BASE = "https://pypi.org/pypi/{}/json"
Expand Down Expand Up @@ -619,7 +626,7 @@ async def _fetch_pypi_json(
if fetched_at and now - fetched_at < ttl_seconds:
return load_json(cache_path), "cache"

headers = {}
headers = {'User-Agent': USER_AGENT}
if has_cache:
if entry.get("etag"):
headers["If-None-Match"] = entry["etag"]
Expand Down
3 changes: 3 additions & 0 deletions scripts/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import inflect


USER_AGENT = "Mozilla/5.0 (thecrawl 1.0; +https://packages.sublimetext.io)"


def err(*args, **kwargs):
print(*args, **kwargs, file=sys.stderr)

Expand Down
4 changes: 2 additions & 2 deletions scripts/accumulate_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from itertools import count, takewhile
from urllib.request import Request, urlopen

from ._utils import write_json
from ._utils import write_json, USER_AGENT

DEFAULT_OUTPUT_FILE = "stats.json"
DEFAULT_URL = "https://stats.sublimetext.io/all-totals"
Expand Down Expand Up @@ -121,7 +121,7 @@ def accumulate(value: int, container: dict, key: str, wanted_length: int, rollov


def fetch_totals(url: str) -> dict:
request = Request(url, headers={"User-Agent": "Mozilla/5.0"})
request = Request(url, headers={"User-Agent": USER_AGENT})
with urlopen(request) as resp:
return json.load(resp)

Expand Down
4 changes: 2 additions & 2 deletions scripts/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from typing import AsyncIterable, TypedDict, Literal, Iterable

from ._utils import drop_falsy, err, normalize_tz_aware_datetime
from ._utils import drop_falsy, err, normalize_tz_aware_datetime, USER_AGENT


type QueryScope = Literal["METADATA", "TAGS", "BRANCHES"]
Expand Down Expand Up @@ -62,7 +62,7 @@ class RepoInfo(TypedDict):


async def fetch_json(session: aiohttp.ClientSession, url: str) -> dict:
headers = {}
headers = {'User-Agent': USER_AGENT}
if token := os.getenv("BITBUCKET_TOKEN"):
headers["Authorization"] = f"Bearer {token}"
async with session.get(url, headers=headers) as resp:
Expand Down
4 changes: 2 additions & 2 deletions scripts/codeberg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from typing import AsyncIterable, TypedDict, Literal, Iterable

from ._utils import drop_falsy, err, normalize_tz_aware_datetime
from ._utils import drop_falsy, err, normalize_tz_aware_datetime, USER_AGENT


type QueryScope = Literal["METADATA", "TAGS", "BRANCHES"]
Expand Down Expand Up @@ -71,7 +71,7 @@ def parse_owner_repo(url: str):


def _auth_headers() -> dict[str, str]:
headers: dict[str, str] = {}
headers: dict[str, str] = {'User-Agent': USER_AGENT}
# Codeberg (Forgejo/Gitea) supports Authorization: token <TOKEN>
if token := os.getenv("CODEBERG_TOKEN"):
headers["Authorization"] = f"token {token}"
Expand Down
4 changes: 2 additions & 2 deletions scripts/compress_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import sys

from ._utils import pl, write_json
from ._utils import pl, write_json, USER_AGENT


NEW_CHANNEL = (
Expand Down Expand Up @@ -153,7 +153,7 @@ async def http_get_json(location: str, session: aiohttp.ClientSession) -> dict:

async def http_get(location: str, session: aiohttp.ClientSession) -> str:
headers = {
'User-Agent': 'Mozilla/5.0',
'User-Agent': USER_AGENT,
'Cache-Control': 'no-cache',
'Pragma': 'no-cache'
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from urllib.parse import urlparse
from typing import Any, Callable, Iterable, Mapping, NotRequired, TypedDict, TypeGuard

from ._utils import flatten, pick, resolve_urls, update_url, write_json, pl
from ._utils import flatten, pick, resolve_urls, update_url, write_json, pl, USER_AGENT


DEFAULT_OUTPUT_FILE = "./registry.json"
Expand Down Expand Up @@ -337,7 +337,7 @@ async def http_get_json(location: str, session: aiohttp.ClientSession) -> dict:


async def http_get(location: str, session: aiohttp.ClientSession) -> str:
headers = {'User-Agent': 'Mozilla/5.0'}
headers = {'User-Agent': USER_AGENT}
async with session.get(location, headers=headers, raise_for_status=True) as resp:
return await resp.text()

Expand Down
3 changes: 2 additions & 1 deletion scripts/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from typing import AsyncIterable, Iterable, TypedDict

from ._utils import drop_falsy, normalize_tz_aware_datetime
from ._utils import drop_falsy, normalize_tz_aware_datetime, USER_AGENT

# This module exposes a single entrypoint
# fetch_repo_info(Url, Iterable[QueryScope]) -> RepoInfo
Expand Down Expand Up @@ -292,6 +292,7 @@ def github_headers(accept: str) -> dict[str, str]:
if not token:
raise RuntimeError("GITHUB_TOKEN env var is not set")
return {
"User-Agent": USER_AGENT,
"Authorization": f"Bearer {token}",
"Accept": accept,
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from urllib.parse import urlparse, quote
from typing import AsyncIterable, TypedDict, Literal, Iterable

from ._utils import drop_falsy, err, normalize_tz_aware_datetime
from ._utils import drop_falsy, err, normalize_tz_aware_datetime, USER_AGENT

QueryScope = Literal["METADATA", "TAGS", "BRANCHES"]
Url = str
Expand Down Expand Up @@ -70,7 +70,7 @@ def parse_owner_repo(url: str):


def _auth_headers() -> dict[str, str]:
headers: dict[str, str] = {}
headers: dict[str, str] = {'User-Agent': USER_AGENT}
if token := os.getenv("GITLAB_TOKEN"):
headers["PRIVATE-TOKEN"] = token
return headers
Expand Down
Loading