Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from rly0nheart/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rly0nheart authored May 13, 2023
2 parents e770b8b + 035757a commit b57d628
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions fbi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Union, Literal
from fbi.connection import get_api_response
from fbi.connection import __get_api_response


def wanted(person_classification: Union[Literal['Main'], Literal['Accomplice'], Literal['Victim']] = None,
Expand All @@ -22,7 +22,7 @@ def wanted(person_classification: Union[Literal['Main'], Literal['Accomplice'],
else:
sort_order = f"&sort_order={sort_order}"

response = get_api_response(f"https://api.fbi.gov/@wanted?pageSize={page_size}&page={page}{person_classification}")
response = __get_api_response(f"https://api.fbi.gov/@wanted?pageSize={page_size}&page={page}{person_classification}")
return response['items']


Expand All @@ -32,7 +32,7 @@ def wanted_person(person_id: str) -> dict:
:param person_id: id of wanted person
:return: a dictionary of person's information
"""
return get_api_response(f"https://api.fbi.gov/@wanted-person/{person_id}")
return __get_api_response(f"https://api.fbi.gov/@wanted-person/{person_id}")


def art_crimes(page_size: int = 20, page: int = 1, sort_order: Union[Literal['asc'], Literal['desc'], None] = None,
Expand All @@ -55,7 +55,7 @@ def art_crimes(page_size: int = 20, page: int = 1, sort_order: Union[Literal['as
else:
sort_order = f"&sort_order={sort_order}"

response = get_api_response(f"https://api.fbi.gov/@artcrimes?pageSize={page_size}&page={page}"
response = __get_api_response(f"https://api.fbi.gov/@artcrimes?pageSize={page_size}&page={page}"
f"{sort_order}{reference_number}")
return response['items']

Expand All @@ -66,4 +66,4 @@ def art_crime(crime_id: str) -> dict:
:param crime_id: id of an art crime
:return: dictionary of an art crime's information
"""
return get_api_response(f"https://api.fbi.gov/@artcrimes/{crime_id}")
return __get_api_response(f"https://api.fbi.gov/@artcrimes/{crime_id}")
18 changes: 9 additions & 9 deletions fbi/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import json

def get_api_response(url: str) -> dict:
def __get_api_response(url: str) -> dict:
"""
Sends a GET request to the specified URL and returns the response as a dictionary.
Expand All @@ -23,18 +23,18 @@ def get_api_response(url: str) -> dict:
else:
# FILTERING HTML TO EXTRACT JSON
# Remove HTML tags and unwanted characters and some extra filters
cleaned_text=re.sub('<[^<]+?>|\\\\xa0|\\\\r\\\\n|\r\n', '',response.text)
cleaned_text=re.sub("\\\\\\'",'Ø',cleaned_text)
cleaned_text=re.sub('"','\\"',cleaned_text)
cleaned_text = re.sub('<[^<]+?>|\\\\xa0|\\\\r\\\\n|\r\n', '',response.text)
cleaned_text = re.sub("\\\\\\'",'Ø',cleaned_text)
cleaned_text = re.sub('"','\\"',cleaned_text)

# replace single quotes with double quotes
# cleaned_text=re.sub(r"'([^']+)':", r'"\1":',cleaned_text,flags=re.DOTALL)
# cleaned_text=re.sub(r":(.{0,4}?)'([^']+)'(.{0,4}?,)", r':\1"\2"\3',cleaned_text,flags=re.DOTALL)
# cleaned_text = re.sub(r"'([^']+)':", r'"\1":',cleaned_text,flags=re.DOTALL)
# cleaned_text = re.sub(r":(.{0,4}?)'([^']+)'(.{0,4}?,)", r':\1"\2"\3',cleaned_text,flags=re.DOTALL)

cleaned_text=re.sub('\'', '"',cleaned_text)
cleaned_text = re.sub('\'', '"',cleaned_text)
#replace None with null
cleaned_text=re.sub('None', 'null',cleaned_text)
cleaned_text=re.sub("Ø",'\'',cleaned_text)
cleaned_text = re.sub('None', 'null',cleaned_text)
cleaned_text = re.sub("Ø",'\'',cleaned_text)
# Convert cleaned text to JSON
data = json.loads(cleaned_text)
return data
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "fbi-api"
version = "1.1.0"
version = "1.2.0"
description = "A Python wrapper around the FBI API (unofficial)"
readme = "README.md"
requires-python = ">=3.9"
Expand Down

0 comments on commit b57d628

Please sign in to comment.