1+ import colorama
2+ import requests
3+ from bs4 import BeautifulSoup
4+ import scp001
5+ import register
6+ import time
7+ from speech_engine import speak
8+ from lockout import lock_protocol
9+ import os
10+ import os .path
11+ import shutil
12+ import sys
13+ from colorama import Fore , Back
14+ colorama .init (autoreset = True )
15+
16+
17+ def progress (percent = 0 , width = 30 ):
18+ symbol = width * percent // 100
19+ blanks = width - symbol
20+ print ('\r [ ' , Fore .GREEN + symbol * "█" , blanks * ' ' , ' ]' ,
21+ f' { percent :.0f} %' , sep = '' , end = '' , flush = True )
22+
23+
24+ print ("" )
25+ speak ("Enter security override code" )
26+ override_code = input (Fore .RED + " Enter security override code: " )
27+ if override_code == "rachinter 201" :
28+
29+ print ("" )
30+ print (Fore .YELLOW + " Security override" )
31+ for i in range (101 ):
32+ progress (i )
33+ time .sleep (0.01 )
34+
35+ print ()
36+ print (Fore .GREEN + " Override code accepted" )
37+ speak ("Override code accepted" )
38+
39+ print ("" )
40+ print (" " , Fore .BLACK + Back .GREEN + " ACCESS GRANTED " )
41+ speak ("Access granted." )
42+
43+ folder = os .path .exists ("SCP object files" )
44+ if folder == False :
45+ os .mkdir ("SCP object files" )
46+ elif folder == True :
47+ pass
48+
49+ if __name__ == "__main__" :
50+
51+ while (1 ):
52+ print ("" )
53+ speak ("Enter terminal command" )
54+ usr = input (" Enter terminal command: " )
55+
56+ if usr == "001" :
57+ scp001 .restricted ()
58+
59+ elif usr .lower () == "del" :
60+ print ("" )
61+ print (Fore .RED + " ----------------------------" )
62+ print (Fore .RED + " INITIATING DELETION PROTOCOL" )
63+ print (Fore .RED + " ----------------------------" )
64+ speak ("initiating deletion protocol" )
65+ shutil .rmtree ("SCP object files" )
66+ time .sleep (1 )
67+ print (
68+ Fore .GREEN + " All files related to SCP objects has been deleted." )
69+ speak ("All files related to SCP objects has been deleted" )
70+
71+ elif usr == "help" :
72+ print ("" )
73+ print (" -----------------------------------------" )
74+ print (" |" , Fore .CYAN + "Enter SCP item number :" , Fore .LIGHTBLACK_EX + "Displays information for a given artifact" )
75+ print (" |" , Fore .CYAN + "del :" , Fore .LIGHTBLACK_EX + "Initiates deletion protocol" )
76+ print (" |" , Fore .CYAN + "clear :" , Fore .LIGHTBLACK_EX + "Clears the output of the terminal" )
77+ print (" |" , Fore .CYAN + "reg :" , Fore .LIGHTBLACK_EX + "Registers new user" )
78+ print (" -----------------------------------------" )
79+ speak ("Displaying terminal instructions." )
80+ time .sleep (3 )
81+
82+ elif usr == "lock" :
83+ lock_protocol ()
84+
85+ elif usr == "reg" :
86+ register .usr_register ()
87+
88+ elif usr == "clear" :
89+ os .system ('cls' )
90+ speak ("terminal output cleared" )
91+
92+ else :
93+ r = requests .get (f'https://scp-wiki.wikidot.com/scp-{ usr } ' )
94+ soup = BeautifulSoup (r .content , 'html.parser' )
95+ s = soup .find ('div' , id = 'page-content' )
96+
97+ paras = len (s .find_all ("p" ))
98+
99+ print ("" )
100+ print (Fore .YELLOW + f" Accessing SCP-{ usr } files" )
101+ speak (f"Accessing SCP-{ usr } files" )
102+ for i in range (101 ):
103+ progress (i )
104+ time .sleep (0.01 )
105+
106+ print ()
107+ print (Fore .GREEN + " Access granted" )
108+ print ("" )
109+
110+ print (Fore .GREEN + soup .title .text .center (100 ))
111+ print ("" )
112+
113+ paras_num = range (1 , paras )
114+ num_list = list (paras_num )
115+
116+ item = f"{ s .find_all ('p' )[0 ].text } \n "
117+ print (Fore .YELLOW + item .center (100 ))
118+
119+ try :
120+ for i in num_list :
121+ txt = s .find_all ('p' )[i ].text
122+
123+ def format_paragraph (paragraph , length , left , right ):
124+ words = paragraph .split ()
125+ lines = []
126+ # we add a space before the first word
127+ curline = ' ' * (left - 1 )
128+
129+ while words :
130+ # process the next word
131+ word = words .pop (0 )
132+ # +1 in the next line is for the space.
133+ if len (curline ) + 1 + len (word ) > length - right :
134+ # line would have been too long, start a new line
135+ lines .append (curline )
136+ curline = ' ' * (left - 1 )
137+ curline += " " + word
138+ lines .append (curline )
139+
140+ return '\n ' .join (lines )
141+ # we need to work on one paragraph at a time
142+ paragraphs = txt .split ('\n \n ' )
143+
144+ for paragraph in paragraphs :
145+ q = format_paragraph (
146+ paragraph , 80 , left = 4 , right = 5 )
147+ print (q )
148+ print ("" ) # next paragraph
149+
150+ except IndexError :
151+ print (Fore .RED + "<<< END OF FILE >>>" .center (100 ))
152+ print (Fore .RED + "<<< END OF FILE >>>" .center (100 ))
153+ print (Fore .LIGHTBLACK_EX + "File saved locally" .center (100 ))
154+ print ("" )
155+ print (Fore .LIGHTBLACK_EX +
156+ "Terminal developed by Ashfaaq Rifath" .center (100 ))
157+
158+ save_path = "SCP object files"
159+ save = os .path .join (save_path , f'SCP-{ usr } .txt' )
160+
161+ orig_stdout = sys .stdout
162+ f = open (save , 'w' , encoding = "utf-8" )
163+ sys .stdout = f
164+
165+ for i in num_list :
166+ txt = s .find_all ('p' )[i ].text
167+
168+ def format_paragraph (paragraph , length , left , right ):
169+ words = paragraph .split ()
170+ lines = []
171+ # we add a space before the first word
172+ curline = ' ' * (left - 1 )
173+
174+ while words :
175+ word = words .pop (0 ) # process the next word
176+ # +1 in the next line is for the space.
177+ if len (curline ) + 1 + len (word ) > length - right :
178+ # line would have been too long, start a new line
179+ lines .append (curline )
180+ curline = ' ' * (left - 1 )
181+ curline += " " + word
182+ lines .append (curline )
183+
184+ return '\n ' .join (lines )
185+ # we need to work on one paragraph at a time
186+ paragraphs = txt .split ('\n \n ' )
187+
188+ for paragraph in paragraphs :
189+ q = format_paragraph (
190+ paragraph , 80 , left = 4 , right = 5 )
191+ print (q )
192+ print ("" )
193+
194+ sys .stdout = orig_stdout
195+ f .close ()
196+
197+ speak (f"Item number : SCP-{ usr } " )
198+
199+ sis = s .find_all ('p' )[2 ].text
200+ speak (sis )
201+
202+ lines = s .find_all ('p' )[3 ]
203+ speak (lines )
204+
205+ else :
206+ print ("" )
207+ print (" " , Fore .BLACK + Back .RED + " INVALID OVERRIDE CODE " )
208+ speak ("INVALID OVERRIDE CODE" )
209+ print ("" )
210+ print (Fore .RED + " <<< TERMINAL LOCKOUT >>>" )
211+ time .sleep (7300 )
212+
213+
214+
215+
216+
217+
218+ # <<< Copyright (c) 2023 Ashfaaq Rifath - SCP Foundation Terminal v2.1.1 >>>
0 commit comments