Skip to content

Commit

Permalink
Feature/allow exact match search when searching for latest url analys…
Browse files Browse the repository at this point in the history
…es (#115)

* Add exact match option to from_latest_analysis in UrlAnalysis

* Add change logs
  • Loading branch information
daniel-oronsi authored Sep 14, 2023
1 parent 1c81b45 commit 16214c1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.19.1
------
- Add "exact_match option" to UrlAnalysis.from_latest_analysis.

1.19
------
- Change "received_by" label to "reported_by" in submit phishing alert.
Expand Down
2 changes: 1 addition & 1 deletion intezer_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.19'
__version__ = '1.19.1'
9 changes: 7 additions & 2 deletions intezer_sdk/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,14 @@ def from_analysis_id(cls, analysis_id: str, api: IntezerApiClient = None) -> Opt
def from_latest_analysis(cls,
url: str,
days_threshold_for_latest_analysis: int = 1,
api: IntezerApiClient = None) -> Optional['UrlAnalysis']:
api: IntezerApiClient = None,
exact_match=False) -> Optional['UrlAnalysis']:
"""
Returns a UrlAnalysis instance with the latest analysis of the given URL.
:param url: The URL to retrieve the latest analysis for.
:param days_threshold_for_latest_analysis: The number of days to look back for the latest analysis.
:param api: The API connection to Intezer.
:param exact_match: If True, the URL must match exactly. Otherwise, try to find similar URLs which were analyzed.
:return: A UrlAnalysis instance with the latest analysis of the given URL.
"""
now = datetime.datetime.now()
Expand All @@ -398,7 +400,10 @@ def from_latest_analysis(cls,
all_analyses_reports = analysis_history_url_result.all()

analyses_ids = [report['analysis_id'] for report in all_analyses_reports
if _clean_url(url) in (_clean_url(report['scanned_url']), _clean_url(report['submitted_url']))]
if url in (report['scanned_url'], report['submitted_url'])]
if not analyses_ids and not exact_match:
analyses_ids = [report['analysis_id'] for report in all_analyses_reports
if _clean_url(url) in (_clean_url(report['scanned_url']), _clean_url(report['submitted_url']))]

if not analyses_ids:
return None
Expand Down

0 comments on commit 16214c1

Please sign in to comment.