From 0aa92c137ac259eae3306e299651b6a1df4c4142 Mon Sep 17 00:00:00 2001 From: Daniel <139119540+DeltaDaniel@users.noreply.github.com> Date: Tue, 26 Sep 2023 09:05:55 +0200 Subject: [PATCH] :construction: fix deprecated module 'cgi' (#73) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :construction: reproducing deprecation error * changed basepython * Update tox.ini * Update tox.ini * 🔄replaced 'cgi' module by 'email' cf. PEP 594 https://peps.python.org/pep-0594/#cgi --------- Co-authored-by: konstantin --- requirements.txt | 2 +- src/edi_energy_scraper/__init__.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index ca85992..5db1f9f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.10 # by the following command: # # pip-compile requirements.in diff --git a/src/edi_energy_scraper/__init__.py b/src/edi_energy_scraper/__init__.py index 22a6e35..f4e9f29 100644 --- a/src/edi_energy_scraper/__init__.py +++ b/src/edi_energy_scraper/__init__.py @@ -2,7 +2,6 @@ A module to scrape data from edi-energy.de. """ import asyncio -import cgi # pylint:disable=deprecated-module # https://github.com/Hochfrequenz/edi_energy_scraper/issues/28 import datetime @@ -11,6 +10,7 @@ import logging import os import re +from email.message import Message from enum import Enum from pathlib import Path from random import randint @@ -158,9 +158,11 @@ def _get_file_path(self, epoch: Epoch, file_name: str) -> Path: def _add_file_extension_to_file_basename(headers: dict, file_basename: str) -> str: """Extracts the extension of a file from a response header and add it to the file basename.""" content_disposition = headers["Content-Disposition"] - _, params = cgi.parse_header(content_disposition) - file_extension = Path(params["filename"]).suffix + params = Message() + params["content-type"] = content_disposition + file_extension = Path(str(params.get_param("filename"))).suffix file_name = file_basename + file_extension + return file_name @staticmethod