diff --git a/config.py b/config.py index b61747ac..64aa4d94 100644 --- a/config.py +++ b/config.py @@ -21,6 +21,18 @@ # 图片压缩大小 kb * 1024 = MB ZIP_SIZE = 3 * 1024 +blockquote = True #是否显示转发的内容,默认打开 +showlottery = True #是否显示互动抽奖信息,默认打开 + +#使用百度翻译API 可选,填的话两个都要填,不填默认使用谷歌翻译(需墙外?) +# Baidu Translate API +UseBaidu = False +BaiduID = '' +BaiduKEY = '' +#百度翻译接口appid和secretKey,前往http://api.fanyi.baidu.com/获取 +#一般来说申请标准版免费就够了,想要好一点可以认证上高级版,有月限额,rss用也足够了 + + # 解决pixiv.cat无法访问问题 CLOSE_PIXIV_CAT = False # 是否关闭使用 pixiv.cat,关闭后必须启用代理 # 以下两项在关闭使用 pixiv.cat时有效,如果你有自己反代pixiv,填上你自己的反代服务器地址即可,没有不要填 @@ -37,4 +49,4 @@ # MYELF博客地址 https://myelf.club # 出现问题请在 GitHub 上提 issues # 项目地址 https://github.com/Quan666/ELF_RSS -# v1.3.5 +# v1.3.7 diff --git a/include/plugins/RSSHub/RSS_class.py b/include/plugins/RSSHub/RSS_class.py index dad96b75..6e2b7622 100644 --- a/include/plugins/RSSHub/RSS_class.py +++ b/include/plugins/RSSHub/RSS_class.py @@ -11,8 +11,9 @@ class rss: time=5 #更新频率 分钟/次 translation=False # 翻译 only_title=False #仅标题 + only_pic=False #仅图片 # 定义构造方法 - def __init__(self,name:str, url:str, user_id:str, group_id:str,time=5,img_proxy=False,notrsshub=False,translation=False,only_title=False): + def __init__(self,name:str, url:str, user_id:str, group_id:str,time=5,img_proxy=False,notrsshub=False,translation=False,only_title=False,only_pic=False): self.name = name self.url = url if user_id!='-1' : @@ -24,6 +25,7 @@ def __init__(self,name:str, url:str, user_id:str, group_id:str,time=5,img_proxy= self.img_proxy=img_proxy self.translation=translation self.only_title=only_title + self.only_pic=only_pic def geturl(self)->str: if self.notrsshub : diff --git a/include/plugins/RSSHub/rss_baidutrans.py b/include/plugins/RSSHub/rss_baidutrans.py new file mode 100644 index 00000000..8f180a10 --- /dev/null +++ b/include/plugins/RSSHub/rss_baidutrans.py @@ -0,0 +1,63 @@ +# coding: utf8 +''' + @Author: LCY + @Contact: lchuanyong@126.com + @blog: http://http://blog.csdn.net/lcyong_ + @Date: 2018-01-15 + @Time: 19:19 + 说明: appid和secretKey为百度翻译文档中自带的,需要切换为自己的 + python2和python3部分库名称更改对应如下: + httplib ----> http.client + md5 ----> hashlib.md5 + urllib.quote ----> urllib.parse.quote + 官方链接: + http://api.fanyi.baidu.com/api/trans/product/index + +''' + +import http.client +import hashlib +import json +import urllib +import random +import config + + +def baidu_translate(content): + appid = config.BaiduID + secretKey = config.BaiduKEY + httpClient = None + myurl = '/api/trans/vip/translate' + q = content + fromLang = 'jp' # 源语言 + toLang = 'zh' # 翻译后的语言 + salt = random.randint(32768, 65536) + sign = appid + q + str(salt) + secretKey + sign = hashlib.md5(sign.encode()).hexdigest() + myurl = myurl + '?appid=' + appid + '&q=' + urllib.parse.quote( + q) + '&from=' + fromLang + '&to=' + toLang + '&salt=' + str( + salt) + '&sign=' + sign + + try: + httpClient = http.client.HTTPConnection('api.fanyi.baidu.com') + httpClient.request('GET', myurl) + # response是HTTPResponse对象 + response = httpClient.getresponse() + jsonResponse = response.read().decode("utf-8") # 获得返回的结果,结果为json格式 + js = json.loads(jsonResponse) # 将json格式的结果转换字典结构 + dst = str(js["trans_result"][0]["dst"]) # 取得翻译后的文本结果 + return dst # 打印结果 + except Exception as e: + print(e) + finally: + if httpClient: + httpClient.close() + + +if __name__ == '__main__': + while True: + print("请输入要翻译的内容,如果退出输入q") + content = input() + if (content == 'q'): + break + baidu_translate(content) \ No newline at end of file diff --git a/include/plugins/RSSHub/rsshub.py b/include/plugins/RSSHub/rsshub.py index 208fdab8..0e174997 100644 --- a/include/plugins/RSSHub/rsshub.py +++ b/include/plugins/RSSHub/rsshub.py @@ -1,6 +1,6 @@ # -*- coding: UTF-8 -*- from io import BytesIO - +import unicodedata import feedparser import json import codecs @@ -23,6 +23,7 @@ from googletrans import Translator import emoji import socket +from retrying import retry # 存储目录 file_path = './data/' #代理 @@ -34,6 +35,7 @@ status_code=[200,301,302] # 去掉烦人的 returning true from eof_received() has no effect when using ssl httpx 警告 asyncio.log.logger.setLevel(40) +@retry async def getRSS(rss:RSS_class.rss)->list:# 链接,订阅名 #设置全局超时 以解决 feedparser.parse 遇到 bad url 时卡住 #socket.setdefaulttimeout(5000) @@ -53,8 +55,6 @@ async def getRSS(rss:RSS_class.rss)->list:# 链接,订阅名 r = await client.get(rss.geturl(),timeout=30) #print(rss.name+":"+str(r.status_code)+' 长度:'+str(len(r.content))) d = feedparser.parse(r.content) - #if(len(r.content)<3000): - # print(r.content) except BaseException as e: logger.error(e) if not rss.notrsshub and config.RSSHUB_backup: @@ -87,7 +87,7 @@ async def getRSS(rss:RSS_class.rss)->list:# 链接,订阅名 # print(Similarity.quick_ratio()) if Similarity.quick_ratio() <= 0.1: # 标题正文相似度 msg = msg + '标题:' + item['title'] + '\n' - msg = msg + '内容:' + await checkstr(item['summary'], rss.img_proxy, rss.translation) + '\n' + msg = msg + '内容:' + await checkstr(item['summary'], rss.img_proxy, rss.translation, rss.only_pic) + '\n' else: msg = msg + '标题:' + item['title'] + '\n' str_link = re.sub('member_illust.php\?mode=medium&illust_id=', 'i/', item['link']) @@ -145,6 +145,7 @@ async def sendMsg(rss,msg,bot): logger.info('发生错误 消息发送失败 E:'+str(e)) # 下载图片 +@retry async def dowimg(url:str,img_proxy:bool)->str: try: img_path = file_path + 'imgs' + os.sep @@ -236,8 +237,9 @@ async def zipPic(content,name): im.save(img_path + name + '.png', 'png') return name + '.png' + #处理正文 -async def checkstr(rss_str:str,img_proxy:bool,translation:bool)->str: +async def checkstr(rss_str:str,img_proxy:bool,translation:bool,only_pic:bool)->str: # 去掉换行 rss_str = re.sub('\n', '', rss_str) @@ -245,14 +247,22 @@ async def checkstr(rss_str:str,img_proxy:bool,translation:bool)->str: doc_rss = pq(rss_str) rss_str = str(doc_rss) + if config.showlottery == False: + if "互动抽奖" in rss_str: + logger.info("内容有互动抽奖,pass") + return + # 处理一些标签 + if config.blockquote == True: + rss_str = re.sub('
|', '', rss_str) + else: + rss_str = re.sub('
|
|', '', rss_str) rss_str = re.sub('
|
|