async def get_weibo_hot(group_id: int) -> list: weibo_hot_url = "http://api.weibo.cn/2/guest/search/hot/word" async with aiohttp.ClientSession() as session: async with session.get(url=weibo_hot_url) as resp: data = await resp.json() data = data["data"] text_list = [f"随机数:{random.randint(0,10000)}", "\n微博实时热榜:"] index = 0 for i in data: index += 1 text_list.append("\n%d.%s" % (index, i["word"])) text = "".join(text_list).replace("#", "") long_text_setting = await get_setting(group_id, "longTextType") if long_text_setting == "img": img = text2piiic(string=text, poster="", length=max(len(x) for x in text.split("\n"))) img.save("./statics/temp/tempWeibo.png") return [ "None", MessageChain.create( [Image.fromLocalFile("./statics/temp/tempWeibo.png")]) ] elif long_text_setting == "text": return ["None", MessageChain.create([Plain(text=text)])] else: return [ "None", MessageChain.create([Plain(text="数据库 longTextType 项出错!请检查!")]) ]
async def get_jlu_csw_notice(group_id: int) -> list: """ Get JLU CSW notice Args: group_id: Group id Examples: msg = await get_jlu_csw_notice() Return: [ str: Auxiliary treatment to be done(Such as add statement), MessageChain: Message to be send(MessageChain) ] """ url = "https://api.sagiri-web.com/JLUCSWNotice/" async with aiohttp.ClientSession() as session: async with session.get(url=url) as resp: res = await resp.json() data = res["data"] content = "----------------------------------\n" for i in range(10): content += f"{data[i]['title']}\n" content += f"{data[i]['href']}\n" content += f" {data[i]['time'].replace('-', '.')}\n" content += "----------------------------------\n" long_text_setting = await get_setting(group_id, "longTextType") if long_text_setting == "img": img = text2piiic(string=content, poster="", length=max(len(x) for x in content.split("\n"))) img.save("./statics/temp/tempJLUCSWNotice.png") return [ "None", MessageChain.create([ Image.fromLocalFile("./statics/temp/tempJLUCSWNotice.png") ]) ] elif long_text_setting == "text": return [ "None", MessageChain.create([ Plain(text=content) ]) ] else: return [ "None", MessageChain.create([ Plain(text="数据库 longTextType 项出错!请检查!") ]) ]
async def formatted_output_bangumi(days: int, group_id: int) -> list: """ Formatted output json data Args: days: The number of days to output(1-7) group_id: Group id Examples: data_str = formatted_output_bangumi(7) Return: str: formatted """ formatted_bangumi_data = await get_formatted_new_bangumi_json() temp_output_substring = ["------BANGUMI------\n\n"] now = datetime.datetime.now() for index in range(days): temp_output_substring.append(now.strftime("%m-%d")) temp_output_substring.append("即将播出:") for data in formatted_bangumi_data[index]: temp_output_substring.append( "\n%s %s %s\n" % (data["pub_time"], data["title"], data["pub_index"])) # temp_output_substring.append("url:%s\n" % (data["url"])) temp_output_substring.append("\n\n----------------\n\n") now += datetime.timedelta(days=1) long_text_setting = await get_setting(group_id, "longTextType") content = "".join(temp_output_substring) if long_text_setting == "img": img = text2piiic( string=content, poster="", length=int( max(count_len(line) for line in content.split("\n")) / 2)) img.save("./statics/temp/tempBungumiTimeTable.png") return [ "None", MessageChain.create([ Image.fromLocalFile("./statics/temp/tempBungumiTimeTable.png") ]) ] elif long_text_setting == "text": return ["None", MessageChain.create([Plain(text=content)])] else: return [ "None", MessageChain.create([Plain(text="数据库 longTextType 项出错!请检查!")]) ]
async def get_zhihu_hot(group_id: int) -> list: zhihu_hot_url = "https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=50&desktop=true" async with aiohttp.ClientSession() as session: async with session.get(url=zhihu_hot_url) as resp: data = await resp.json() print(data) data = data["data"] text_list = [f"随机数:{random.randint(0,10000)}", "\n知乎实时热榜:"] index = 0 for i in data: index += 1 text_list.append("\n%d. %s" % (index, i["target"]["title"])) text = "".join(text_list).replace("#", "") long_text_setting = await get_setting(group_id, "longTextType") if long_text_setting == "img": img = text2piiic(string=text, poster="", length=int(max(count_len(line) for line in text.split("\n")) / 2)) img.save("./statics/temp/tempZhihu.png") return [ "None", MessageChain.create([ Image.fromLocalFile("./statics/temp/tempZhihu.png") ]) ] elif long_text_setting == "text": return [ "None", MessageChain.create([ Plain(text=text) ]) ] else: return [ "None", MessageChain.create([ Plain(text="数据库 longTextType 项出错!请检查!") ]) ]
async def search_magnet_old(keyword: str, group_id: int) -> list: url = f"https://btsow.com/search/{keyword}" headers = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", "referer": f"https://btsow.com/search/{keyword}" } print(url) proxy = await get_proxy() proxies = { "http": f"http://{proxy['proxy']}" } if proxy.get("proxy") else None print("proxy:", proxies) try: async with aiohttp.ClientSession() as session: async with session.get(url=url, headers=headers, proxy=proxies["http"]) as resp: html = await resp.text() except (aiohttp.client_exceptions.ClientHttpProxyError, aiohttp.client_exceptions.ClientProxyConnectionError, aiohttp.client_exceptions.ClientOSError, TypeError): return [ "quoteSource", MessageChain.create([Plain(text="Proxy Error!")]) ] # print("html:", html) if not html: return ["None", MessageChain.create([Plain("IP可能被屏蔽!")])] records = list() soup = BeautifulSoup(html, "html.parser") data = soup.find("div", { "class": "data-list" }).find_all("div", {"class": "row"}) count = 0 for div in data: count += 1 if count > 5: break record = dict() # print(div) try: record["link"] = div.find("a", href=True)["href"] async with aiohttp.ClientSession() as session: async with session.get(url=record["link"]) as resp: magnet_html = await resp.text() # print(magnet_html) record["magnet"] = re.findall( r'<textarea id="magnetLink" name="magnetLink" class="magnet-link hidden-xs" readonly>(.*?)</textarea>', magnet_html, re.S)[0] record["title"] = div.find("a").find("div", { "class": "file" }).get_text() record["size"] = div.find("div", {"class": "size"}).get_text() record["date"] = div.find("div", {"class": "date"}).get_text() records.append(record) except TypeError: pass text = "--------------------\n搜索到结果:\n" for data in records: text += f"标题:{data['title']}\n" text += f"大小:{data['size']}\n" text += f"日期:{data['date']}\n" text += f"磁力:{data['magnet']}\n" text += "--------------------\n" long_text_setting = await get_setting(group_id, "longTextType") if long_text_setting == "img": img = text2piiic(string=text, poster="", length=max(len(x) for x in text.split("\n"))) img.save("./statics/temp/tempMagnet.png") return [ "quoteSource", MessageChain.create( [Image.fromLocalFile("./statics/temp/tempMagnet.png")]) ] elif long_text_setting == "text": return ["quoteSource", MessageChain.create([Plain(text=text)])] else: return [ "None", MessageChain.create([Plain(text="数据库 longTextType 项出错!请检查!")]) ]
async def search_magnet(keyword: str, group_id: int, audio: bool = False, video: bool = False, app: bool = False, games: bool = False, p**n: bool = False): args = "100,200,300,400,500" if not audio: args = args.replace("100,", "") if not video: args = args.replace("200,", "") if not app: args = args.replace("300,", "") if not games: args = args.replace("400,", "") if not p**n: if len(args) == 3: args = "0" else: args = args.replace(",500", "") url = f"https://tpb.party/search/{keyword}/1/99/{args}" print(url) headers = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" } async with aiohttp.ClientSession() as session: async with session.get(url=url, headers=headers) as resp: html = await resp.text() soup = BeautifulSoup(html, "html.parser") data = soup.find("table").find_all("tr") divs = [] for i in data: div = i.find("div", {"class": "detName"}) if div: if div and div.find("a").get_text() not in divs: divs.append(div) records = [] count = 0 for i in divs: count += 1 if count > 5: break record = {"title": i.get_text().strip()} print(record["title"]) record["href"] = i.find("a", href=True)["href"] async with aiohttp.ClientSession() as session: async with session.get(url=record["href"], headers=headers) as resp: html_torrent = await resp.text() soup_torrent = BeautifulSoup(html_torrent, "html.parser") record["magnet"] = soup_torrent.find("div", { "class": "download" }).find_all("a", href=True)[0]["href"] records.append(record) text = "--------------------\n搜索到结果:\n" for data in records: text += f"标题:{data['title']}\n" text += f"磁力:{data['magnet']}\n" text += "--------------------\n" long_text_setting = await get_setting(group_id, "longTextType") if long_text_setting == "img": img = text2piiic(string=text, poster="", length=max(len(x) for x in text.split("\n"))) img.save("./statics/temp/tempMagnet.png") return [ "quoteSource", MessageChain.create([ Plain( text= "为防止tx吞超长文本及封禁此账号,已将链接转为图片格式,请自行使用OCR(有毅力的也可以手打)获取链接!\n"), Image.fromLocalFile("./statics/temp/tempMagnet.png") ]) ] elif long_text_setting == "text": return ["quoteSource", MessageChain.create([Plain(text=text)])] else: return [ "None", MessageChain.create([Plain(text="数据库 longTextType 项出错!请检查!")]) ]
async def get_abbreviation_explain(abbreviation: str, group_id: int) -> list: url = "https://lab.magiconch.com/api/nbnhhsh/guess" headers = { "referer": "https://lab.magiconch.com/nbnhhsh/" } data = { "text": abbreviation } async with aiohttp.ClientSession() as session: async with session.post(url=url, headers=headers, data=data) as resp: res = await resp.json() # print(res) result = "可能的结果:\n\n" has_result = False for i in res: if "trans" in i: if i["trans"]: has_result = True result += f"{i['name']} => {','.join(i['trans'])}\n\n" else: result += f"{i['name']} => 没找到结果!\n\n" else: if i["inputting"]: has_result = True result += f"{i['name']} => {','.join(i['inputting'])}\n\n" else: result += f"{i['name']} => 没找到结果!\n\n" long_text_setting = await get_setting(group_id, "longTextType") if has_result: if long_text_setting == "img": img = text2piiic(string=result, poster="", length=max(len(x) for x in result.split("\n"))) img.save("./statics/temp/tempAbbreviation.png") return [ "quoteSource", MessageChain.create([ Image.fromLocalFile("./statics/temp/tempAbbreviation.png") ]) ] elif long_text_setting == "text": return [ "quoteSource", MessageChain.create([ Plain(text=result) ]) ] else: return [ "None", MessageChain.create([ Plain(text="数据库 longTextType 项出错!请检查!") ]) ] else: return [ "quoteSource", MessageChain.create([ Plain(text="没有找到结果哦~") ]) ]