-
Notifications
You must be signed in to change notification settings - Fork 10
feature(url-analysis): add domain utility functions and update analysis logic #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = '1.21.11' | ||
| __version__ = '1.21.12' |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||
| from typing import Optional | ||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Union | ||||||||||||||||||||||||||||||||||||||||||||||
| from typing import List | ||||||||||||||||||||||||||||||||||||||||||||||
| from urllib.parse import urlparse | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import requests | ||||||||||||||||||||||||||||||||||||||||||||||
| from requests import Response | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -335,6 +336,17 @@ def get_file_analysis_by_id(analysis_id: str, api: IntezerApi = None) -> Optiona | |||||||||||||||||||||||||||||||||||||||||||||
| def get_analysis_by_id(analysis_id: str, api: IntezerApi = None) -> Optional[FileAnalysis]: | ||||||||||||||||||||||||||||||||||||||||||||||
| return get_file_analysis_by_id(analysis_id, api) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| def _get_domain(url: str) -> str: | ||||||||||||||||||||||||||||||||||||||||||||||
| if not url.startswith(('http://', 'https://')): | ||||||||||||||||||||||||||||||||||||||||||||||
| url = 'http://' + url | ||||||||||||||||||||||||||||||||||||||||||||||
| return urlparse(url).netloc | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+340
to
+343
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add type hints and improve error handling. The function should include type hints and handle invalid URLs gracefully. -def _get_domain(url: str) -> str:
+def _get_domain(url: str) -> str:
+ """Extract domain from URL, prefixing with http:// if protocol is missing.
+
+ Args:
+ url: URL string to parse
+
+ Returns:
+ str: Domain extracted from URL
+
+ Raises:
+ ValueError: If URL is invalid
+ """
if not url.startswith(('http://', 'https://')):
url = 'http://' + url
- return urlparse(url).netloc
+ try:
+ return urlparse(url).netloc
+ except Exception as e:
+ raise ValueError(f"Invalid URL format: {url}") from e📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| def _domain_contains(url: str, search_domain: str) -> bool: | ||||||||||||||||||||||||||||||||||||||||||||||
| return search_domain in _get_domain(url) | ||||||||||||||||||||||||||||||||||||||||||||||
OrenIntezer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| def _clean_url(url: str) -> str: | ||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||
| Remove http:// or https:// or www. from the beginning of the URL, | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -407,7 +419,12 @@ def from_latest_analysis(cls, | |||||||||||||||||||||||||||||||||||||||||||||
| url=url, | ||||||||||||||||||||||||||||||||||||||||||||||
| aggregated_view=True, | ||||||||||||||||||||||||||||||||||||||||||||||
| api=api) | ||||||||||||||||||||||||||||||||||||||||||||||
| analyses_ids = [report['analysis_id'] for report in analysis_history_url_result.all()] | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| analyses_ids = [ | ||||||||||||||||||||||||||||||||||||||||||||||
| report['analysis_id'] for report in analysis_history_url_result.all() | ||||||||||||||||||||||||||||||||||||||||||||||
| if _domain_contains(report['submitted_url'], url) | ||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's talk, not sure i understand why we need the fix here and not in the actual search |
||||||||||||||||||||||||||||||||||||||||||||||
| or _domain_contains(report['scanned_url'], url) | ||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if not analyses_ids: | ||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore case