From 1aab6b2bedde2bb2d97edd0c99d983e837b8f57b Mon Sep 17 00:00:00 2001 From: unkn0w7n <51942695+unkn0w7n@users.noreply.github.com> Date: Sun, 26 Nov 2023 16:34:45 +0530 Subject: [PATCH 1/2] Update infzm --- recipes/icons/ifzm.png | Bin 0 -> 726 bytes recipes/ifzm.recipe | 93 +++++++++++++++++++-------------------- recipes/singtaohk.recipe | 5 ++- 3 files changed, 50 insertions(+), 48 deletions(-) create mode 100644 recipes/icons/ifzm.png diff --git a/recipes/icons/ifzm.png b/recipes/icons/ifzm.png new file mode 100644 index 0000000000000000000000000000000000000000..1e660b740906b95894663a8785846d0c410402bc GIT binary patch literal 726 zcmV;{0xA88P)@(4yGRbW8k2Tc*C=3xZqXT^aB%>1XK{VTBTWNyDi=BLalE`YtY1tPV)B6zWI2+ zH}e})yvV)=p=E~-^0+IbgOcDLG7R;zhlO3F!> z)2iIRJEo0~^@0fz+?alB*Y%peFVsF;F6+_Wpx_m|+XR*ftW9PJiUO>xY#!{&`5f=E zExr4o#BDZn_UYn`MhNic!GUwLmCEt-;3Z!m*eO7>!wSPg9dJ}JpwrJox9AbxY-WYU zCuwJ>#{(Oi`|}K3<_toNFxYCj8lAa4O2K%Bw@d4LsFHXE2Q)D>cW#Xa&=+ISKnV<^ z7V8SQy^+h}4{!E8W(jb)TO4$Dq@6&asIh-Li09p2T|bGTff8WBCMNm?bUH29uJ!@n zOs|Ayy9F-vcwt9AgvrSP;V`d-(U+`6Rdb&8@Z^kd@9?$KY6PRBnO(K7lu!lqRap$` zga8!`M2QS{!KW_;R)gQskdb|`4k!)w5CZJ;j;!#$c9BqAXZ?MdmSKxr0XqP`b_a|{ zf}j+tu(h2dZlIYEw7DIr7p%`e{b?KO_d`x8(~{PAA@Mp(=bly$o;`nifH8PL2^hoX zJ~EQvt$&lx>{+#MK*+LR)f{KD%>7Eh=$S%>#TV8xjU-q=M9~n`rB^aMh_7Z^T-=hB zk_iFT0J)9y4E1{8;iJ{)^74jvYU-kZJjfR-z<2_wgmjR}7IG~-xAcBniDL{Vr&%~X zOp&k{){T>U*k`p=b>ggGk%cx#(#|!_ttIx-&Oe8#0rOw>?^q!lUgi3;(*OVf07*qo IM6N<$f|IpWF#rGn literal 0 HcmV?d00001 diff --git a/recipes/ifzm.recipe b/recipes/ifzm.recipe index 1ad2145878..a8f72c66f0 100644 --- a/recipes/ifzm.recipe +++ b/recipes/ifzm.recipe @@ -1,56 +1,55 @@ from calibre.web.feeds.news import BasicNewsRecipe +import json - -class AdvancedUserRecipe1277305250(BasicNewsRecipe): - title = u'infzm - China Southern Weekly' - oldest_article = 14 - max_articles_per_feed = 100 - - feeds = [(u'\u5357\u65b9\u5468\u672b-\u70ed\u70b9\u65b0\u95fb', u'http://www.infzm.com/rss/home/rss2.0.xml'), - (u'\u5357\u65b9\u5468\u672b-\u7ecf\u6d4e\u65b0\u95fb', - u'http://www.infzm.com/rss/economic.xml'), - (u'\u5357\u65b9\u5468\u672b-\u6587\u5316\u65b0\u95fb', - u'http://www.infzm.com/rss/culture.xml'), - (u'\u5357\u65b9\u5468\u672b-\u751f\u6d3b\u65f6\u5c1a', - u'http://www.infzm.com/rss/lifestyle.xml'), - (u'\u5357\u65b9\u5468\u672b-\u89c2\u70b9', - u'http://www.infzm.com/rss/opinion.xml') - ] - __author__ = 'rty' - __version__ = '1.0' +class infzm(BasicNewsRecipe): + title = '南方周末' + __author__ = 'unkn0wn' + description = 'Southern Weekly (infzm.com), founded in 1984, is a Chinese weekly newspaper based in Guangzhou. Download Weekly.' language = 'zh' - publisher = 'http://www.infzm.com' - description = 'Chinese Weekly Tabloid' - category = 'News, China' - remove_javascript = True - use_embedded_content = False + encoding = 'utf-8' no_stylesheets = True - encoding = 'UTF-8' - conversion_options = {'linearize_tables': True} - masthead_url = 'http://i50.tinypic.com/2qmfb7l.jpg' + remove_javascript = True + ignore_duplicate_articles = {'title'} + remove_empty_feeds = True + use_embedded_content = False + remove_attributes = ['style', 'height', 'width'] + + articles_are_obfuscated = True + + remove_tags = [dict(name=['video', 'svg', 'button'])] + + def get_obfuscated_article(self, url): + br = self.get_browser() + try: + br.open(url) + except Exception as e: + url = e.hdrs.get('location') + soup = self.index_to_soup(url) + link = soup.find('a', href=True)['href'].split('?')[0] + res_link = link.replace('https://www.infzm.com', 'https://api.infzm.com/mobile') \ + + '?platform=wap&version=1.89.0&machine_id=35458aa29603f2b246636e5492122b50&user_id=&token=&member_type=' + raw = br.open(res_link).read() + data = json.loads(raw) + data = data['data'] + content = data['content'] + title = '

'.format(link) + content['subject'] + '

' + auth = '

' + content['author'] + '

' + sub = '

' + content['introtext'] + '

' + body = content['fulltext'] + html = '
' + title + auth + body + '
' + return ({ 'data': html, 'url': link }) extra_css = ''' - @font-face { font-family: "DroidFont", serif, sans-serif; src: url(res:///system/fonts/DroidSansFallback.ttf); }\n - body { - margin-right: 8pt; - font-family: 'DroidFont', serif;} - .detailContent {font-family: 'DroidFont', serif, sans-serif} - ''' + img {display:block; margin:0 auto;} + .cm_pic_caption, .cm_pic_author { font-size:small; text-align:center; } + ''' - keep_only_tags = [ - dict(name='div', attrs={'id': 'detailContent'}), - ] - remove_tags = [ - dict(name='div', attrs={ - 'id': ['detailTools', 'detailSideL', 'pageNum']}), - ] - remove_tags_after = [ - dict(name='div', attrs={'id': 'pageNum'}), + feeds = [ + ('南方周末', 'https://news.google.com/rss/search?q=when:170h+allinurl:https%3A%2F%2Fwww.infzm.com&hl=zh-HK&gl=HK&ceid=HK:zh') ] - def preprocess_html(self, soup): - for item in soup.findAll(color=True): - del item['font'] - for item in soup.findAll(style=True): - del item['style'] - return soup + def populate_article_metadata(self, article, soup, first): + article.title = article.title.replace(' - 南方周末', '') + article.url = soup.find('h1')['title'] + article.summary = self.tag_to_string(soup.find(attrs={'class':'intro'})) + article.text_summary = self.tag_to_string(soup.find(attrs={'class':'intro'})) diff --git a/recipes/singtaohk.recipe b/recipes/singtaohk.recipe index 86137d1458..a1f8a41fea 100644 --- a/recipes/singtaohk.recipe +++ b/recipes/singtaohk.recipe @@ -5,12 +5,15 @@ class STHKRecipe(BasicNewsRecipe): __author__ = 'unkn0wn' description = 'The Sing Tao Daily is among Hong Kong\'s oldest Chinese language newspapers. (https://std.stheadline.com/)' category = 'Chinese, News, Hong Kong' + language = 'zh' + encoding = 'utf-8' masthead_url = 'https://std.stheadline.com/dist/images/logo-v2@2x.png' no_stylesheets = True remove_javascript = True ignore_duplicate_articles = {'title'} - resolve_internal_links = True remove_empty_feeds = True + use_embedded_content = False + remove_attributes = ['style', 'height', 'width'] extra_css = ''' img {display:block; margin:0 auto;} From 90967016cc2c73391b3304d21e187780a21f021a Mon Sep 17 00:00:00 2001 From: unkn0w7n <51942695+unkn0w7n@users.noreply.github.com> Date: Sun, 26 Nov 2023 17:33:05 +0530 Subject: [PATCH 2/2] ... --- recipes/ifzm.recipe | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/recipes/ifzm.recipe b/recipes/ifzm.recipe index a8f72c66f0..9d46bd6b84 100644 --- a/recipes/ifzm.recipe +++ b/recipes/ifzm.recipe @@ -1,6 +1,16 @@ from calibre.web.feeds.news import BasicNewsRecipe import json +def json_to_html(raw, link): + data = json.loads(raw) + data = data['data']['content'] + title = '

'.format(link) + data['subject'] + '

' + auth = '

' + data['author'] + '

' + sub = '

' + data['introtext'] + '

' + body = data['fulltext'] + return '
' + title + auth + sub + body + '
' + + class infzm(BasicNewsRecipe): title = '南方周末' __author__ = 'unkn0wn' @@ -13,6 +23,7 @@ class infzm(BasicNewsRecipe): remove_empty_feeds = True use_embedded_content = False remove_attributes = ['style', 'height', 'width'] + masthead_url = 'http://ssimg.kkod.cn/web/02/14227.gif' articles_are_obfuscated = True @@ -28,15 +39,9 @@ class infzm(BasicNewsRecipe): link = soup.find('a', href=True)['href'].split('?')[0] res_link = link.replace('https://www.infzm.com', 'https://api.infzm.com/mobile') \ + '?platform=wap&version=1.89.0&machine_id=35458aa29603f2b246636e5492122b50&user_id=&token=&member_type=' + # if article is paywalled, add code to figure out machine_id raw = br.open(res_link).read() - data = json.loads(raw) - data = data['data'] - content = data['content'] - title = '

'.format(link) + content['subject'] + '

' - auth = '

' + content['author'] + '

' - sub = '

' + content['introtext'] + '

' - body = content['fulltext'] - html = '
' + title + auth + body + '
' + html = json_to_html(raw, link) return ({ 'data': html, 'url': link }) extra_css = '''