SaiBon99 commited on
Commit
09de783
·
1 Parent(s): d619900

Add script to transform legitimate URLs for phishing detection

Browse files
src/phising_detection/utils/hopsworks_utils.py CHANGED
@@ -69,10 +69,6 @@ def get_or_create_feature_group(
69
  project,
70
  name: str,
71
  version: int = 1,
72
- description: str = "",
73
- primary_key: list = None,
74
- event_time: Optional[str] = None,
75
- online_enabled: bool = False
76
  ):
77
  """
78
  Get existing feature group or create new one if it doesn't exist.
 
69
  project,
70
  name: str,
71
  version: int = 1,
 
 
 
 
72
  ):
73
  """
74
  Get existing feature group or create new one if it doesn't exist.
temporary_examples/transform_legit_urls_to_hopsworks.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Script to retrieve legitimate URLs from Hopsworks, transform them to match phishing URL format, and upload."""
2
+
3
+ import sys
4
+ from pathlib import Path
5
+ import json
6
+ import argparse
7
+
8
+ import pandas as pd
9
+
10
+ project_root = Path(__file__).parent.parent
11
+ sys.path.insert(0, str(project_root / "src"))
12
+
13
+ from phising_detection.utils.hopsworks_utils import (
14
+ connect_to_hopsworks,
15
+ upload_dataframe_to_feature_group,
16
+ get_or_create_feature_group
17
+ )
18
+
19
+
20
+ import hopsworks
21
+
22
+ # Connect and read feature group
23
+ project = hopsworks.login()
24
+ fs = project.get_feature_store(name='simbe200_featurestore')
25
+ fg = fs.get_feature_group('scan_progress_legit_urls', version=4)
26
+ df = fg.read()
27
+
28
+ print("Original feature group data:")
29
+ print(df.head(5))
30
+ print(f"\nDataFrame shape: {df.shape}")
31
+
32
+ # Extract all URLs from the JSON-serialized 'urls' column
33
+ all_urls = []
34
+ for _, row in df.iterrows():
35
+ # Deserialize the JSON string to get the list of URLs
36
+ urls_list = json.loads(row['urls'])
37
+ all_urls.extend(urls_list)
38
+
39
+ print(f"\nTotal URLs extracted: {len(all_urls)}")
40
+
41
+ # Create new DataFrame matching phishing URL format
42
+ legit_urls_df = pd.DataFrame({
43
+ 'url_id': range(len(all_urls)),
44
+ 'url': all_urls,
45
+ 'is_phishing': 0 # 0 for legitimate URLs
46
+ })
47
+
48
+ get_or_create_feature_group(project, 'legit_urls_before_scan', version=1)
49
+ upload_dataframe_to_feature_group(
50
+ project=project,
51
+ df=legit_urls_df,
52
+ feature_group_name='legit_urls_before_scan',
53
+ version=1,
54
+ description='Legitimate URLs formatted for phishing detection',
55
+ primary_key=['url_id'],
56
+ event_time=None,
57
+ online_enabled=False
58
+ )
59
+