fetcher = ProxyFetcher()
Browse files- App/Chat/PoeChatrouter.py +11 -2
App/Chat/PoeChatrouter.py
CHANGED
@@ -3,12 +3,11 @@ from .utils.PoeBot import SendMessage, GenerateImage
|
|
3 |
from .Schemas import BotRequest
|
4 |
from aiohttp import ClientSession
|
5 |
from pydantic import BaseModel
|
6 |
-
|
7 |
from ballyregan.models import Protocols, Anonymities
|
8 |
from ballyregan import ProxyFetcher
|
9 |
|
10 |
# Setting the debug mode to True, defaults to False
|
11 |
-
fetcher = ProxyFetcher()
|
12 |
|
13 |
|
14 |
chat_router = APIRouter(tags=["Chat"])
|
@@ -22,9 +21,19 @@ class InputData(BaseModel):
|
|
22 |
|
23 |
async def fetch_predictions(data):
|
24 |
global proxy
|
|
|
25 |
proxy_set = proxy != ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
if not proxy_set:
|
27 |
try:
|
|
|
28 |
proxies = fetcher.get(
|
29 |
limit=10,
|
30 |
protocols=[Protocols.HTTP],
|
|
|
3 |
from .Schemas import BotRequest
|
4 |
from aiohttp import ClientSession
|
5 |
from pydantic import BaseModel
|
6 |
+
import asyncio
|
7 |
from ballyregan.models import Protocols, Anonymities
|
8 |
from ballyregan import ProxyFetcher
|
9 |
|
10 |
# Setting the debug mode to True, defaults to False
|
|
|
11 |
|
12 |
|
13 |
chat_router = APIRouter(tags=["Chat"])
|
|
|
21 |
|
22 |
async def fetch_predictions(data):
|
23 |
global proxy
|
24 |
+
proxies = []
|
25 |
proxy_set = proxy != ""
|
26 |
+
if not asyncio.get_event_loop().is_running():
|
27 |
+
# If not, create a new event loop
|
28 |
+
loop = asyncio.new_event_loop()
|
29 |
+
asyncio.set_event_loop(loop)
|
30 |
+
else:
|
31 |
+
# If an event loop is already running, use the current one
|
32 |
+
loop = asyncio.get_event_loop()
|
33 |
+
fetcher = ProxyFetcher(loop=loop)
|
34 |
if not proxy_set:
|
35 |
try:
|
36 |
+
|
37 |
proxies = fetcher.get(
|
38 |
limit=10,
|
39 |
protocols=[Protocols.HTTP],
|