Skip to content

Commit 7185c49

Browse files
committed
chore: switch to ruff as formatter
1 parent f196e1c commit 7185c49

File tree

14 files changed

+555
-420
lines changed

14 files changed

+555
-420
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ root = true
44
end_of_line = lf
55
insert_final_newline = true
66
indent_size = 4
7-
indent_style = space
7+
indent_style = tab

.github/workflows/ruff.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Ruff
2+
on: [push, pull_request]
3+
jobs:
4+
ruff:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- uses: chartboost/ruff-action@v1

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ venv
55
.venv
66
__pycache__
77
config.json
8-
credentials.txt
8+
credentials.txt
9+
.ruff_cache
10+
.mypy_cache

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"recommendations": ["editorconfig.editorconfig"]
2+
"recommendations": ["editorconfig.editorconfig", "charliermarsh.ruff", "ms-python.mypy-type-checker"]
33
}
4+

.vscode/settings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"python.analysis.typeCheckingMode": "basic",
3-
"python.analysis.autoImportCompletions": true,
4-
"editor.defaultFormatter": "ms-python.autopep8",
52
"editor.formatOnSave": true,
6-
"editor.formatOnPaste": true
3+
"editor.formatOnPaste": true,
4+
"[python]": {
5+
"editor.defaultFormatter": "charliermarsh.ruff"
6+
}
77
}

main.py

Lines changed: 182 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Main file for the project, handles the arguments and calls the other files."""
2+
23
import asyncio
34
import argparse
45
import os
@@ -9,151 +10,209 @@
910
from services.alive import keepalive
1011
from services.upload import upload_file
1112
from services.extract import extract_credentials
12-
from utilities.fs import Config, concrete_read_config, read_config, write_config, write_default_config, save_credentials
13-
from utilities.web import generate_mail, type_name, type_password, initial_setup, mail_login, get_mail
14-
from utilities.etc import Credentials, p_print, clear_console, Colours, clear_tmp, reinstall_tenacity, check_for_updates, delete_default
13+
from utilities.fs import (
14+
Config,
15+
concrete_read_config,
16+
read_config,
17+
write_config,
18+
write_default_config,
19+
save_credentials,
20+
)
21+
from utilities.web import (
22+
generate_mail,
23+
type_name,
24+
type_password,
25+
initial_setup,
26+
mail_login,
27+
get_mail,
28+
)
29+
from utilities.etc import (
30+
Credentials,
31+
p_print,
32+
clear_console,
33+
Colours,
34+
clear_tmp,
35+
reinstall_tenacity,
36+
check_for_updates,
37+
delete_default,
38+
)
1539

1640
# Spooky import to check if the correct version of tenacity is installed.
1741
if sys.version_info.major == 3 and sys.version_info.minor <= 11:
18-
try:
19-
from mega import Mega
20-
except AttributeError:
21-
reinstall_tenacity()
42+
try:
43+
pass
44+
except AttributeError:
45+
reinstall_tenacity()
2246

2347
default_installs = [
24-
"C:/Program Files/Google/Chrome/Application/chrome.exe",
25-
"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
26-
"C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe",
27-
"C:/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
28-
"C:/Program Files/Microsoft/Edge/Application/msedge.exe",
48+
"C:/Program Files/Google/Chrome/Application/chrome.exe",
49+
"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
50+
"C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe",
51+
"C:/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
52+
"C:/Program Files/Microsoft/Edge/Application/msedge.exe",
2953
]
3054
args = [
31-
"--no-sandbox",
32-
"--disable-setuid-sandbox",
33-
"--disable-infobars",
34-
"--window-position=0,0",
35-
"--ignore-certificate-errors",
36-
"--ignore-certificate-errors-spki-list",
37-
'--user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0"',
55+
"--no-sandbox",
56+
"--disable-setuid-sandbox",
57+
"--disable-infobars",
58+
"--window-position=0,0",
59+
"--ignore-certificate-errors",
60+
"--ignore-certificate-errors-spki-list",
61+
'--user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0"',
3862
]
3963

4064
parser = argparse.ArgumentParser()
41-
parser.add_argument('-ka', '--keepalive', required=False, action='store_true',
42-
help='Logs into the accounts to keep them alive.')
43-
parser.add_argument('-e', '--extract', required=False, action='store_true', help='Extracts the credentials to a file.')
44-
parser.add_argument('-v', '--verbose', required=False, action='store_true',
45-
help='Shows storage left while using keepalive function.')
46-
parser.add_argument('-f', '--file', required=False,
47-
help='Uploads a file to the account.')
48-
parser.add_argument('-p', '--public', required=False, action='store_true',
49-
help='Generates a public link to the uploaded file, use with -f')
50-
parser.add_argument('-l', '--loop', required=False,
51-
help="Loops the program for a specified amount of times.", type=int)
65+
parser.add_argument(
66+
"-ka",
67+
"--keepalive",
68+
required=False,
69+
action="store_true",
70+
help="Logs into the accounts to keep them alive.",
71+
)
72+
parser.add_argument(
73+
"-e",
74+
"--extract",
75+
required=False,
76+
action="store_true",
77+
help="Extracts the credentials to a file.",
78+
)
79+
parser.add_argument(
80+
"-v",
81+
"--verbose",
82+
required=False,
83+
action="store_true",
84+
help="Shows storage left while using keepalive function.",
85+
)
86+
parser.add_argument(
87+
"-f", "--file", required=False, help="Uploads a file to the account."
88+
)
89+
parser.add_argument(
90+
"-p",
91+
"--public",
92+
required=False,
93+
action="store_true",
94+
help="Generates a public link to the uploaded file, use with -f",
95+
)
96+
parser.add_argument(
97+
"-l",
98+
"--loop",
99+
required=False,
100+
help="Loops the program for a specified amount of times.",
101+
type=int,
102+
)
52103

53104
console_args = parser.parse_args()
54105

55106

56107
def setup() -> Tuple[str, Config]:
57-
"""Sets up the configs so everything runs smoothly."""
58-
59-
executable_path = ""
60-
config = read_config()
61-
62-
if config is None:
63-
write_default_config()
64-
config = concrete_read_config()
65-
else:
66-
executable_path = config.executablePath
67-
68-
# If no Chromium based browser is found, ask the user for the path to one.
69-
if not executable_path:
70-
p_print(
71-
"Failed to find a Chromium based browser. Please make sure you have one installed.", Colours.FAIL)
72-
executable_path = input(
73-
"Please enter the path to a Chromium based browser's executable: ")
74-
if os.path.exists(executable_path):
75-
p_print("Found executable!", Colours.OKGREEN)
76-
write_config("executablePath", executable_path, config)
77-
else:
78-
p_print("Failed to find executable!", Colours.FAIL)
79-
sys.exit(1)
80-
81-
return executable_path, config
108+
"""Sets up the configs so everything runs smoothly."""
109+
110+
executable_path = ""
111+
config = read_config()
112+
113+
if config is None:
114+
write_default_config()
115+
config = concrete_read_config()
116+
else:
117+
executable_path = config.executablePath
118+
119+
# If no Chromium based browser is found, ask the user for the path to one.
120+
if not executable_path:
121+
p_print(
122+
"Failed to find a Chromium based browser. Please make sure you have one installed.",
123+
Colours.FAIL,
124+
)
125+
executable_path = input(
126+
"Please enter the path to a Chromium based browser's executable: "
127+
)
128+
if os.path.exists(executable_path):
129+
p_print("Found executable!", Colours.OKGREEN)
130+
write_config("executablePath", executable_path, config)
131+
else:
132+
p_print("Failed to find executable!", Colours.FAIL)
133+
sys.exit(1)
134+
135+
return executable_path, config
82136

83137

84138
def loop_registrations(loop_count: int, executable_path: str, config: Config):
85-
"""Registers accounts in a loop."""
86-
for _ in range(loop_count):
87-
p_print(f"Loop {_ + 1}/{loop_count}", Colours.OKGREEN)
88-
clear_tmp()
139+
"""Registers accounts in a loop."""
140+
for _ in range(loop_count):
141+
p_print(f"Loop {_ + 1}/{loop_count}", Colours.OKGREEN)
142+
clear_tmp()
89143

90-
credentials = asyncio.run(generate_mail())
91-
asyncio.run(register(credentials, executable_path, config))
144+
credentials = asyncio.run(generate_mail())
145+
asyncio.run(register(credentials, executable_path, config))
92146

93147

94148
async def register(credentials: Credentials, executable_path: str, config: Config):
95-
"""Registers and verifies mega.nz account."""
96-
browser = await pyppeteer.launch({
97-
"headless": True,
98-
"ignoreHTTPSErrors": True,
99-
"userDataDir": f"{os.getcwd()}/tmp",
100-
"args": args,
101-
"executablePath": executable_path,
102-
"autoClose": False,
103-
"ignoreDefaultArgs": ["--enable-automation", "--disable-extensions"],
104-
})
105-
106-
context = await browser.createIncognitoBrowserContext()
107-
page = await context.newPage()
108-
109-
await type_name(page, credentials)
110-
await type_password(page, credentials)
111-
mail = await mail_login(credentials)
112-
113-
await asyncio.sleep(1.5)
114-
message = await get_mail(mail)
115-
116-
await initial_setup(context, message, credentials)
117-
await asyncio.sleep(0.5)
118-
await browser.close()
119-
120-
p_print("Verified account.", Colours.OKGREEN)
121-
p_print(
122-
f"Email: {credentials.email}\nPassword: {credentials.password}",
123-
Colours.OKCYAN,
124-
)
125-
126-
delete_default(credentials)
127-
save_credentials(credentials, config.accountFormat)
128-
129-
if console_args.file is not None:
130-
file_size = os.path.getsize(console_args.file)
131-
if os.path.exists(console_args.file) and 0 < file_size < 2e+10:
132-
if file_size >= 5e+9:
133-
p_print("File is larger than 5GB, mega.nz limits traffic to 5GB per IP.", Colours.WARNING)
134-
upload_file(console_args.public, console_args.file, credentials)
135-
else:
136-
p_print("File not found.", Colours.FAIL)
137-
if console_args.loop is None or console_args.loop <= 1:
138-
sys.exit(0)
149+
"""Registers and verifies mega.nz account."""
150+
browser = await pyppeteer.launch(
151+
{
152+
"headless": True,
153+
"ignoreHTTPSErrors": True,
154+
"userDataDir": f"{os.getcwd()}/tmp",
155+
"args": args,
156+
"executablePath": executable_path,
157+
"autoClose": False,
158+
"ignoreDefaultArgs": ["--enable-automation", "--disable-extensions"],
159+
}
160+
)
161+
162+
context = await browser.createIncognitoBrowserContext()
163+
page = await context.newPage()
164+
165+
await type_name(page, credentials)
166+
await type_password(page, credentials)
167+
mail = await mail_login(credentials)
168+
169+
await asyncio.sleep(1.5)
170+
message = await get_mail(mail)
171+
172+
await initial_setup(context, message, credentials)
173+
await asyncio.sleep(0.5)
174+
await browser.close()
175+
176+
p_print("Verified account.", Colours.OKGREEN)
177+
p_print(
178+
f"Email: {credentials.email}\nPassword: {credentials.password}",
179+
Colours.OKCYAN,
180+
)
181+
182+
delete_default(credentials)
183+
save_credentials(credentials, config.accountFormat)
184+
185+
if console_args.file is not None:
186+
file_size = os.path.getsize(console_args.file)
187+
if os.path.exists(console_args.file) and 0 < file_size < 2e10:
188+
if file_size >= 5e9:
189+
p_print(
190+
"File is larger than 5GB, mega.nz limits traffic to 5GB per IP.",
191+
Colours.WARNING,
192+
)
193+
upload_file(console_args.public, console_args.file, credentials)
194+
else:
195+
p_print("File not found.", Colours.FAIL)
196+
if console_args.loop is None or console_args.loop <= 1:
197+
sys.exit(0)
139198

140199

141200
if __name__ == "__main__":
142-
clear_console()
143-
check_for_updates()
144-
145-
executable_path, config = setup()
146-
if not executable_path:
147-
p_print("Failed while setting up!", Colours.FAIL)
148-
sys.exit(1)
149-
150-
if console_args.extract:
151-
extract_credentials(config.accountFormat)
152-
elif console_args.keepalive:
153-
keepalive(console_args.verbose)
154-
elif console_args.loop is not None and console_args.loop > 1:
155-
loop_registrations(console_args.loop, executable_path, config)
156-
else:
157-
clear_tmp()
158-
credentials = asyncio.run(generate_mail())
159-
asyncio.run(register(credentials, executable_path, config))
201+
clear_console()
202+
check_for_updates()
203+
204+
executable_path, config = setup()
205+
if not executable_path:
206+
p_print("Failed while setting up!", Colours.FAIL)
207+
sys.exit(1)
208+
209+
if console_args.extract:
210+
extract_credentials(config.accountFormat)
211+
elif console_args.keepalive:
212+
keepalive(console_args.verbose)
213+
elif console_args.loop is not None and console_args.loop > 1:
214+
loop_registrations(console_args.loop, executable_path, config)
215+
else:
216+
clear_tmp()
217+
credentials = asyncio.run(generate_mail())
218+
asyncio.run(register(credentials, executable_path, config))

0 commit comments

Comments
 (0)