This repository has been archived by the owner on Nov 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathmultiprocess.py
169 lines (145 loc) · 7.01 KB
/
multiprocess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# -*- coding: utf-8 -*-
# multiprocess.py
"""
@author: Maxime Dréan.
Github: https://github.com/maximedrn
Telegram: https://t.me/maximedrn
"""
# Utils functions for GUI and CLI.
from app.utils.colors import GREEN, RED, YELLOW, RESET
from app.utils.const import ENTER, FIRST_PAGE, SECOND_PAGE
from app.utils.func import cls, exit
# Common functions for the metadata file.
from app.utils.values import UPLOAD, SALE, UPLOAD_AND_SALE
from app.common.reader import Reader
from app.common.structure import Structure
from app.common.save import Save
# Services functions for Upload/Sale process.
from app.services.webdriver import download_browser
# Main functions.
from main import user
# A Python default import.
from os import getcwd, chdir, system as ossystem
from multiprocessing import Process
from subprocess import Popen
from platform import system
from os.path import abspath
from sys import executable
from requests import post
from json import loads
from time import sleep
from math import ceil
# Mode and details constants.
MODE = {'1': 'upload', '2': 'sale', '1 2': 'upload_and_sale'}
DETAILS = {'1': UPLOAD, '2': SALE, '1 2': UPLOAD_AND_SALE}
def processes_number() -> int:
"""Ask the user for the number of processes."""
while True:
processes = input('\nHow many processes do you want to use? ')
if processes.isdigit() and 0 < int(processes) <= 5:
return int(processes)
print(f'{RED}Please enter a number between 1 and 5.{RESET}')
def split_file(file_path: str, part: int, processes: int,
action: list, action_str: str, starting: int) -> list:
"""Split the file in two files to multiprocess."""
print(f'\nCreation of part n°{part + 1}/{processes}.')
action_str = ''.join(action_str)
reader = Reader(file_path) # Send the file path.
structure = Structure(action, reader) # Send the action.
save = Save(structure) # Initialize the Save class.
# Get odd and even indexes of the file.
for number in range(part + starting, reader.length_file, processes):
text = f'Element n°{ceil(number / processes + 1)}/' + \
f'{ceil(reader.length_file / processes)}.'
print(text, end='\r') # Display the number of elements.
structure.get_data(number) # Structure metadata.
# Save it in a temporary file.
save.save(MODE[action_str], DETAILS[action_str], True)
print(f'{text} {GREEN}Done.{RESET}')
return eval(f'save.{MODE[action_str]}_file')
def command_line(wallet_name: str, password: str, recovery_phrase: str,
private_key: str, action: str, solver: int, key: str,
browser: int, file: str, browser_path: str,
system_password: str) -> None:
"""Open a command prompt and then start task.py."""
python = executable.replace('\\', '/') # Python path.
current = abspath(getcwd()).replace('\\', '/') # Work directory.
browser_path = browser_path.replace('\\', '/')
if solver == 4: # reCAPTCHA Bypasser.
from pickle import dumps # Create a copy of the class
from base64 import b64encode # and encode it.
key = str(b64encode(dumps(key)))[2:-1]
python_command = (
f'"{python}" task.py --wallet_name="{wallet_name}" '
f'--password="{password}" --recovery_phrase="{recovery_phrase}" '
f'--private_key="{private_key}" --action {action} '
f'--solver={solver if isinstance(solver, int) else 0} '
f'--key="{key}" --browser={browser} --file="{file}" '
f'--browser_path="{browser_path}"')
if system() == 'Darwin': # MacOS.
from appscript import app
python_command = python_command.replace('!', '\!')
app('Terminal').do_script(
f'echo "{system_password}" | sudo -i -S ; clear ;'
f' cd "{current}" ; sudo {python_command}')
elif system() == 'Windows': # Windows.
chdir(current) # Move to the bot path.
ossystem(f'start /wait cmd /c "{python_command}"')
elif system() == 'Linux': # Linux.
Popen(f'gnome-terminal --wait -- /bin/bash -c \'echo "'
f'{system_password}" | sudo -i -S ; cd "{current}" ; '
f'sudo {python_command}\'', shell=True)
def install_appscript(python: str) -> None:
print('\nInstalling the Appscript module.\n')
for command in (f'"{python}" -m pip', 'pip3'):
try:
ossystem(f'{command} install appscript')
return # Done.
except Exception:
continue # Retry a second time.
exit('\nCannot install the AppScript module.')
if __name__ == '__main__':
try:
cls() # Clear console.
print(FIRST_PAGE)
input(ENTER) # Press enter to continue.
cls() # Clear console.
print(SECOND_PAGE) # License and author.
# Get user informations and choices.
wallet_name, password, recovery_phrase, private_key, \
action, solver, key, browser, file, starting = user()
processes = processes_number() # Get the number of processes.
cls() # Clear console.
browser_path = download_browser(browser) # Download the webdriver.
if system() == 'Darwin': # Only for MacOS users.
try: # Try to import the Appscript module if it exists.
from appscript import app
except ImportError: # Install the Appscript module.
install_appscript(executable.replace('\\', '/'))
system_password = input(
'\nWhat is your system password to activate the administrator '
'privileges? ') if system() != 'Windows' else ''
if solver == 4: # reCAPTCHA Bypasser.
from app.services.solvers.solver import Solver
key = Solver(solver, key)
key.init_solver() # Send web instance.
tasks, action_str = [], ' '.join(str(element) for element in action)
for number in range(processes): # Multiprocessing.
task = Process(target=command_line, args=(
wallet_name, password, recovery_phrase, private_key,
action_str, solver, key, browser, split_file(
file, number, processes, action, action_str, starting)
if processes > 1 else file, browser_path, system_password))
tasks.append(task) # Add the task the the tasks list.
task.start() # Start the task in multiprocess.
if number != processes - 1: # Do not wait for the last process.
print('Waiting 10 seconds before starting the next task.')
sleep(10) # Wait 10 seconds before.
[task.join() for task in tasks]
print('\nYou can close this tab.')
except KeyboardInterrupt:
print(f'\n\n{YELLOW}The program has been '
f'stopped by the user.{RESET}')
except Exception as error:
print(f'{RED}Something went wrong.{RESET} \n{error}')
exit() # Exit the program.