22import time
33import sys
44import re
5- from user_scanner .cli import printer
6- from user_scanner .core .orchestrator import generate_permutations , load_categories
5+ from user_scanner .core .orchestrator import generate_permutations , load_categories , load_modules
76from colorama import Fore , Style
87from user_scanner .cli .banner import print_banner
98from typing import List
109from user_scanner .core .result import Result
1110from user_scanner .core .version import load_local_version
1211from user_scanner .core .helpers import is_last_value
12+ from user_scanner .core import formatter
1313from user_scanner .utils .updater_logic import check_for_updates
1414from user_scanner .utils .update import update_self
1515
2121X = Fore .RESET
2222
2323
24- MAX_PERMUTATIONS_LIMIT = 100 # To prevent excessive generation
24+ MAX_PERMUTATIONS_LIMIT = 100 # To prevent excessive generation
2525
2626
2727def main ():
@@ -53,13 +53,13 @@ def main():
5353 "-v" , "--verbose" , action = "store_true" , help = "Enable verbose output"
5454 )
5555 parser .add_argument (
56- "-p" , "--permute" ,type = str ,help = "Generate username permutations using a string pattern (e.g -p 234)"
56+ "-p" , "--permute" , type = str , help = "Generate username permutations using a string pattern (e.g -p 234)"
5757 )
5858 parser .add_argument (
59- "-s" , "--stop" ,type = int ,default = MAX_PERMUTATIONS_LIMIT ,help = "Limit the number of username permutations generated"
59+ "-s" , "--stop" , type = int , default = MAX_PERMUTATIONS_LIMIT , help = "Limit the number of username permutations generated"
6060 )
6161 parser .add_argument (
62- "-d" , "--delay" ,type = float ,default = 0 ,help = "Delay in seconds between requests (recommended: 1-2 seconds)"
62+ "-d" , "--delay" , type = float , default = 0 , help = "Delay in seconds between requests (recommended: 1-2 seconds)"
6363 )
6464 parser .add_argument (
6565 "-f" , "--format" , choices = ["console" , "csv" , "json" ], default = "console" , help = "Specify the output format (default: console)"
@@ -75,15 +75,21 @@ def main():
7575 )
7676 args = parser .parse_args ()
7777
78- Printer = printer .Printer (args .format )
79-
8078 if args .update is True :
8179 update_self ()
8280 print (f"[{ G } +{ X } ] { G } Update successful. Please restart the tool.{ X } " )
8381 sys .exit (0 )
8482
8583 if args .list :
86- Printer .print_modules (args .category )
84+ categories = load_categories ()
85+ for cat_name , cat_path in categories .items ():
86+ modules = load_modules (cat_path )
87+ print (Fore .MAGENTA +
88+ f"\n == { cat_name .upper ()} SITES =={ Style .RESET_ALL } " )
89+ for module in modules :
90+ site_name = module .__name__ .split ("." )[- 1 ].capitalize ()
91+ print (f" - { site_name } " )
92+
8793 return
8894
8995 if args .version :
@@ -93,57 +99,53 @@ def main():
9399 check_for_updates ()
94100
95101 if not (args .username or args .email ):
96- parser .print_help ()
97- return
102+ parser .print_help ()
103+ return
98104
99- if Printer .is_console :
100- print_banner ()
105+ print_banner ()
101106
102107 is_email = args .email is not None
103108 if is_email and not re .findall (r"^[^@\s]+@[^@\s]+\.[^@\s]+$" , args .email ):
104109 print (R + "[✘] Error: Invalid email." + X )
105110 sys .exit (1 )
106111
107- if args .permute and args .delay == 0 and Printer . is_console :
112+ if args .permute and args .delay == 0 :
108113 print (
109- Y
110- + "[!] Warning: You're generating multiple usernames with NO delay between requests. "
111- "This may trigger rate limits or IP bans. Use --delay 1 or higher. (Use only if the sites throw errors otherwise ignore)\n "
112- + Style .RESET_ALL )
114+ Y
115+ + "[!] Warning: You're generating multiple usernames with NO delay between requests. "
116+ "This may trigger rate limits or IP bans. Use --delay 1 or higher. (Use only if the sites throw errors otherwise ignore)\n "
117+ + Style .RESET_ALL )
113118
114- name = args .username or args .email # Username or email
119+ name = args .username or args .email # Username or email
115120 usernames = [name ] # Default single username list
116121
117122 # Added permutation support , generate all possible permutation of given sequence.
118123 if args .permute :
119- usernames = generate_permutations (name , args . permute , args . stop , is_email )
120- if Printer . is_console :
121- print (
122- C + f"[+] Generated { len (usernames )} username permutations" + Style .RESET_ALL )
124+ usernames = generate_permutations (
125+ name , args . permute , args . stop , is_email )
126+ print (
127+ C + f"[+] Generated { len (usernames )} username permutations" + Style .RESET_ALL )
123128
124129 if args .module and "." in args .module :
125130 args .module = args .module .replace ("." , "_" )
126131
127- def run_all_usernames (func , arg = None ) -> List [Result ]:
132+ def run_all_usernames (func , arg = None ) -> List [Result ]:
128133 """
129134 Executes a function for all given usernames.
130135 Made in order to simplify main()
131136 """
132137 results = []
133- print (Printer .get_start ())
134138 for i , name in enumerate (usernames ):
135- is_last = i == len (usernames ) - 1
139+ is_last = is_last_value (usernames , i )
136140 if arg is None :
137- results .extend (func (name , Printer , is_last ))
141+ results .extend (func (name ))
138142 else :
139- results .extend (func (arg , name , Printer , is_last ))
143+ results .extend (func (arg , name ))
140144 if args .delay > 0 and not is_last :
141145 time .sleep (args .delay )
142- if Printer .is_json :
143- print (Printer .get_end ())
144146 return results
145147
146- results = []
148+ results = []
147149
148150 if args .module :
149151 # Single module search across all categories
@@ -171,22 +173,16 @@ def run_all_usernames(func, arg = None) -> List[Result]:
171173 if not args .output :
172174 return
173175
174- if args .output and Printer . is_console :
176+ if args .output and args . format == "console" :
175177 msg = (
176178 "\n [!] The console format cannot be "
177179 f"written to file: '{ args .output } '."
178180 )
179181 print (R + msg + Style .RESET_ALL )
180182 return
181183
182- content = Printer .get_start ()
183-
184- for i ,result in enumerate (results ):
185- char = "" if Printer .is_csv or is_last_value (results , i ) else ","
186- content += "\n " + Printer .get_result_output (result ) + char
187-
188- if Printer .is_json :
189- content += "\n " + Printer .get_end ()
184+
185+ content = formatter .into_csv (results ) if args .format == "csv" else formatter .into_json (results )
190186
191187 with open (args .output , "a" , encoding = "utf-8" ) as f :
192188 f .write (content )
0 commit comments