Skip to content

Fetch individual translation archives for cache (#217) #218

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

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Changes from 1 commit
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
12 changes: 7 additions & 5 deletions tldr.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,17 @@ def update_cache(language: Optional[List[str]] = None) -> None:
elif isinstance(language, list):
language = language[0]
try:
pages_dir = "pages"
pages_dir = "pages/"
cache_location = DOWNLOAD_CACHE_LOCATION
if language and language != 'en':
pages_dir += "." + language
pages_dir = ""
cache_location = f"{cache_location[:-4]}-pages.{language}.zip"
req = urlopen(Request(
DOWNLOAD_CACHE_LOCATION,
cache_location,
headers=REQUEST_HEADERS
), context=URLOPEN_CONTEXT)
zipfile = ZipFile(BytesIO(req.read()))
pattern = re.compile(r"{}/(.+)/(.+)\.md".format(pages_dir))
pattern = re.compile(r"{}(.+)/(.+)\.md".format(pages_dir))
cached = 0
for entry in zipfile.namelist():
match = pattern.match(entry)
Expand All @@ -402,7 +404,7 @@ def update_cache(language: Optional[List[str]] = None) -> None:
cached += 1
print("Updated cache for {:d} entries".format(cached))
except Exception:
sys.exit("Error: Unable to update cache from " + DOWNLOAD_CACHE_LOCATION)
sys.exit("Error: Unable to update cache from " + cache_location)


def create_parser() -> ArgumentParser:
Expand Down