diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-12-19 12:12:19 +0100 |
---|---|---|
committer | Árni Dagur <arni@dagur.eu> | 2020-12-19 20:30:24 +0000 |
commit | 801361b3ca04988c4916561c9fb69418000b3eb6 (patch) | |
tree | 2093ecbb3c5ff40e1d5711f7e17baf531eefcff9 | |
parent | 082e6240696ac2f0488bb21de2b59721a091ff9a (diff) | |
download | qutebrowser-801361b3ca04988c4916561c9fb69418000b3eb6.tar.gz qutebrowser-801361b3ca04988c4916561c9fb69418000b3eb6.zip |
generate.py: Use pathlib
-rw-r--r-- | tests/end2end/data/brave-adblock/generate.py | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/tests/end2end/data/brave-adblock/generate.py b/tests/end2end/data/brave-adblock/generate.py index 0ada4b1b9..a69898096 100644 --- a/tests/end2end/data/brave-adblock/generate.py +++ b/tests/end2end/data/brave-adblock/generate.py @@ -19,15 +19,15 @@ # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. import io -import os import gzip import csv +import pathlib import itertools import urllib.request from typing import Optional URL = "https://raw.githubusercontent.com/brave/adblock-rust/master/data/ublock-matches.tsv" -CACHE_LOCATION = "/tmp/ublock-matches.tsv.cache" +CACHE_PATH = pathlib.Path("/tmp/ublock-matches.tsv.cache") ROWS_TO_USE = 30_000 @@ -46,19 +46,17 @@ def type_rename(type_str: str) -> Optional[str]: def main(): # Download file or use cached version - if os.path.isfile(CACHE_LOCATION): - print(f"Using cached file {CACHE_LOCATION}") - with open(CACHE_LOCATION, "r", encoding="utf-8") as cache_f: - data = io.StringIO(cache_f.read()) + if CACHE_PATH.is_file(): + print(f"Using cached file {CACHE_PATH}") + data = io.StringIO(CACHE_PATH.read_text(encoding="utf-8")) else: request = urllib.request.Request(URL) print(f"Downloading {URL} ...") response = urllib.request.urlopen(request) assert response.status == 200 data_str = response.read().decode("utf-8") - print(f"Saving to cache file {CACHE_LOCATION} ...") - with open(CACHE_LOCATION, "w", encoding="utf-8") as cache_f: - cache_f.write(data_str) + print(f"Saving to cache file {CACHE_PATH} ...") + CACHE_PATH.write_text(data_str, encoding="utf-8") data = io.StringIO(data_str) # We only want the first three columns and the first ROWS_TO_USE rows |