This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.py
196 lines (163 loc) · 8.19 KB
/
main.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import sys
try:
import os
import platform
import logging
import json
import threading
from threading import Semaphore
import colorama
from colorama import Fore
from colorama import init
colorama.init()
init(autoreset=True)
from captchatools import captcha_harvesters
from newegg.create_account import static_data
import time
except ModuleNotFoundError:
print("Make sure you ran pip3 install -r requirements.txt")
time.sleep(999)
sys.exit(0)
class Newegg:
def __init__(self):
self.screenlock = Semaphore(value=1)
# Load config
settings = self.load_settings()
self.settings = settings
if settings["captcha"]["captcha_solver"] == 1 or str( settings["captcha"]["captcha_solver"]).lower() == "capmonster":
api_key = settings["captcha"]["keys"]["capmonster"]
elif settings["captcha"]["captcha_solver"] == 2 or str( settings["captcha"]["captcha_solver"]).lower() == "anticaptcha":
api_key = settings["captcha"]["keys"]["anticaptcha"]
elif settings["captcha"]["captcha_solver"] == 3 or str( settings["captcha"]["captcha_solver"]).lower() == "2captcha":
api_key = settings["captcha"]["keys"]["2captcha"]
if settings["captcha"]["version"].lower() == "v3":
sitekey = static_data.v3_sitekey
elif settings["captcha"]["version"].lower() == "v2":
sitekey = static_data.v2_sitekey
self.captcha_solver = captcha_harvesters(
solving_site=settings["captcha"]["captcha_solver"],
api_key=api_key,
sitekey=sitekey,
captcha_url="https://secure.newegg.com/identity/signup?tk=",
min_score=0.7, action="Register", captcha_type=settings["captcha"]["version"]
)
# Start the bot when initialized.
self.main()
def main(self):
'''
Main method.
This method will be called (automatically) when the bot starts.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'''
# Get user input for what they want to do
print()
print(Fore.CYAN + '1' ,Fore.MAGENTA + "=", Fore.YELLOW + "Create Accounts")
print(Fore.CYAN + '2' ,Fore.MAGENTA + "=", Fore.YELLOW + "Submit Entries")
choice = eval(input("{}".format(Fore.MAGENTA + "Enter your choice: " + Fore.CYAN)))
if choice == 1:
self.create_accounts()
elif choice == 2:
self.submit_entries()
def load_settings(self):
# Some users said their program couldn't find the files
# So this is a quick fix to that.
original_path = os.getcwd()
os.chdir("./data/")
self.PATH_EMAILS = os.getcwd() + "\\emails.txt"
self.PATH_PROXIES = os.getcwd() + "\\proxies.txt"
if platform.system() == "Linux" or platform.system() == "Darwin":
self.PATH_EMAILS = self.PATH_EMAILS.replace("\\", "/")
self.PATH_PROXIES = self.PATH_PROXIES.replace("\\", "/")
# Open settings file
settings_file_path = os.getcwd() + "/settings.json"
os.chdir(original_path)
with open(settings_file_path) as settingsFile:
try:
return json.load(settingsFile)
except json.JSONDecodeError:
print(Fore.RED + "There is an error in your settings.json file." +
"Make sure the commas are correct and there aren't any extra commas!")
time.sleep(999)
sys.exit(0)
def create_accounts(self):
'''
This method will be called when the user wants to create Newegg Accounts.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It will pull emails from the /data/emails.txt folder and use those
to create the accounts
'''
from newegg.create_account import desktop, app, static_data
# Prompt for how many tasks
num_tasks = eval(input(Fore.BLUE + "\nEnter amount of tasks at a time: " + Fore.WHITE + " "))
self.sema = threading.Semaphore(value=num_tasks)
threads = []
# Start to create create accounts
with open(self.PATH_EMAILS) as email_file:
for line in email_file.readlines():
email = line.split(':')[0].strip("\n")
self.sema.acquire()
thread = threading.Thread(target=desktop.Create_Account,args=(self,email))
threads.append(thread)
thread.start()
def submit_entries(self):
'''
This method will be called when the user wants to enter the Newegg raffle.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It'll pull sessions from the file that the user used to create accounts
'''
from newegg.submit_raffle import raffles, app, desktop
path_to_created_accounts = os.getcwd() + "\\{}".format(self.settings["output_filename"]) if \
platform.system == "Windows" else os.getcwd() + "/{}".format(self.settings["output_filename"])
# Because Newegg still has V2 captcha enabled for submitting entries,
# we'll use that over V3. If for whatever reason you want to use V3,
# you would have to change this line of code.
self.captcha_solver.sitekey = "6Lcv-WUUAAAAAA9hyir8HPKZ44OvDLg1oZqnq_9d"
self.captcha_solver.captcha_type = "v2"
# Scrape & display raffle items
print()
print(Fore.YELLOW + "Getting items in raffle...")
items = raffles.get_items()
index = 0
for item in items:
print(Fore.GREEN + str(index) ,Fore.MAGENTA + "=", Fore.CYAN + "{} (${})".format( item["name"], item["price"]))
index +=1
# Get user choice(s) for the items they want to enter for
self.PRODUCTS_TO_ENTER = [] # This will be the array used to submit entries
choices = input(Fore.MAGENTA + "Enter the numbers of all the products you'd like to enter for, seperated by a space. (Example: 1 5 7 9 ): " + Fore.GREEN)
for choice in choices.split():
try:
self.PRODUCTS_TO_ENTER.append({"ItemNumber": items[eval(choice)]["id"]})
except Exception:
print(Fore.RED + f"There was an error with item: #{choice}. Skipping that item.")
# Show how many accounts have been made / are about to enter the raffle
print()
try:
with open(path_to_created_accounts) as email_file:
print( Fore.BLUE + "Amount of accounts loaded: {} ({})".format(
Fore.CYAN + str(len(email_file.readlines())),
self.settings["output_filename"])
)
except (FileExistsError, FileNotFoundError):
print(Fore.RED + "Could not find the file with sessions. Check repo fore help.")
time.sleep(100)
return
# Prompt how many tasks
num_tasks = eval(input(Fore.BLUE + "Enter amount of tasks at a time: " + Fore.WHITE + " "))
self.sema = threading.Semaphore(value=num_tasks)
threads = []
# Enter raffle
with open(path_to_created_accounts) as email_file: # Get the emails from the file the user named
for line in email_file.readlines():
if "error" not in line:
self.sema.acquire()
email = line.split(':')[2].strip("\n")
sessionData = json.loads(":".join(line.split(":")[3:]))
# If the acct was created via desktop, it will enter via that way
# If the acct was created via app, it will enter via that way
if sessionData["desktop"] == {}: # If there are no desktop cookies, means it was created via APP
task = threading.Thread(target=app.SubmitRaffle,args=(self,email, sessionData))
else:
task = threading.Thread(target=desktop.SubmitRaffle,args=(self,email, sessionData))
threads.append(task)
task.start()
Newegg()