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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from bs4 import BeautifulSoup
|
| 3 |
+
from fastapi import FastAPI, BackgroundTasks, HTTPException, Form
|
| 4 |
+
from fastapi.responses import PlainTextResponse, HTMLResponse
|
| 5 |
+
from fastapi.staticfiles import StaticFiles
|
| 6 |
+
from pydantic import BaseModel
|
| 7 |
+
import re
|
| 8 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 9 |
+
import urllib.parse
|
| 10 |
+
import gradio as gr
|
| 11 |
+
import fake_useragent as fake
|
| 12 |
+
import random
|
| 13 |
+
from dotenv import load_dotenv
|
| 14 |
+
import os
|
| 15 |
+
|
| 16 |
+
load_dotenv()
|
| 17 |
+
|
| 18 |
+
app = FastAPI()
|
| 19 |
+
|
| 20 |
+
class Proxy(BaseModel):
|
| 21 |
+
ip: str
|
| 22 |
+
port: str
|
| 23 |
+
|
| 24 |
+
class VisitRequest(BaseModel):
|
| 25 |
+
url: str
|
| 26 |
+
platform: str
|
| 27 |
+
count: int
|
| 28 |
+
delay: int
|
| 29 |
+
parallel_processes: int
|
| 30 |
+
|
| 31 |
+
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 32 |
+
|
| 33 |
+
def get_random_proxy():
|
| 34 |
+
pubproxy_url = "http://pubproxy.com/api/proxy?limit=1"
|
| 35 |
+
response = requests.get(pubproxy_url, verify=False)
|
| 36 |
+
data = response.json()
|
| 37 |
+
if data['data']:
|
| 38 |
+
proxy_data = data['data'][0]
|
| 39 |
+
return f"{proxy_data['ip']}:{proxy_data['port']}"
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
@app.get("/get_proxies", response_class=PlainTextResponse)
|
| 43 |
+
def get_proxies():
|
| 44 |
+
try:
|
| 45 |
+
proxies = []
|
| 46 |
+
pubproxy_url = "http://pubproxy.com/api/proxy?limit=5"
|
| 47 |
+
response = requests.get(pubproxy_url, verify=False)
|
| 48 |
+
data = response.json()
|
| 49 |
+
|
| 50 |
+
for proxy_data in data['data']:
|
| 51 |
+
ip, port = proxy_data['ipPort'].split(":")
|
| 52 |
+
proxy = f"{ip}:{port}"
|
| 53 |
+
proxies.append(proxy)
|
| 54 |
+
|
| 55 |
+
return "\n".join(proxies)
|
| 56 |
+
except Exception as e:
|
| 57 |
+
return PlainTextResponse(str(e), status_code=500)
|
| 58 |
+
|
| 59 |
+
@app.get("/rotate_ip", response_class=PlainTextResponse)
|
| 60 |
+
def rotate_ip():
|
| 61 |
+
try:
|
| 62 |
+
random_ip = fake.ipv4()
|
| 63 |
+
|
| 64 |
+
headers = {
|
| 65 |
+
"X-Forwarded-For": random_ip,
|
| 66 |
+
"Client-IP": random_ip,
|
| 67 |
+
"X-Real-IP": random_ip
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
test_url = "http://pubproxy.com/api/proxy?limit=1&type=http&https=true&speed=60"
|
| 71 |
+
response = requests.get(test_url, headers=headers, verify=False)
|
| 72 |
+
data = response.json()
|
| 73 |
+
|
| 74 |
+
proxies = []
|
| 75 |
+
for proxy_data in data['data']:
|
| 76 |
+
ip, port = proxy_data['ipPort'].split(":")
|
| 77 |
+
proxy = f"{ip}:{port}"
|
| 78 |
+
proxies.append(proxy)
|
| 79 |
+
|
| 80 |
+
return "\n".join(proxies)
|
| 81 |
+
except Exception as e:
|
| 82 |
+
return PlainTextResponse(str(e), status_code=500)
|
| 83 |
+
|
| 84 |
+
def extract_video_id(url: str, platform: str) -> str:
|
| 85 |
+
url = urllib.parse.unquote(url)
|
| 86 |
+
if platform == "instagram":
|
| 87 |
+
match = re.search(r"instagram\.com/reel/([^/?]+)", url)
|
| 88 |
+
elif platform == "tiktok":
|
| 89 |
+
match = re.search(r"tiktok\.com/@[^/]+/video/(\d+)", url)
|
| 90 |
+
elif platform == "youtube":
|
| 91 |
+
match = re.search(r"youtube\.com/watch\?v=([^&]+)", url)
|
| 92 |
+
elif platform == "facebook":
|
| 93 |
+
match = re.search(r"facebook\.com/.*/videos/(\d+)", url)
|
| 94 |
+
elif platform == "twitch":
|
| 95 |
+
match = re.search(r"twitch\.tv/videos/(\d+)", url)
|
| 96 |
+
elif platform == "spotify":
|
| 97 |
+
match = re.search(r"spotify\.com/track/([^/?]+)", url)
|
| 98 |
+
else:
|
| 99 |
+
match = None
|
| 100 |
+
|
| 101 |
+
if match:
|
| 102 |
+
return match.group(1)
|
| 103 |
+
else:
|
| 104 |
+
raise ValueError("Invalid URL format")
|
| 105 |
+
|
| 106 |
+
def instagram_login(username: str, password: str):
|
| 107 |
+
login_url = "https://www.instagram.com/accounts/login/ajax/"
|
| 108 |
+
session = requests.Session()
|
| 109 |
+
|
| 110 |
+
response = session.get("https://www.instagram.com/", headers={"User-Agent": "Mozilla/5.0"})
|
| 111 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
| 112 |
+
csrf_token = soup.find("meta", {"name": "csrf-token"})["content"]
|
| 113 |
+
|
| 114 |
+
login_data = {
|
| 115 |
+
"username": username,
|
| 116 |
+
"enc_password": f"#PWD_INSTAGRAM_BROWSER:0:&:{password}"
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
headers = {
|
| 120 |
+
"User-Agent": "Mozilla/5.0",
|
| 121 |
+
"X-CSRFToken": csrf_token,
|
| 122 |
+
"X-Requested-With": "XMLHttpRequest"
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
response = session.post(login_url, data=login_data, headers=headers)
|
| 126 |
+
|
| 127 |
+
if response.status_code == 200 and response.json().get("authenticated"):
|
| 128 |
+
return session
|
| 129 |
+
else:
|
| 130 |
+
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 131 |
+
|
| 132 |
+
def tiktok_login(username: str, password: str):
|
| 133 |
+
login_url = "https://www.tiktok.com/login/"
|
| 134 |
+
session = requests.Session()
|
| 135 |
+
|
| 136 |
+
login_data = {
|
| 137 |
+
"username": username,
|
| 138 |
+
"password": password
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
response = session.post(login_url, data=login_data)
|
| 142 |
+
|
| 143 |
+
if response.status_code == 200:
|
| 144 |
+
return session
|
| 145 |
+
else:
|
| 146 |
+
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 147 |
+
|
| 148 |
+
def youtube_login(username: str, password: str):
|
| 149 |
+
login_url = "https://accounts.google.com/ServiceLogin"
|
| 150 |
+
session = requests.Session()
|
| 151 |
+
|
| 152 |
+
login_data = {
|
| 153 |
+
"username": username,
|
| 154 |
+
"password": password
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
response = session.post(login_url, data=login_data)
|
| 158 |
+
|
| 159 |
+
if response.status_code == 200:
|
| 160 |
+
return session
|
| 161 |
+
else:
|
| 162 |
+
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 163 |
+
|
| 164 |
+
def facebook_login(username: str, password: str):
|
| 165 |
+
login_url = "https://www.facebook.com/login"
|
| 166 |
+
session = requests.Session()
|
| 167 |
+
|
| 168 |
+
login_data = {
|
| 169 |
+
"email": username,
|
| 170 |
+
"pass": password
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
response = session.post(login_url, data=login_data)
|
| 174 |
+
|
| 175 |
+
if response.status_code == 200:
|
| 176 |
+
return session
|
| 177 |
+
else:
|
| 178 |
+
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 179 |
+
|
| 180 |
+
def twitch_login(username: str, password: str):
|
| 181 |
+
login_url = "https://www.twitch.tv/login"
|
| 182 |
+
session = requests.Session()
|
| 183 |
+
|
| 184 |
+
login_data = {
|
| 185 |
+
"login": username,
|
| 186 |
+
"password": password
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
response = session.post(login_url, data=login_data)
|
| 190 |
+
|
| 191 |
+
if response.status_code == 200:
|
| 192 |
+
return session
|
| 193 |
+
else:
|
| 194 |
+
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 195 |
+
|
| 196 |
+
def spotify_login(username: str, password: str):
|
| 197 |
+
login_url = "https://accounts.spotify.com/api/token"
|
| 198 |
+
session = requests.Session()
|
| 199 |
+
|
| 200 |
+
login_data = {
|
| 201 |
+
"username": username,
|
| 202 |
+
"password": password
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
response = session.post(login_url, data=login_data)
|
| 206 |
+
|
| 207 |
+
if response.status_code == 200:
|
| 208 |
+
return session
|
| 209 |
+
else:
|
| 210 |
+
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 211 |
+
|
| 212 |
+
def simulate_instagram_view(video_id: str, proxy: str, session: requests.Session):
|
| 213 |
+
proxies = {
|
| 214 |
+
"http": f"http://{proxy}",
|
| 215 |
+
"https": f"http://{proxy}"
|
| 216 |
+
}
|
| 217 |
+
fake_ipv4 = fake.ipv4()
|
| 218 |
+
headers = {
|
| 219 |
+
"User-Agent": fake.user_agent(),
|
| 220 |
+
"X-Forwarded-For": fake_ipv4,
|
| 221 |
+
"Client-IP": fake_ipv4,
|
| 222 |
+
"X-Real-IP": fake_ipv4
|
| 223 |
+
}
|
| 224 |
+
try:
|
| 225 |
+
view_url = f"https://www.instagram.com/reel/{video_id}"
|
| 226 |
+
response = session.get(view_url, headers=headers, proxies=proxies)
|
| 227 |
+
embed_link = f"https://www.instagram.com/p/{video_id}/embed/"
|
| 228 |
+
embed_link_with_start = f"{embed_link}?start={rand(4, 8)}"
|
| 229 |
+
print(embed_link_with_start)
|
| 230 |
+
except Exception as e:
|
| 231 |
+
print(f"Error in simulate_instagram_view: {e}")
|
| 232 |
+
|
| 233 |
+
def simulate_tiktok_view(video_id: str, proxy: str, session: requests.Session):
|
| 234 |
+
proxies = {
|
| 235 |
+
"http": f"http://{proxy}",
|
| 236 |
+
"https": f"http://{proxy}"
|
| 237 |
+
}
|
| 238 |
+
fake_ipv4 = fake.ipv4()
|
| 239 |
+
headers = {
|
| 240 |
+
"User-Agent": fake.user_agent(),
|
| 241 |
+
"X-Forwarded-For": fake_ipv4,
|
| 242 |
+
"Client-IP": fake_ipv4,
|
| 243 |
+
"X-Real-IP": fake_ipv4
|
| 244 |
+
}
|
| 245 |
+
try:
|
| 246 |
+
view_url = f"https://www.tiktok.com/@user/video/{video_id}"
|
| 247 |
+
response = session.get(view_url, headers=headers, proxies=proxies)
|
| 248 |
+
embed_link = f"https://www.tiktok.com/embed/v/{video_id}"
|
| 249 |
+
embed_link_with_start = f"{embed_link}?start={rand(4, 8)}"
|
| 250 |
+
print(embed_link_with_start)
|
| 251 |
+
except Exception as e:
|
| 252 |
+
print(f"Error in simulate_tiktok_view: {e}")
|
| 253 |
+
|
| 254 |
+
def simulate_youtube_view(video_id: str, proxy: str, session: requests.Session):
|
| 255 |
+
proxies = {
|
| 256 |
+
"http": f"http://{proxy}",
|
| 257 |
+
"https": f"http://{proxy}"
|
| 258 |
+
}
|
| 259 |
+
fake_ipv4 = fake.ipv4()
|
| 260 |
+
headers = {
|
| 261 |
+
"User-Agent": fake.user_agent(),
|
| 262 |
+
"X-Forwarded-For": fake_ipv4,
|
| 263 |
+
"Client-IP": fake_ipv4,
|
| 264 |
+
"X-Real-IP": fake_ipv4
|
| 265 |
+
}
|
| 266 |
+
try:
|
| 267 |
+
view_url = f"https://www.youtube.com/watch?v={video_id}"
|
| 268 |
+
response = session.get(view_url, headers=headers, proxies=proxies)
|
| 269 |
+
embed_link = f"https://www.youtube.com/embed/{video_id}"
|
| 270 |
+
embed_link_with_start = f"{embed_link}?controls=0&start={rand(4, 8)}"
|
| 271 |
+
print(embed_link_with_start)
|
| 272 |
+
except Exception as e:
|
| 273 |
+
print(f"Error in simulate_youtube_view: {e}")
|
| 274 |
+
|
| 275 |
+
def simulate_facebook_view(video_id: str, proxy: str, session: requests.Session):
|
| 276 |
+
proxies = {
|
| 277 |
+
"http": f"http://{proxy}",
|
| 278 |
+
"https": f"http://{proxy}"
|
| 279 |
+
}
|
| 280 |
+
fake_ipv4 = fake.ipv4()
|
| 281 |
+
headers = {
|
| 282 |
+
"User-Agent": fake.user_agent(),
|
| 283 |
+
"X-Forwarded-For": fake_ipv4,
|
| 284 |
+
"Client-IP": fake_ipv4,
|
| 285 |
+
"X-Real-IP": fake_ipv4
|
| 286 |
+
}
|
| 287 |
+
try:
|
| 288 |
+
view_url = f"https://www.facebook.com/{video_id}"
|
| 289 |
+
response = session.get(view_url, headers=headers, proxies=proxies)
|
| 290 |
+
embed_link = f"https://www.facebook.com/plugins/video.php?href=https://www.facebook.com/{video_id}/&show_text=0&width=560&height=315"
|
| 291 |
+
embed_link_with_start = f"{embed_link}&start={rand(4, 8)}"
|
| 292 |
+
print(embed_link_with_start)
|
| 293 |
+
except Exception as e:
|
| 294 |
+
print(f"Error in simulate_facebook_view: {e}")
|
| 295 |
+
|
| 296 |
+
def simulate_twitch_view(video_id: str, proxy: str, session: requests.Session):
|
| 297 |
+
proxies = {
|
| 298 |
+
"http": f"http://{proxy}",
|
| 299 |
+
"https": f"http://{proxy}"
|
| 300 |
+
}
|
| 301 |
+
fake_ipv4 = fake.ipv4()
|
| 302 |
+
headers = {
|
| 303 |
+
"User-Agent": fake.user_agent(),
|
| 304 |
+
"X-Forwarded-For": fake_ipv4,
|
| 305 |
+
"Client-IP": fake_ipv4,
|
| 306 |
+
"X-Real-IP": fake_ipv4
|
| 307 |
+
}
|
| 308 |
+
try:
|
| 309 |
+
view_url = f"https://www.twitch.tv/videos/{video_id}"
|
| 310 |
+
response = session.get(view_url, headers=headers, proxies=proxies)
|
| 311 |
+
embed_link = f"https://player.twitch.tv/?video=v{video_id}&parent=www.example.com&autoplay=false&muted=false"
|
| 312 |
+
embed_link_with_start = f"{embed_link}&start={rand(4, 8)}"
|
| 313 |
+
print(embed_link_with_start)
|
| 314 |
+
except Exception as e:
|
| 315 |
+
print(f"Error in simulate_twitch_view: {e}")
|
| 316 |
+
|
| 317 |
+
def simulate_spotify_view(video_id: str, proxy: str, session: requests.Session):
|
| 318 |
+
proxies = {
|
| 319 |
+
"http": f"http://{proxy}",
|
| 320 |
+
"https": f"http://{proxy}"
|
| 321 |
+
}
|
| 322 |
+
fake_ipv4 = fake.ipv4()
|
| 323 |
+
headers = {
|
| 324 |
+
"User-Agent": fake.user_agent(),
|
| 325 |
+
"X-Forwarded-For": fake_ipv4,
|
| 326 |
+
"Client-IP": fake_ipv4,
|
| 327 |
+
"X-Real-IP": fake_ipv4
|
| 328 |
+
}
|
| 329 |
+
try:
|
| 330 |
+
view_url = f"https://open.spotify.com/track/{video_id}"
|
| 331 |
+
response = session.get(view_url, headers=headers, proxies=proxies)
|
| 332 |
+
embed_link = f"https://open.spotify.com/embed/track/{video_id}"
|
| 333 |
+
embed_link_with_start = f"{embed_link}?start={rand(4, 8)}"
|
| 334 |
+
print(embed_link_with_start)
|
| 335 |
+
except Exception as e:
|
| 336 |
+
print(f"Error in simulate_spotify_view: {e}")
|
| 337 |
+
|
| 338 |
+
def simulate_views(url: str, platform: str, count: int, delay: int, parallel_processes: int, session: requests.Session):
|
| 339 |
+
video_id = extract_video_id(url, platform)
|
| 340 |
+
proxy = get_random_proxy()
|
| 341 |
+
|
| 342 |
+
if not proxy:
|
| 343 |
+
print("No proxy available.")
|
| 344 |
+
return
|
| 345 |
+
|
| 346 |
+
with ThreadPoolExecutor(max_workers=parallel_processes) as executor:
|
| 347 |
+
for _ in range(count):
|
| 348 |
+
if platform == "instagram":
|
| 349 |
+
executor.submit(simulate_instagram_view, video_id, proxy, session)
|
| 350 |
+
elif platform == "tiktok":
|
| 351 |
+
executor.submit(simulate_tiktok_view, video_id, proxy, session)
|
| 352 |
+
elif platform == "youtube":
|
| 353 |
+
executor.submit(simulate_youtube_view, video_id, proxy, session)
|
| 354 |
+
elif platform == "facebook":
|
| 355 |
+
executor.submit(simulate_facebook_view, video_id, proxy, session)
|
| 356 |
+
elif platform == "twitch":
|
| 357 |
+
executor.submit(simulate_twitch_view, video_id, proxy, session)
|
| 358 |
+
elif platform == "spotify":
|
| 359 |
+
executor.submit(simulate_spotify_view, video_id, proxy, session)
|
| 360 |
+
|
| 361 |
+
@app.post("/simulate_views")
|
| 362 |
+
async def simulate_views_endpoint(request: VisitRequest):
|
| 363 |
+
try:
|
| 364 |
+
if os.getenv(f'{request.platform.upper()}_USER') and os.getenv(f'{request.platform.upper()}_PASSWORD'):
|
| 365 |
+
session = authenticate(os.getenv(f'{request.platform.upper()}_USER'), os.getenv(f'{request.platform.upper()}_PASSWORD'), request.platform)
|
| 366 |
+
simulate_views(
|
| 367 |
+
url=request.url,
|
| 368 |
+
platform=request.platform,
|
| 369 |
+
count=request.count,
|
| 370 |
+
delay=request.delay,
|
| 371 |
+
parallel_processes=request.parallel_processes,
|
| 372 |
+
session=session
|
| 373 |
+
)
|
| 374 |
+
return PlainTextResponse("Views simulation started")
|
| 375 |
+
else:
|
| 376 |
+
return PlainTextResponse("Credentials not found for this platform.")
|
| 377 |
+
except Exception as e:
|
| 378 |
+
return PlainTextResponse(str(e), status_code=500)
|
| 379 |
+
|
| 380 |
+
def authenticate(username: str, password: str, platform: str):
|
| 381 |
+
if platform == "instagram":
|
| 382 |
+
return instagram_login(username, password)
|
| 383 |
+
elif platform == "tiktok":
|
| 384 |
+
return tiktok_login(username, password)
|
| 385 |
+
elif platform == "youtube":
|
| 386 |
+
return youtube_login(username, password)
|
| 387 |
+
elif platform == "facebook":
|
| 388 |
+
return facebook_login(username, password)
|
| 389 |
+
elif platform == "twitch":
|
| 390 |
+
return twitch_login(username, password)
|
| 391 |
+
elif platform == "spotify":
|
| 392 |
+
return spotify_login(username, password)
|
| 393 |
+
else:
|
| 394 |
+
raise HTTPException(status_code=400, detail="Invalid platform")
|
| 395 |
+
|
| 396 |
+
@app.post("/login")
|
| 397 |
+
async def login(username: str = Form(...), password: str = Form(...), platform: str = Form(...)):
|
| 398 |
+
try:
|
| 399 |
+
session = authenticate(username, password, platform)
|
| 400 |
+
return PlainTextResponse(f"Authenticated on {platform}")
|
| 401 |
+
except HTTPException as e:
|
| 402 |
+
return e
|
| 403 |
+
|
| 404 |
+
def gradio_interface(file, platform, count, delay, parallel_processes):
|
| 405 |
+
try:
|
| 406 |
+
# Suponiendo que el archivo es un CSV con columnas: URL, Count, Delay, Parallel Processes
|
| 407 |
+
import pandas as pd
|
| 408 |
+
df = pd.read_csv(file)
|
| 409 |
+
|
| 410 |
+
if os.getenv(f'{platform.upper()}_USER') and os.getenv(f'{platform.upper()}_PASSWORD'):
|
| 411 |
+
session = authenticate(os.getenv(f'{platform.upper()}_USER'), os.getenv(f'{platform.upper()}_PASSWORD'), platform)
|
| 412 |
+
for index, row in df.iterrows():
|
| 413 |
+
try:
|
| 414 |
+
url = row['URL']
|
| 415 |
+
simulate_views(url, platform, count, delay, parallel_processes, session)
|
| 416 |
+
print(f"Simulation started for row {index}")
|
| 417 |
+
except Exception as e:
|
| 418 |
+
print(f"Error processing row {index}: {e}")
|
| 419 |
+
|
| 420 |
+
return "Simulation completed."
|
| 421 |
+
else:
|
| 422 |
+
return "Credentials not found for this platform."
|
| 423 |
+
except Exception as e:
|
| 424 |
+
return f"Error: {e}"
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
def rand(min, max):
|
| 428 |
+
return random.randint(min, max)
|
| 429 |
+
|
| 430 |
+
def run_simulation(file, platform, count, delay, parallel_processes):
|
| 431 |
+
try:
|
| 432 |
+
# Suponiendo que el archivo es un CSV con columnas: URL, Count, Delay, Parallel Processes
|
| 433 |
+
import pandas as pd
|
| 434 |
+
df = pd.read_csv(file)
|
| 435 |
+
|
| 436 |
+
if os.getenv(f'{platform.upper()}_USER') and os.getenv(f'{platform.upper()}_PASSWORD'):
|
| 437 |
+
session = authenticate(os.getenv(f'{platform.upper()}_USER'), os.getenv(f'{platform.upper()}_PASSWORD'), platform)
|
| 438 |
+
|
| 439 |
+
# Create a thread pool executor with maximum workers based on parallel_processes
|
| 440 |
+
with ThreadPoolExecutor(max_workers=parallel_processes) as executor:
|
| 441 |
+
for index, row in df.iterrows():
|
| 442 |
+
try:
|
| 443 |
+
url = row['URL']
|
| 444 |
+
|
| 445 |
+
# Execute the simulate_views function in a separate thread
|
| 446 |
+
executor.submit(simulate_views, url, platform, count, delay, parallel_processes, session)
|
| 447 |
+
|
| 448 |
+
print(f"Simulation started for row {index}")
|
| 449 |
+
except Exception as e:
|
| 450 |
+
print(f"Error processing row {index}: {e}")
|
| 451 |
+
|
| 452 |
+
return "Simulation completed."
|
| 453 |
+
else:
|
| 454 |
+
return "Credentials not found for this platform."
|
| 455 |
+
except Exception as e:
|
| 456 |
+
return f"Error: {e}"
|
| 457 |
+
|
| 458 |
+
gr.Interface(
|
| 459 |
+
fn=run_simulation,
|
| 460 |
+
inputs=[
|
| 461 |
+
gr.File(label="Upload CSV File"),
|
| 462 |
+
gr.Dropdown(choices=["instagram", "tiktok", "youtube", "facebook", "twitch", "spotify"], label="Platform"),
|
| 463 |
+
gr.Slider(minimum=1, maximum=1000, label="Count"),
|
| 464 |
+
gr.Slider(minimum=1, maximum=60, label="Delay (seconds)"),
|
| 465 |
+
gr.Slider(minimum=1, maximum=10, label="Parallel Processes")
|
| 466 |
+
],
|
| 467 |
+
outputs=gr.Textbox(label="Output")
|
| 468 |
+
).launch(share=True)
|