| 1 |
import json |
| 2 |
from collections import defaultdict |
| 3 |
from datetime import date |
| 4 |
|
| 5 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 6 |
|
| 7 |
# figure out your local edition id from the log of this recipe |
| 8 |
edi_id = 34 # HYDERABAD MAIN I - 34 |
| 9 |
|
| 10 |
today = date.today().strftime('%d/%m/%Y') |
| 11 |
|
| 12 |
# for older edition |
| 13 |
# today = '15/01/2024' |
| 14 |
|
| 15 |
day, month, year = (int(x) for x in today.split('/')) |
| 16 |
dt = date(year, month, day) |
| 17 |
today = today.replace('/', '%2F') |
| 18 |
|
| 19 |
index = 'https://epaper.andhrajyothy.com' |
| 20 |
|
| 21 |
|
| 22 |
class andhra(BasicNewsRecipe): |
| 23 |
title = 'ఆంధ్రజ్యోతి - తెలంగాణ' |
| 24 |
language = 'te' |
| 25 |
__author__ = 'unkn0wn' |
| 26 |
masthead_url = 'https://upload.wikimedia.org/wikipedia/commons/0/01/Andhra_Jyothi_newspaper_logo.png' |
| 27 |
timefmt = ' [' + dt.strftime('%b %d, %Y') + ']' |
| 28 |
description = 'Articles from the ABN Andhra Jyothy epaper, digital edition' |
| 29 |
encoding = 'utf-8' |
| 30 |
remove_empty_feeds = True |
| 31 |
|
| 32 |
def __init__(self, *args, **kwargs): |
| 33 |
BasicNewsRecipe.__init__(self, *args, **kwargs) |
| 34 |
if self.output_profile.short_name.startswith('kindle'): |
| 35 |
self.title = 'ఆంధ్రజ్యోతి ' + dt.strftime('%b %d, %Y') |
| 36 |
|
| 37 |
extra_css = ''' |
| 38 |
.cap { text-align:center; font-size:small; } |
| 39 |
img { display:block; margin:0 auto; } |
| 40 |
''' |
| 41 |
|
| 42 |
def parse_index(self): |
| 43 |
|
| 44 |
self.log('\n***\nif this recipe fails, report it on: https://www.mobileread.com/forums/forumdisplay.php?f=228\n***\n') |
| 45 |
|
| 46 |
get_edition = index + '/Home/GetEditionsHierarchy' |
| 47 |
edi_data = json.loads(self.index_to_soup(get_edition, raw=True)) |
| 48 |
self.log('## For your local edition id, modify this recipe to match your edi_id from the cities below\n') |
| 49 |
for edi in edi_data: |
| 50 |
if edi['org_location'] in {'Magazines', 'Navya Daily'}: |
| 51 |
continue |
| 52 |
self.log(edi['org_location']) |
| 53 |
cities = [] |
| 54 |
for edi_loc in edi['editionlocation']: |
| 55 |
cities.append(edi_loc['Editionlocation'] + ' - ' + edi_loc['EditionId']) |
| 56 |
self.log('\t', ',\n\t'.join(cities)) |
| 57 |
|
| 58 |
self.log('\nDownloading: Edition ID - ', edi_id) |
| 59 |
url = index + '/Home/GetAllpages?editionid=' + str(edi_id) + '&editiondate=' + today |
| 60 |
main_data = json.loads(self.index_to_soup(url, raw=True)) |
| 61 |
|
| 62 |
feeds_dict = defaultdict(list) |
| 63 |
|
| 64 |
for page in main_data: |
| 65 |
sec_name = page['PageNo'] + 'వ పేజీ' |
| 66 |
if page['PageNumber'] == 'Page 1': |
| 67 |
self.cover_url = page['HighResolution'] |
| 68 |
art = index + '/Home/getingRectangleObject?pageid=' + str(page['PageId']) |
| 69 |
raw2 = self.index_to_soup(art, raw=True) |
| 70 |
art_data = json.loads(raw2) |
| 71 |
for snaps in art_data: |
| 72 |
section = sec_name |
| 73 |
url = str(snaps['OrgId']) |
| 74 |
if snaps['ObjectType'] == 4: |
| 75 |
continue |
| 76 |
feeds_dict[section].append({'title': '', 'url': url}) |
| 77 |
return list(feeds_dict.items()) |
| 78 |
|
| 79 |
def preprocess_raw_html(self, raw, *a): |
| 80 |
data = json.loads(raw) |
| 81 |
body = '' |
| 82 |
for x in data['StoryContent']: |
| 83 |
if x['Headlines']: |
| 84 |
if len(x['Headlines']) > 0: |
| 85 |
body += '<h1>' + x['Headlines'][0].replace('\n', ' ') + '</h1>' |
| 86 |
for y in x['Headlines'][1:]: |
| 87 |
body += '<h4>' + y.replace('\n', ' ') + '</h4>' |
| 88 |
if data['LinkPicture']: |
| 89 |
for pics in data['LinkPicture']: |
| 90 |
if pics['fullpathlinkpic']: |
| 91 |
body += '<div><img src="{}"></div>'.format(pics['fullpathlinkpic']) |
| 92 |
if pics['caption']: |
| 93 |
body += '<div class="cap">' + pics['caption'] + '</div><p>' |
| 94 |
for x in data['StoryContent']: |
| 95 |
if x['Body'] and x['Body'] != '': |
| 96 |
body += '<span class="body">' + x['Body'] + '</span>' |
| 97 |
# if data['filepathstorypic']: # this gives you a snap image of the article from page |
| 98 |
# body += '<div><img src="{}"></div>'.format(data['filepathstorypic'].replace('\\', '/')) |
| 99 |
if body.strip() == '': |
| 100 |
self.abort_article('no article') |
| 101 |
return '<html><body><div>' + body + '</div></body></html>' |
| 102 |
|
| 103 |
def populate_article_metadata(self, article, soup, first): |
| 104 |
article.url = '***' |
| 105 |
h1 = soup.find('h1') |
| 106 |
h4 = soup.find('h4') |
| 107 |
body = soup.find(attrs={'class': 'body'}) |
| 108 |
if h4: |
| 109 |
article.summary = self.tag_to_string(h4) |
| 110 |
article.text_summary = article.summary |
| 111 |
elif body: |
| 112 |
article.summary = ' '.join(self.tag_to_string(body).split()[:15]) + '...' |
| 113 |
article.text_summary = article.summary |
| 114 |
article.title = 'ఆంధ్రజ్యోతి' |
| 115 |
if h1: |
| 116 |
article.title = self.tag_to_string(h1) |
| 117 |
elif body: |
| 118 |
article.title = ' '.join(self.tag_to_string(body).split()[:7]) + '...' |
| 119 |
|
| 120 |
def print_version(self, url): |
| 121 |
return index + '/User/ShowArticleView?OrgId=' + url |