def test(url, rotate=False): result = web_2_album.get(url) suffix = '[source](%s)' % url if result.video: with open('tmp/video.mp4', 'wb') as f: f.write(cached_url.get(result.video, force_cache=True, mode='b')) group = [ InputMediaVideo(open('tmp/video.mp4', 'rb'), caption=cutCaption(result.cap, suffix, 1000), parse_mode='Markdown') ] return tele.bot.send_media_group(-1001198682178, group, timeout=20 * 60) imgs = pic_cut.getCutImages(result.imgs, 9) if imgs: imgs = pic_cut.getCutImages(result.imgs, 9) if rotate: for img_path in imgs: img = Image.open(img_path) img = img.rotate(180) img.save(img_path) group = [InputMediaPhoto(open(imgs[0], 'rb'), caption=cutCaption(result.cap, suffix, 1000), parse_mode='Markdown')] + \ [InputMediaPhoto(open(x, 'rb')) for x in imgs[1:]] return tele.bot.send_media_group(-1001198682178, group, timeout=20 * 60) tele.bot.send_message(-1001198682178, cutCaption(result.cap, suffix, 4000), timeout=20 * 60)
def processStatus(url, channels): if not db.existing.add(note): return result = web_2_album.get(url) for channel in channels: time.sleep(5) album_sender.send_v2(channel, result)
def log(item, result=''): if item.get('data-sid'): post_link = ('https://www.douban.com/people/%s/status/%s/' % (item['data-uid'], item['data-sid'])) else: dt = item['data-atype'] if dt == 'photo': dt = 'photo/album' post_link = 'https://www.douban.com/' + dt + '/' + item['data-aid'] if log_existing.contain(post_link): return if sum(dataCount(item)) < 20: return album_result = web_2_album.get(post_link, content = item) text = album_result.cap + getBlock(item) images = list(findImgs(item)) additional_text = '' if images: additional_text += ' '.join(images) + ' ' additional_text += findUser(item) + ' ' + findUserId(item) if result == 'sent': additional_text += ' douban_read_sent' if sum(dataCount(item)) > 200: additional_text += ' douban_read_please_review' time.sleep(5) try: logger.send_message(escapeMarkdown(text + '\n\n' + additional_text) + ' ' + post_link + ' [source](%s)' % post_link, parse_mode='markdown') except Exception as e: print('send markdown fail', str(e), text, additional_text, post_link) logger.send_message(text + '\n\n' + additional_text + ' ' + post_link) log_existing.add(post_link)
def getResult(post_link, item): r = web_2_album.get(post_link, content = item) url = getUrl(item, post_link) if url: r.cap = getCap(r.cap, url) return r if r.imgs or r.video or isUrl(r.cap): return r
def sendLink(site, link, fixed_channel = None): simplified = None telegraph = None album_result = None additional_info = getAdditionalInfo(site) channels = list(db.sub.channels(site, tele.bot)) message = link success = True for channel, config in channels: if fixed_channel and channel.id != fixed_channel: continue blocked_keys = getMatchedKey( link + export_to_telegraph.getTitle(link) + export_to_telegraph.getTitle(link, toSimplified=True), blocklist.get(channel.id, [])) if blocked_keys: message += ' filtered: ' + ' '.join(blocked_keys) continue if not album_result and '.douban.' in link and '/note/' not in link: album_result = web_2_album.get(link, force_cache = True) if album_result.imgs: album_result.cap = cutCaptionHtml(album_result.cap, 800) else: album_result.cap = cutCaptionHtml(album_result.cap, 2000) if not album_result and 'to_album' in config: album_result = export_to_telegraph.getAlbum(link) if not simplified and 'to_simplify' in config: simplified = export_to_telegraph.export(link, force_cache = True, force=True, toSimplified=True) or link if not telegraph and not album_result and 'to_telegraph' in config: telegraph = export_to_telegraph.export(link, force_cache = True, force=True) or link message = link if 'to_simplify' in config: message = simplified if 'to_telegraph' in config: message = telegraph try: if album_result: album_sender.send_v2(channel, album_result) else: channel.send_message(message + additional_info, parse_mode='HTML') except Exception as e: print(e) success = False debug_group.send_message('send fail: %s %d %s' % (link, channel.id, e)) log(message or link, site, [item[0] for item in channels]) return success
def sendLink(site, link, fixed_channel=None): simplified = None telegraph = None album_result = None sent = False for channel, config in db.sub.channels(site, tele.bot): if fixed_channel and channel.id != fixed_channel: continue if not simplified and 'to_simplify' in config: simplified = export_to_telegraph.export( link, force_cache=True, force=True, toSimplified=True) or link if '.douban.' in link and '/note/' not in link: album_result = web_2_album.get(link, force_cache=True) if not telegraph and not album_result and 'to_telegraph' in config: telegraph = export_to_telegraph.export( link, force_cache=True, force=True) or link message = link if 'to_simplify' in config: message = simplified if 'to_telegraph' in config: message = telegraph result = [1] * 10 try: if album_result: result = album_sender.send_v2(channel, album_result) else: result = [channel.send_message(message)] except Exception as e: print(e) debug_group.send_message('send fail: ' + str(channel.id) + ' ' + str(e)) finally: if sent: post_len = len(result) time.sleep((post_len**2) / 2 + post_len * 10) sent = True
def test(url, rotate=False): result = web_2_album.get(url) # print(list(result.cap)) album_sender.send_v2(chat, result, rotate=rotate)
def testAlbum(): url = 'https://www.pride.com/art/2018/5/10/photographer-empowering-trans-youth-through-art?fbclid=IwAR1WM82jyIovZRmLQwgJtBTExGGy-_py6SnOirDb2_IEjEAxxzqyKCjqLxY#media-gallery-media-1' print(web_2_album.get(url))