Skip to content

Commit

Permalink
🚧 fix deprecated module 'cgi' (#73)
Browse files Browse the repository at this point in the history
* 🚧 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 <konstantin.klein@hochfrequenz.de>
  • Loading branch information
DeltaDaniel and hf-kklein authored Sep 26, 2023
1 parent 78609a3 commit 0aa92c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/edi_energy_scraper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0aa92c1

Please sign in to comment.