Skip to content

Commit 4f21e9c

Browse files
authored
Merge pull request #23 from GYFX35/teen-protection-features
Integrate teenager protection tools to social media analyzer.
2 parents 7b864ba + 9b4d3d4 commit 4f21e9c

File tree

5 files changed

+219
-7
lines changed

5 files changed

+219
-7
lines changed

social_media_analyzer/heuristics.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,37 @@
122122
"bank transfer", "wire details", "account details", "iban", "swift code", "bic"
123123
]
124124

125+
# --- Teenager Protection Heuristics ---
126+
127+
# Keywords/phrases related to cyberbullying
128+
CYBERBULLYING_KEYWORDS = [
129+
"loser", "stupid", "idiot", "hate you", "ugly", "fat",
130+
"kill yourself", "kys", "go die", "nobody likes you", "freak",
131+
"weirdo", "everyone hates you", "you're worthless", "pathetic",
132+
"troll", "noob", "poser", "wannabe", "go away",
133+
"social reject", "outcast", "misfit", "dork", "nerd"
134+
]
135+
136+
# Keywords/phrases related to inappropriate content (sexual, violent, etc.)
137+
INAPPROPRIATE_CONTENT_KEYWORDS = [
138+
# Sexually suggestive
139+
"nude", "sexting", "send nudes", "horny", "slut", "whore", "dick", "pussy",
140+
"porn", "sexy pic", "private parts", "hook up",
141+
# Violence
142+
"kill", "murder", "blood", "gun", "knife", "fight me",
143+
"i will hurt you", "beat you up", "gonna get you",
144+
# Drugs/Alcohol
145+
"drugs", "weed", "cocaine", "pills", "get high", "drunk", "wasted"
146+
]
147+
148+
# Keywords/phrases indicating oversharing of personal information
149+
PRIVACY_RISK_KEYWORDS = [
150+
"my address is", "i live at", "my phone number is", "call me at",
151+
"my full name is", "my school is", "i go to [school_name]",
152+
"my mom's name is", "my dad's name is",
153+
"i'm home alone", "parents are out", "my password is"
154+
]
155+
125156

126157
# --- Fake News Heuristics ---
127158

@@ -240,6 +271,10 @@ def generate_suspicious_url_patterns(legitimate_domains):
240271
"PHONE_NUMBER_UNSOLICITED": 1.0,
241272
"SUSPICIOUS_URL_PATTERN": 3.0, # High weight for matching a suspicious URL pattern
242273
"GOOGLE_SAFE_BROWSING_HIT": 10.0, # Very high weight for a positive Google Safe Browsing match
274+
# Teenager Protection Weights
275+
"CYBERBULLYING": 2.5,
276+
"INAPPROPRIATE_CONTENT": 3.0,
277+
"PRIVACY_RISK": 3.5,
243278
}
244279

245280
if __name__ == '__main__':

social_media_analyzer/main.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from . import fake_profile_detector
33
from . import scam_detector
44
from . import fake_news_detector
5+
from . import teen_protection
56

67
def get_api_key():
78
"""Gets the Google API key from environment variables."""
@@ -130,6 +131,48 @@ def analyze_social_media(api_key):
130131
except ValueError:
131132
print("Invalid input. Please enter a number.")
132133

134+
def analyze_for_teen_risks():
135+
"""Handles analysis for risks relevant to teenagers."""
136+
print("\n--- Teenager Protection Tools ---")
137+
print("Select the type of analysis you want to perform:")
138+
print("1. Analyze text for Cyberbullying")
139+
print("2. Analyze text for Inappropriate Content")
140+
print("3. Analyze text for Privacy Risks (Oversharing)")
141+
142+
try:
143+
choice = int(input("Enter your choice (1-3): "))
144+
if choice not in [1, 2, 3]:
145+
print("Invalid choice. Please try again.")
146+
return
147+
except ValueError:
148+
print("Invalid input. Please enter a number.")
149+
return
150+
151+
text_to_analyze = input("Please paste the text you want to analyze: ").strip()
152+
if not text_to_analyze:
153+
print("No text entered.")
154+
return
155+
156+
result = {}
157+
if choice == 1:
158+
print("\n--- Analyzing for Cyberbullying ---")
159+
result = teen_protection.analyze_for_cyberbullying(text_to_analyze)
160+
elif choice == 2:
161+
print("\n--- Analyzing for Inappropriate Content ---")
162+
result = teen_protection.analyze_for_inappropriate_content(text_to_analyze)
163+
elif choice == 3:
164+
print("\n--- Analyzing for Privacy Risks ---")
165+
result = teen_protection.analyze_for_privacy_risks(text_to_analyze)
166+
167+
print(f"Score: {result['score']} (Higher is more suspicious)")
168+
if result['indicators_found']:
169+
print("Indicators Found:")
170+
for indicator in result['indicators_found']:
171+
print(f"- {indicator}")
172+
else:
173+
print("No specific risk indicators were found.")
174+
175+
133176
def main():
134177
"""Main function to run the security analyzer."""
135178
api_key = get_api_key()
@@ -145,17 +188,20 @@ def main():
145188
print("1. Analyze a Social Media Platform")
146189
print("2. Analyze a Website URL for Scams")
147190
print("3. Analyze a News URL for Fake News")
148-
print("4. Exit")
191+
print("4. Teenager Protection Tools")
192+
print("5. Exit")
149193

150194
try:
151-
choice = int(input("Enter your choice (1-4): "))
195+
choice = int(input("Enter your choice (1-5): "))
152196
if choice == 1:
153197
analyze_social_media(api_key)
154198
elif choice == 2:
155199
analyze_website_url(api_key)
156200
elif choice == 3:
157201
analyze_news_url()
158202
elif choice == 4:
203+
analyze_for_teen_risks()
204+
elif choice == 5:
159205
print("Exiting. Stay safe!")
160206
break
161207
else:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from .heuristics import (
2+
CYBERBULLYING_KEYWORDS,
3+
INAPPROPRIATE_CONTENT_KEYWORDS,
4+
PRIVACY_RISK_KEYWORDS,
5+
HEURISTIC_WEIGHTS
6+
)
7+
8+
def analyze_text_for_teen_risks(text, analysis_type):
9+
"""
10+
Analyzes text for a specific type of risk to teenagers.
11+
12+
:param text: The text content to analyze.
13+
:param analysis_type: The type of analysis to perform ('cyberbullying',
14+
'inappropriate_content', 'privacy_risk').
15+
:return: A dictionary with the score and indicators found.
16+
"""
17+
if not text:
18+
return {"score": 0.0, "indicators_found": []}
19+
20+
text_lower = text.lower()
21+
score = 0.0
22+
indicators_found = []
23+
24+
keyword_map = {
25+
'cyberbullying': ('CYBERBULLYING', CYBERBULLYING_KEYWORDS),
26+
'inappropriate_content': ('INAPPROPRIATE_CONTENT', INAPPROPRIATE_CONTENT_KEYWORDS),
27+
'privacy_risk': ('PRIVACY_RISK', PRIVACY_RISK_KEYWORDS),
28+
}
29+
30+
if analysis_type not in keyword_map:
31+
return {"error": "Invalid analysis type specified."}
32+
33+
category, keywords = keyword_map[analysis_type]
34+
weight = HEURISTIC_WEIGHTS.get(category.upper(), 1.0)
35+
36+
for keyword in keywords:
37+
if keyword in text_lower:
38+
message = f"Detected potential {category.replace('_', ' ').lower()} keyword: '{keyword}'"
39+
if message not in indicators_found:
40+
indicators_found.append(message)
41+
score += weight
42+
43+
return {
44+
"score": round(score, 2),
45+
"indicators_found": indicators_found
46+
}
47+
48+
def analyze_for_cyberbullying(text):
49+
"""Analyzes text for signs of cyberbullying."""
50+
return analyze_text_for_teen_risks(text, 'cyberbullying')
51+
52+
def analyze_for_inappropriate_content(text):
53+
"""Analyzes text for inappropriate content."""
54+
return analyze_text_for_teen_risks(text, 'inappropriate_content')
55+
56+
def analyze_for_privacy_risks(text):
57+
"""Analyzes text for privacy risks (oversharing)."""
58+
return analyze_text_for_teen_risks(text, 'privacy_risk')

social_media_analyzer/test_runner.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
from unittest.mock import patch, Mock
3-
from social_media_analyzer.scam_detector import analyze_text_for_scams
3+
from .scam_detector import analyze_text_for_scams
4+
from .test_teen_protection import TestTeenProtection
45

56
def run_manual_tests():
67
# Example Usage
@@ -91,11 +92,13 @@ def test_google_safe_browsing_clean(self, mock_post):
9192
if __name__ == '__main__':
9293
run_manual_tests()
9394
# Run unit tests
94-
suite = unittest.TestSuite()
95-
suite.addTest(unittest.makeSuite(TestScamDetector))
95+
scam_suite = unittest.makeSuite(TestScamDetector)
96+
teen_suite = unittest.makeSuite(TestTeenProtection)
97+
all_tests = unittest.TestSuite([scam_suite, teen_suite])
98+
9699
runner = unittest.TextTestRunner()
97-
print("\n--- Running Unit Tests for Google Safe Browsing Integration ---")
98-
result = runner.run(suite)
100+
print("\n--- Running All Unit Tests ---")
101+
result = runner.run(all_tests)
99102
if result.wasSuccessful():
100103
print("All tests passed!")
101104
else:
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import unittest
2+
from .teen_protection import (
3+
analyze_for_cyberbullying,
4+
analyze_for_inappropriate_content,
5+
analyze_for_privacy_risks
6+
)
7+
8+
class TestTeenProtection(unittest.TestCase):
9+
10+
def test_cyberbullying(self):
11+
"""Test the cyberbullying detection."""
12+
# Test case with bullying keywords
13+
text1 = "You are such a loser and an idiot."
14+
result1 = analyze_for_cyberbullying(text1)
15+
self.assertGreater(result1['score'], 0)
16+
self.assertIn("Detected potential cyberbullying keyword: 'loser'", result1['indicators_found'])
17+
self.assertIn("Detected potential cyberbullying keyword: 'idiot'", result1['indicators_found'])
18+
19+
# Test case with no bullying keywords
20+
text2 = "Have a great day!"
21+
result2 = analyze_for_cyberbullying(text2)
22+
self.assertEqual(result2['score'], 0)
23+
self.assertEqual(len(result2['indicators_found']), 0)
24+
25+
def test_inappropriate_content(self):
26+
"""Test the inappropriate content detection."""
27+
# Test case with inappropriate keywords
28+
text1 = "Don't send nudes or talk about drugs."
29+
result1 = analyze_for_inappropriate_content(text1)
30+
self.assertGreater(result1['score'], 0)
31+
self.assertIn("Detected potential inappropriate content keyword: 'send nudes'", result1['indicators_found'])
32+
self.assertIn("Detected potential inappropriate content keyword: 'drugs'", result1['indicators_found'])
33+
34+
# Test case with no inappropriate keywords
35+
text2 = "This is a perfectly normal conversation."
36+
result2 = analyze_for_inappropriate_content(text2)
37+
self.assertEqual(result2['score'], 0)
38+
self.assertEqual(len(result2['indicators_found']), 0)
39+
40+
def test_privacy_risks(self):
41+
"""Test the privacy risk detection."""
42+
# Test case with privacy risk keywords
43+
text1 = "My address is 123 Main St and my phone number is 555-1234."
44+
result1 = analyze_for_privacy_risks(text1)
45+
self.assertGreater(result1['score'], 0)
46+
self.assertIn("Detected potential privacy risk keyword: 'my address is'", result1['indicators_found'])
47+
self.assertIn("Detected potential privacy risk keyword: 'my phone number is'", result1['indicators_found'])
48+
49+
# Test case with no privacy risk keywords
50+
text2 = "I like to talk about my hobbies."
51+
result2 = analyze_for_privacy_risks(text2)
52+
self.assertEqual(result2['score'], 0)
53+
self.assertEqual(len(result2['indicators_found']), 0)
54+
55+
def test_empty_input(self):
56+
"""Test empty input for all analysis types."""
57+
result_cb = analyze_for_cyberbullying("")
58+
self.assertEqual(result_cb['score'], 0)
59+
self.assertEqual(len(result_cb['indicators_found']), 0)
60+
61+
result_ic = analyze_for_inappropriate_content("")
62+
self.assertEqual(result_ic['score'], 0)
63+
self.assertEqual(len(result_ic['indicators_found']), 0)
64+
65+
result_pr = analyze_for_privacy_risks("")
66+
self.assertEqual(result_pr['score'], 0)
67+
self.assertEqual(len(result_pr['indicators_found']), 0)
68+
69+
if __name__ == '__main__':
70+
unittest.main()

0 commit comments

Comments
 (0)