33import requests
44import os
55from urllib .parse import urlparse
6+ from textblob import TextBlob
67from .heuristics import (
78 URGENCY_KEYWORDS ,
89 SENSITIVE_INFO_KEYWORDS ,
@@ -127,7 +128,15 @@ def analyze_text_for_scams(text_content, platform=None, api_key=None):
127128 indicators_found = []
128129 urls_analyzed_details = []
129130
130- # 1. Keyword-based checks
131+ # 1. Sentiment Analysis
132+ blob = TextBlob (text_content )
133+ if blob .sentiment .polarity < - 0.5 :
134+ message = "Strong negative sentiment detected in text."
135+ if message not in indicators_found :
136+ indicators_found .append (message )
137+ score += HEURISTIC_WEIGHTS .get ("NEGATIVE_SENTIMENT" , 2.0 )
138+
139+ # 2. Keyword-based checks
131140 keyword_checks = {
132141 "URGENCY" : URGENCY_KEYWORDS ,
133142 "SENSITIVE_INFO" : SENSITIVE_INFO_KEYWORDS ,
@@ -145,7 +154,7 @@ def analyze_text_for_scams(text_content, platform=None, api_key=None):
145154 indicators_found .append (message )
146155 score += HEURISTIC_WEIGHTS .get (category , 1.0 )
147156
148- # 2 . Regex-based checks
157+ # 3 . Regex-based checks
149158 found_urls = URL_PATTERN .findall (text_content )
150159 for url_str in found_urls :
151160 is_susp , reason = is_url_suspicious (url_str , platform , api_key )
@@ -159,15 +168,15 @@ def analyze_text_for_scams(text_content, platform=None, api_key=None):
159168 indicators_found .append (f"Suspicious URL found: { url_str } (Reason: { reason } )" )
160169 urls_analyzed_details .append (url_analysis )
161170
162- # 3 . Financial Identifiers
171+ # 4 . Financial Identifiers
163172 for id_name , pattern in FINANCIAL_ADDRESS_PATTERNS .items ():
164173 if pattern .search (text_content ):
165174 message = f"Potential { id_name } identifier found."
166175 if message not in indicators_found :
167176 indicators_found .append (message )
168177 score += HEURISTIC_WEIGHTS .get (f"{ id_name } _ADDRESS" , 2.5 )
169178
170- # 4 . Phone Numbers
179+ # 5 . Phone Numbers
171180 if PHONE_NUMBER_PATTERN .search (text_content ):
172181 message = "Phone number detected in text."
173182 if message not in indicators_found :
0 commit comments