Update app.py
Browse files
app.py
CHANGED
|
@@ -529,7 +529,7 @@ def simulate_spotify_view(video_id: str, proxy: Proxy, session: requests.Session
|
|
| 529 |
finally:
|
| 530 |
driver.quit()
|
| 531 |
|
| 532 |
-
def simulate_views(url: str, platform: str, count: int, delay: int, parallel_processes: int, session: requests.Session):
|
| 533 |
video_id = extract_video_id(url, platform)
|
| 534 |
proxy = get_random_proxy()
|
| 535 |
if not proxy:
|
|
@@ -554,19 +554,20 @@ def simulate_views(url: str, platform: str, count: int, delay: int, parallel_pro
|
|
| 554 |
@app.post("/simulate_views")
|
| 555 |
async def simulate_views_endpoint(request: VisitRequest):
|
| 556 |
try:
|
|
|
|
| 557 |
if os.getenv(f'{request.platform.upper()}_USER') and os.getenv(f'{request.platform.upper()}_PASSWORD'):
|
| 558 |
session = authenticate(os.getenv(f'{request.platform.upper()}_USER'), os.getenv(f'{request.platform.upper()}_PASSWORD'), request.platform)
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
except Exception as e:
|
| 571 |
return PlainTextResponse(str(e), status_code=500)
|
| 572 |
|
|
@@ -597,16 +598,17 @@ async def login(username: str = Form(...), password: str = Form(...), platform:
|
|
| 597 |
@app.post("/simulate")
|
| 598 |
async def simulate(urls: str = Form(...), platform: str = Form(...), count: int = Form(...), delay: int = Form(...), parallel_processes: int = Form(...)):
|
| 599 |
try:
|
|
|
|
| 600 |
if os.getenv(f'{platform.upper()}_USER') and os.getenv(f'{platform.upper()}_PASSWORD'):
|
| 601 |
session = authenticate(os.getenv(f'{platform.upper()}_USER'), os.getenv(f'{platform.upper()}_PASSWORD'), platform)
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
except Exception as e:
|
| 611 |
return PlainTextResponse(str(e), status_code=500)
|
| 612 |
|
|
|
|
| 529 |
finally:
|
| 530 |
driver.quit()
|
| 531 |
|
| 532 |
+
def simulate_views(url: str, platform: str, count: int, delay: int, parallel_processes: int, session: requests.Session = None):
|
| 533 |
video_id = extract_video_id(url, platform)
|
| 534 |
proxy = get_random_proxy()
|
| 535 |
if not proxy:
|
|
|
|
| 554 |
@app.post("/simulate_views")
|
| 555 |
async def simulate_views_endpoint(request: VisitRequest):
|
| 556 |
try:
|
| 557 |
+
session = None
|
| 558 |
if os.getenv(f'{request.platform.upper()}_USER') and os.getenv(f'{request.platform.upper()}_PASSWORD'):
|
| 559 |
session = authenticate(os.getenv(f'{request.platform.upper()}_USER'), os.getenv(f'{request.platform.upper()}_PASSWORD'), request.platform)
|
| 560 |
+
|
| 561 |
+
simulate_views(
|
| 562 |
+
url=request.url,
|
| 563 |
+
platform=request.platform,
|
| 564 |
+
count=request.count,
|
| 565 |
+
delay=request.delay,
|
| 566 |
+
parallel_processes=request.parallel_processes,
|
| 567 |
+
session=session
|
| 568 |
+
)
|
| 569 |
+
return PlainTextResponse("Views simulation started")
|
| 570 |
+
|
| 571 |
except Exception as e:
|
| 572 |
return PlainTextResponse(str(e), status_code=500)
|
| 573 |
|
|
|
|
| 598 |
@app.post("/simulate")
|
| 599 |
async def simulate(urls: str = Form(...), platform: str = Form(...), count: int = Form(...), delay: int = Form(...), parallel_processes: int = Form(...)):
|
| 600 |
try:
|
| 601 |
+
session = None
|
| 602 |
if os.getenv(f'{platform.upper()}_USER') and os.getenv(f'{platform.upper()}_PASSWORD'):
|
| 603 |
session = authenticate(os.getenv(f'{platform.upper()}_USER'), os.getenv(f'{platform.upper()}_PASSWORD'), platform)
|
| 604 |
+
|
| 605 |
+
for index, url in enumerate(urls.split("\n")):
|
| 606 |
+
try:
|
| 607 |
+
simulate_views(url, platform, count, delay, parallel_processes, session)
|
| 608 |
+
except Exception as e:
|
| 609 |
+
pass
|
| 610 |
+
return PlainTextResponse("Simulation completed.")
|
| 611 |
+
|
| 612 |
except Exception as e:
|
| 613 |
return PlainTextResponse(str(e), status_code=500)
|
| 614 |
|