-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
79 lines (64 loc) · 2.62 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
import json
import random
import time
import concurrent.futures
import logger
import threading
import logging
from tapjoy.tapjoy import TapjoyManager
from offer.offerHandker import OfferHandler
from offer.offerCache import userManager
logger.logger.setLevel(logging.DEBUG)
random.seed(time.time())
PROXY_URL = f""
def handle_tapjoy(name: str, eid: str) -> None:
try:
proxy_url = PROXY_URL
manager = TapjoyManager(proxy_url, eid)
offers = manager.getOffers()
with open("files/response.html", "w", encoding="utf-8") as f:
f.write(manager.html_content)
threads = []
for offer in offers:
handler = OfferHandler(manager.ad_id, manager.proxy_str, name, offer)
thread = threading.Thread(target=handler.handleTask)
thread.start()
threads.append(thread)
except Exception as e:
logging.error(f"Error processing Tapjoy offers for {name}: {str(e)}")
def start_eid() -> None:
try:
with open("files/eid.json", "r") as f:
user_ids = json.load(f)
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
futures = [
executor.submit(handle_tapjoy, name, eid)
for name, eids in user_ids.items()
for eid in eids
]
for future in concurrent.futures.as_completed(futures):
try:
future.result()
except Exception as e:
logging.error(f"Thread execution failed: {str(e)}")
except json.JSONDecodeError as e:
logging.error(f"Error reading eid.json: {str(e)}")
except Exception as e:
logging.error(f"Unexpected error in start_eid: {str(e)}")
def start_added_task():
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
futures = []
cached_offers = userManager.getFreeOffers()
for name, offers in cached_offers.items():
for offer in offers:
from offer.offers import get_offer_by_name
offer_data = get_offer_by_name(offer.offerData.offerName)
if offer_data:
handler = OfferHandler(offer.ad_id, "", name, offer_data)
futures.append(executor.submit(handler.handleTask))
time.sleep(3)
for future in concurrent.futures.as_completed(futures):
try:
future.result()
except Exception as e:
logging.error(f"Thread execution failed: {str(e)}")