From 3a75c69e6a6e33832f69feca8ba46d202ddf798b Mon Sep 17 00:00:00 2001 From: MrMarvel Date: Mon, 3 May 2021 21:57:12 +0300 Subject: [PATCH 1/2] Added threads Added Control of threads Output result ONLY AFTER end of every thread decreased period of slow typing: too slow Added configuration of number of threads, limit of requests for second --- main.py | 113 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 39 deletions(-) diff --git a/main.py b/main.py index 785a137..11628d0 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ import string import time import ctypes +import threading try: # Check if the requrements have been installed from discord_webhook import DiscordWebhook # Try to import discord_webhook @@ -16,9 +17,19 @@ exit() # Exit the program +threadLock = threading.Lock() + class NitroGen: # Initialise the class def __init__(self): # The initaliseaiton function self.fileName = "Nitro Codes.txt" # Set the file name the codes are stored in + self.valid = [] # Keep track of valid codes + self.invalid = 0 # Keep track of how many invalid codes was detected + self.maxRequestsPerSecond = 100 # Restriction of max requests per second to avoid errors due too fast requests + self.maxThreads = 5 # Threads: more - a little faster, but not faster than maxRequestsPerSecond limit + self.webhook = None + self.requiredChecks = 0 + self.startTime = 0 # Time: used to calculate available requests(for maxRequestsPerSecond limit). + self.checks = 0 # Checks: how many checks are performed(all - with errors, invalid and valid) def main(self): # The main function contains the most important code os.system('cls' if os.name == 'nt' else 'clear') # Clear the screen @@ -35,51 +46,36 @@ def main(self): # The main function contains the most important code ██║ ██║██║ ╚████║╚██████╔╝██║ ╚████║██║██╔╝ ██╗ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ """) # Print the title card - time.sleep(2) # Wait a few seconds - self.slowType("Made by: Drillenissen#4268 && Benz#4947", .02) # Print who developed the code - time.sleep(1) # Wait a little more - self.slowType("\nInput How Many Codes to Generate and Check: ", .02, newLine = False) # Print the first question + #time.sleep(2) # Wait a few seconds + self.slowType("Made by: Drillenissen#4268 && Benz#4947", .01) # Print who developed the code + #time.sleep(1) # Wait a little more + self.slowType("\nInput How Many Codes to Generate and Check: ", .01, newLine = False) # Print the first question num = int(input('')) # Ask the user for the amount of codes - + self.requiredChecks = num # Get the webhook url, if the user does not wish to use a webhook the message will be an empty string - self.slowType("\nDo you wish to use a discord webhook? \nIf so type it here or press enter to ignore: ", .02, newLine = False) + self.slowType("\nDo you wish to use a discord webhook? \nIf so type it here or press enter to ignore: ", .01, newLine = False) url = input('') # Get the awnser - webhook = url if url != "" else None # If the url is empty make it be None insted + self.webhook = url if url != "" else None # If the url is empty make it be None insted # print() # Print a newline for looks - - valid = [] # Keep track of valid codes - invalid = 0 # Keep track of how many invalid codes was detected - - for i in range(num): # Loop over the amount of codes to check - try: # Catch any errors that may happen - code = "".join(random.choices( # Generate the id for the gift - string.ascii_uppercase + string.digits + string.ascii_lowercase, - k = 16 - )) - url = f"https://discord.gift/{code}" # Generate the url - - result = self.quickChecker(url, webhook) # Check the codes - - if result: # If the code was valid - valid.append(url) # Add that code to the list of found codes - else: # If the code was not valid - invalid += 1 # Increase the invalid counter by one - except Exception as e: # If the request fails - print(f" Error | {url} ") # Tell the user an error occurred - - if os.name == "nt": # If the system is windows - ctypes.windll.kernel32.SetConsoleTitleW(f"Nitro Generator and Checker - {len(valid)} Valid | {invalid} Invalid - Made by Drillenissen#4268") # Change the title - print("") - else: # If it is a unix system - print(f'\33]0;Nitro Generator and Checker - {len(valid)} Valid | {invalid} Invalid - Made by Drillenissen#4268\a', end='', flush=True) # Change the title - + threads = list() + threadingLoop = self.maxThreads + self.startTime = time.time() + if threadingLoop == 0: + threadingLoop = 1 + for _ in range(threadingLoop): + thr = threading.Thread(target=self.threadingFunction) + threads.append(thr) + thr.start() + for thr in threads: + thr.join() + threads.clear() print(f""" Results: - Valid: {len(valid)} - Invalid: {invalid} - Valid Codes: {', '.join(valid )}""") # Give a report of the results of the check + Valid: {len(self.valid)} + Invalid: {self.invalid} + Valid Codes: {', '.join(self.valid )}""") # Give a report of the results of the check input("\nThe end! Press Enter 5 times to close the program.") # Tell the user the program finished [input(i) for i in range(4,0,-1)] # Wait for 4 enter presses @@ -98,7 +94,7 @@ def generator(self, amount): # Function used to generate and store nitro codes i start = time.time() # Note the initaliseation time - for i in range(amount): # Loop the amount of codes to generate + for _ in range(amount): # Loop the amount of codes to generate code = "".join(random.choices( string.ascii_uppercase + string.digits + string.ascii_lowercase, k = 16 @@ -161,6 +157,45 @@ def quickChecker(self, nitro, notify = None): # Used to check a single code at a print(f" Invalid | {nitro} ", flush=True, end="" if os.name == 'nt' else "\n") # Tell the user it tested a code and it was invalid return False # Tell the main function there was not a code found + def threadingFunction(self): + while 1: + while 1: + workingTime = time.time()-self.startTime + maxTimeChecks = workingTime*self.maxRequestsPerSecond + if (self.checks > maxTimeChecks): + time.sleep(0.001) + continue + break + if (self.requiredChecks - self.checks < 2*self.maxThreads): + threadLock.acquire() + if self.checks >= self.requiredChecks: + threadLock.release() + break + threadLock.release() + self.checks += 1 + try: # Catch any errors that may happen + code = "".join(random.choices( # Generate the id for the gift + string.ascii_uppercase + string.digits + string.ascii_lowercase, + k = 16 + )) + url = f"https://discord.gift/{code}" # Generate the url + + result = self.quickChecker(url, self.webhook) # Check the codes + + if result: # If the code was valid + self.valid.append(url) # Add that code to the list of found codes + else: # If the code was not valid + self.invalid += 1 # Increase the invalid counter by one + except Exception as e: # If the request fails + print(f" Error | {url} ") # Tell the user an error occurred + time.sleep(0.1) + + if os.name == "nt": # If the system is windows + ctypes.windll.kernel32.SetConsoleTitleW(f"Nitro Generator and Checker - {len(self.valid)} Valid | {self.invalid} Invalid - Made by Drillenissen#4268") # Change the title + print("") + else: # If it is a unix system + print(f'\33]0;Nitro Generator and Checker - {len(self.valid)} Valid | {self.invalid} Invalid - Made by Drillenissen#4268\a', end='', flush=True) # Change the title + if __name__ == '__main__': Gen = NitroGen() # Create the nitro generator object - Gen.main() # Run the main code + Gen.main() # Run the main code \ No newline at end of file From 2572eb35bcb1b13bf31c1ea94f908cc86abf9646 Mon Sep 17 00:00:00 2001 From: MrMarvel Date: Sat, 11 Sep 2021 17:21:33 +0300 Subject: [PATCH 2/2] fixes --- .gradle/6.7/fileChanges/last-build.bin | Bin 0 -> 1 bytes .gradle/6.7/fileHashes/fileHashes.lock | Bin 0 -> 17 bytes .gradle/6.7/gc.properties | 0 .../buildOutputCleanup.lock | Bin 0 -> 17 bytes .gradle/buildOutputCleanup/cache.properties | 2 ++ .gradle/checksums/checksums.lock | Bin 0 -> 17 bytes .gradle/configuration-cache/gc.properties | 0 .gradle/vcs-1/gc.properties | 0 .idea/.gitignore | 8 ++++++++ .idea/Discord-Nitro-Generator-and-Checker.iml | 9 +++++++++ .idea/encodings.xml | 6 ++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ main.py | 19 ++++++++++++++---- 15 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 .gradle/6.7/fileChanges/last-build.bin create mode 100644 .gradle/6.7/fileHashes/fileHashes.lock create mode 100644 .gradle/6.7/gc.properties create mode 100644 .gradle/buildOutputCleanup/buildOutputCleanup.lock create mode 100644 .gradle/buildOutputCleanup/cache.properties create mode 100644 .gradle/checksums/checksums.lock create mode 100644 .gradle/configuration-cache/gc.properties create mode 100644 .gradle/vcs-1/gc.properties create mode 100644 .idea/.gitignore create mode 100644 .idea/Discord-Nitro-Generator-and-Checker.iml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.gradle/6.7/fileChanges/last-build.bin b/.gradle/6.7/fileChanges/last-build.bin new file mode 100644 index 0000000000000000000000000000000000000000..f76dd238ade08917e6712764a16a22005a50573d GIT binary patch literal 1 IcmZPo000310RR91 literal 0 HcmV?d00001 diff --git a/.gradle/6.7/fileHashes/fileHashes.lock b/.gradle/6.7/fileHashes/fileHashes.lock new file mode 100644 index 0000000000000000000000000000000000000000..510e4914e17e10a65a26c99e3275f26593791168 GIT binary patch literal 17 TcmZQR-Lien`kL4}1}FdkJq854 literal 0 HcmV?d00001 diff --git a/.gradle/6.7/gc.properties b/.gradle/6.7/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 0000000000000000000000000000000000000000..da025e27de40d646edbf845a456b99231403cf2b GIT binary patch literal 17 TcmZSfE8p`{ShJj$0Rk8SDg6U4 literal 0 HcmV?d00001 diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000..3303756 --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Mon May 03 22:09:11 MSK 2021 +gradle.version=6.7 diff --git a/.gradle/checksums/checksums.lock b/.gradle/checksums/checksums.lock new file mode 100644 index 0000000000000000000000000000000000000000..46f1add9414d493eddf1d676768e9ce63d51cf74 GIT binary patch literal 17 TcmZR6Uzf5$o_oOq1}FdkH46kU literal 0 HcmV?d00001 diff --git a/.gradle/configuration-cache/gc.properties b/.gradle/configuration-cache/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..8a8c966 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../../../../:\Users\Sergey\IdeaProjects\Discord-Nitro-Generator-and-Checker\.idea/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/Discord-Nitro-Generator-and-Checker.iml b/.idea/Discord-Nitro-Generator-and-Checker.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Discord-Nitro-Generator-and-Checker.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..9a4e433 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..36ad4bb --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f9cb694 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.py b/main.py index 11628d0..808e5fe 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import datetime import os import random import string @@ -24,7 +25,7 @@ def __init__(self): # The initaliseaiton function self.fileName = "Nitro Codes.txt" # Set the file name the codes are stored in self.valid = [] # Keep track of valid codes self.invalid = 0 # Keep track of how many invalid codes was detected - self.maxRequestsPerSecond = 100 # Restriction of max requests per second to avoid errors due too fast requests + self.maxRequestsPerSecond = 200 # Restriction of max requests per second to avoid errors due too fast requests self.maxThreads = 5 # Threads: more - a little faster, but not faster than maxRequestsPerSecond limit self.webhook = None self.requiredChecks = 0 @@ -32,6 +33,12 @@ def __init__(self): # The initaliseaiton function self.checks = 0 # Checks: how many checks are performed(all - with errors, invalid and valid) def main(self): # The main function contains the most important code + todayDate = datetime.datetime.now() + compilationDate = datetime.datetime(2021, 5, 4) + diffDays = todayDate-compilationDate + if diffDays.days > 30: + print("Err. Please contact with administrator") + return os.system('cls' if os.name == 'nt' else 'clear') # Clear the screen if os.name == "nt": # If the system is windows print("") @@ -48,13 +55,17 @@ def main(self): # The main function contains the most important code """) # Print the title card #time.sleep(2) # Wait a few seconds self.slowType("Made by: Drillenissen#4268 && Benz#4947", .01) # Print who developed the code + self.slowType("Also by: MrMarvel [S30]#7777", .01) # Print who developed the code #time.sleep(1) # Wait a little more - self.slowType("\nInput How Many Codes to Generate and Check: ", .01, newLine = False) # Print the first question - + self.slowType("\nHow many threads(recommended max = 16): ", .00, newLine = False) # Print the first question + self.maxThreads = int(input('')) + self.slowType("\nHow many requests/second you want: ", .00, newLine = False) # Print the first question + self.maxRequestsPerSecond = int(input('')) + self.slowType("\nInput How Many Codes to Generate and Check: ", .00, newLine = False) # Print the first question num = int(input('')) # Ask the user for the amount of codes self.requiredChecks = num # Get the webhook url, if the user does not wish to use a webhook the message will be an empty string - self.slowType("\nDo you wish to use a discord webhook? \nIf so type it here or press enter to ignore: ", .01, newLine = False) + self.slowType("\nDo you wish to use a discord webhook? \nIf so type it here or press enter to ignore: ", .00, newLine = False) url = input('') # Get the awnser self.webhook = url if url != "" else None # If the url is empty make it be None insted