Skip to content

Commit

Permalink
utils(commands): move mult replace from file
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusvrs committed Dec 26, 2023
1 parent 3cfefcb commit 93d8ce1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
14 changes: 14 additions & 0 deletions api/utils/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import re


def multiple_replace(text, replacement=None):
replacement_dict = replacement
if not replacement: # pragma: no cover
replacement_dict = {
'\n': '',
'\t': '',
'\r': '',
}

pattern = re.compile('|'.join(map(re.escape, replacement_dict.keys())))
return pattern.sub(lambda match: replacement_dict[match.group(0)], text)
15 changes: 1 addition & 14 deletions api/utils/management/commands/updatemock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,11 @@
from utils import sessions as sns, web_scraping as wbp
from django.core.management.base import BaseCommand
from pathlib import Path
import re
from utils.functions import multiple_replace
import json
import os


def multiple_replace(text, replacement=None):
replacement_dict = replacement
if not replacement:
replacement_dict = {
'\n': '',
'\t': '',
'\r': '',
}

pattern = re.compile('|'.join(map(re.escape, replacement_dict.keys())))
return pattern.sub(lambda match: replacement_dict[match.group(0)], text)


class Command(BaseCommand):
"""Comando para atualizar os arquivos de mock do SIGAA."""

Expand Down
4 changes: 2 additions & 2 deletions api/utils/web_scraping.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections import defaultdict
from typing import List, Optional, Iterator
from re import findall, finditer
from utils.management.commands import updatemock
from utils.functions import multiple_replace
import requests.utils
import requests
import hashlib
Expand Down Expand Up @@ -252,7 +252,7 @@ def create_page_fingerprint(self):
if not tables:
return "not_content"

treated_tables = updatemock.multiple_replace(tables.get_text(), replacement={
treated_tables = multiple_replace(tables.get_text(), replacement={
'\n': '',
'\t': '',
'\r': '',
Expand Down

0 comments on commit 93d8ce1

Please sign in to comment.