Skip to content

Commit

Permalink
🐛 fixed copilot.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AirportR committed May 10, 2024
1 parent 6d7a73f commit 0be60ba
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions addons/builtin/copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@

import aiohttp
from loguru import logger
from utils import retry

# 解锁判定方式;目前Copilot除了极少数地区未提供支持,其他的几乎都支持。和节点质量关系并不大。
UNS_REGION = ["MY", "CV", "CN", "CU", "SR", "TL", "IR", 'CI', 'KP', 'PS', 'RU', 'SH', 'SY']
try:
from utils import retry
except ImportError:
def retry(_=3):
def wrapper(func):
async def inner(*args, **kwargs):
await func(*args, **kwargs)

return inner

return wrapper


@retry(3)
Expand All @@ -21,7 +32,7 @@ async def fetch_copilot(collector, session: aiohttp.ClientSession, proxy=None):
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0'
}
url = 'https://www.bing.com/search?q=bing'
url = 'https://www.bing.com/chat?toWww=1'
async with session.get(url, headers=headers, proxy=proxy, timeout=5) as resp:
if resp.history:
for i in resp.history:
Expand All @@ -30,8 +41,10 @@ async def fetch_copilot(collector, session: aiohttp.ClientSession, proxy=None):
return True
if resp.status == 200:
text = await resp.text()
# index = text.find("Copilot")
index = text.find("b-scopeListItem-conv")
index = text.find("b_wlcmPersLogo.copilot")
# print("b_wlcmPersLogo.copilot:", index)
collector.info['copilot'] = str(index)
# return True
try:
region = re.search(r'Region:"(\w\w)"', text).group(1)
# region2 = re.search(r'Region:"(.*)"', text).group(1)
Expand Down Expand Up @@ -81,4 +94,6 @@ async def demo():


if __name__ == "__main__":
asyncio.run(demo())
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(demo())

0 comments on commit 0be60ba

Please sign in to comment.