My issue is that it continues to be slow. I removed the links and cookies and some other stuff for privacy reasons but I want to know if the structure is the issue.
import asyncio, aiohttp, time, os
Results = None
Path = None
validPath = False
# Request Results
Valid = 0
Invalid = 0
# Request Variables
URL = ""
COOKIES = {
}
# Visuals
async def Reset():
os.system('cls' )
async def Error(ErrorMessage:str):
print(f"[-] {ErrorMessage}")
async def Path2List(Path:str):
global validPath, Results
try:
with open(Path, 'r') as file:
result = [line.strip() for line in file if line.strip()]
validPath = True
Results = result
Path = Path
except FileNotFoundError as error:
await Error(f"No such file or directory: '{Path}'")
time.sleep(5)
async def IndexResult(result:str):
with open("Test.txt", 'a') as file:
file.write(f"{result}\n")
async def UpdateCurrent():
Text = f"[+] {Valid} | [-] {Invalid}"
print(f"{Text:^126}", end="\r")
async def Request(Session, result:str):
global Valid, Invalid
async with Session.post(URL, data={"value": result}, cookies=COOKIES) as Request:
ResponseText = await Request.text()
if ResponseText == "true":
await IndexResult(result)
Valid += 1
elif ResponseText:
Invalid += 1
await UpdateCurrent()
async def main():
while not validPath:
await Reset()
print(f"{"Path":^91}")
Path = input(f" >>> ")
await Path2List(Path)
await Reset()
await UpdateCurrent()
async with aiohttp.ClientSession() as Session:
for result in Results:
if len(result) >= 4:
await Request(Session, result)
print(Results)
if __name__ == "__main__":
asyncio.run(main())```
This is my first attempt at switching from synchronous code and using requests to asyncio and aiohttp. It maintains a speed fairly similar to my original code being non-async.