def test_get_page(self):
     t = TelegraphPoster(use_api=True)
     page = t.get_page('Test-html-telegraph-poster-Page-02-17', return_content=True)
     self.assertEqual(page['title'], 'Test html telegraph poster Page')
     self.assertEqual(page['path'], 'Test-html-telegraph-poster-Page-02-17')
     self.assertTrue('content' in page)
     self.assertTrue('html' in page)
 def test_get_account_info(self):
     t = TelegraphPoster(use_api=True,
                         access_token=self.sandbox_access_token)
     acc_info = t.get_account_info(
         fields=['short_name', 'author_url', 'page_count'])
     self.assertTrue('page_count' in acc_info)
     self.assertEqual(acc_info['short_name'], 'Sandbox')
Example #3
0
async def tele_text(message: Message):
    """Paste on Telegra.ph"""
    start = time.time()
    replied = message.reply_to_message
    if not replied:
        await message.err("Reply To Message First !", del_in=5)
        return
    if not replied.text:
        await message.err("Replied Message Doesn't Contain Text. ­Ъце", del_in=5)
        return
    await message.edit("Pasting...")
    t = TelegraphPoster(use_api=True)
    t.create_api_token('USERGE-X')
    user = await userge.get_me()
    if user.username:
        user_n = f"@{user.username}"
    else:
        user_n = user.first_name
    text = replied.text
    title = message.input_str
    if not title:
        title = f"By {user_n}"
    link = t.post(title=title, author=user_n, text=text)
    msg = "**Pasted to -** "
    msg += f"<a href={link['url']}>{link['path']}</a>\n"
    end = time.time()
    total = "{:.2f}".format(end - start)
    msg += f"in <code>{total}</code> sec"
    await message.edit(msg,  disable_web_page_preview=True)
Example #4
0
async def ofox_(message: Message):
    if not message.input_str:
        await message.err("Provide a device codename to search recovery",
                          del_in=2)
        return
    t = TelegraphPoster(use_api=True)
    t.create_api_token('Userge-X')
    await message.edit("🔍 searching for recovery...", del_in=2)
    photo = "https://i.imgur.com/582uaSk.png"
    API_HOST = 'https://api.orangefox.download/v2/device/'
    codename = message.input_str
    try:
        cn = requests.get(f"{API_HOST}{codename}")
        r = cn.json()
    except ValueError:
        await message.err(f"recovery not found for {codename}!", del_in=3)
        return
    s = requests.get(f"{API_HOST}{codename}/releases/stable/last").json()
    info = f"📱 **Device**: {r['fullname']}\n"
    info += f"👤 **Maintainer**: {r['maintainer']['name']}\n\n"
    recovery = f"🦊 <code>{s['file_name']}</code>\n"
    recovery += f"📅 {s['date']}\n"
    recovery += f"ℹ️ **Version:** {s['version']}\n"
    recovery += f"📌 **Build Type:** {s['build_type']}\n"
    recovery += f"🔰 **Size:** {s['size_human']}\n\n"
    recovery += "📍 **Changelog:**\n"
    recovery += f"<code>{s['changelog']}</code>\n\n"
    msg = info
    msg += recovery
    notes_ = s.get('notes')
    if notes_:
        notes = t.post(title='READ Notes', author="", text=notes_)
        msg += f"🗒️ <a href={notes['url']}>NOTES</a>\n"
    msg += f"⬇️ <a href={s['url']}>DOWNLOAD</a>"
    await userge.send_photo(message.chat.id, photo=photo, caption=msg)
def _getPoster():
    global token
    if token:
        return TelegraphPoster(access_token=token)
    p = TelegraphPoster()
    r = p.create_api_token('export_to_telegraph', 'export_to_telegraph')
    token = r['access_token']
    return p
Example #6
0
def _getPoster():
	global token
	if token:
		return TelegraphPoster(access_token = token)
	p = TelegraphPoster()
	r = p.create_api_token('title_finder', 'title_finder')
	token = r['access_token']
	return p
 def test_edit_account_info(self):
     t = TelegraphPoster(use_api=True)
     t.create_api_token('SandboxTest', author_url='https://google.com/')
     acc_info = t.edit_account_info(short_name='Sandbox',
                                    author_name='aaa',
                                    author_url='https://telegram.org/')
     self.assertEqual(acc_info['short_name'], 'Sandbox')
     self.assertEqual(acc_info['author_url'], 'https://telegram.org/')
Example #8
0
def make_html_telegraph(title, author, text):
    client = TelegraphPoster(use_api=True)
    client.create_api_token(title)
    page = client.post(title=title,
                       author=author,
                       author_url="https://t.me/lvufrvrbby",
                       text=text)
    return page["url"]
 def test_post(self):
     t = TelegraphPoster()
     result = t.post('test_no_api0201', 'unit_test', '<p>first para</p>')
     self.assertTrue(
         'url' in result and
         'path' in result and
         'tph_uuid' in result and
         'page_id' in result
     )
Example #10
0
def post_to_telegraph(anime_title, html_format_content):
    post_client = TelegraphPoster(use_api=True)
    auth_name = "@projectdils"
    bish = "https://t.me/projectdils"
    post_client.create_api_token(auth_name)
    post_page = post_client.post(
        title=anime_title, author=auth_name, author_url=bish, text=html_format_content
    )
    return post_page["url"]
def get_telegraph_token(msg):
    from_id, name, username = get_from(msg)
    fid = str(from_id)
    if fid in telegraph_tokens:
        p = TelegraphPoster(access_token=telegraph_tokens[fid])
    else:
        p = TelegraphPoster()
        r = p.create_api_token(name, username)
        telegraph_tokens[fid] = r['access_token']
    send_auth_url(msg, p)
Example #12
0
def post_to_tp(a_title, content):
    """ Create a Telegram Post using HTML Content """
    post_client = TelegraphPoster(use_api=True)
    auth_name = "@PhycoNinja13b"
    post_client.create_api_token(auth_name)
    post_page = post_client.post(title=a_title,
                                 author=auth_name,
                                 author_url="https://t.me/PhycoNinja13b",
                                 text=content)
    return post_page['url']
Example #13
0
def msgTelegraphToken(msg):
	user_id = msg.from_user.id
	if user_id in TELEGRAPH_TOKENS:
		p = TelegraphPoster(access_token = TELEGRAPH_TOKENS[user_id])
	else:
		p = TelegraphPoster()
		r = p.create_api_token(msg.from_user.first_name, msg.from_user.username)
		TELEGRAPH_TOKENS[user_id] = r['access_token']
		saveTelegraphTokens()
	msgAuthUrl(msg, p)
Example #14
0
def post_to_telegraph(a_title: str, content: str) -> str:
    """ Create a Telegram Post using HTML Content """
    post_client = TelegraphPoster(use_api=True)
    auth_name = "@theUserge"
    post_client.create_api_token(auth_name)
    post_page = post_client.post(title=a_title,
                                 author=auth_name,
                                 author_url="https://t.me/theUserge",
                                 text=content)
    return post_page['url']
Example #15
0
async def post_to_telegraph(page_title, html_format_content):
    post_client = TelegraphPoster(use_api=True)
    auth_name = "LEGEND"
    post_client.create_api_token(auth_name)
    post_page = post_client.post(
        title=page_title,
        author=auth_name,
        author_url="https://t.me/LEGEND_USERBOT_SUPPORT",
        text=html_format_content,
    )
    return post_page["url"]
 def test_api_token(self):
     t = TelegraphPoster(use_api=True)
     result = t.create_api_token('teleposter_test', 'tele_author_test')
     self.assertEqual(
         'teleposter_test',
         result['short_name']
     )
     self.assertEqual(
         'tele_author_test',
         result['author_name']
     )
Example #17
0
 def test_api(self):
     html = '<p>test paragraph</p>'
     t = TelegraphPoster(use_api=True,
                         access_token=self.sandbox_access_token)
     result = t.post('test_page0201', 'au', html)
     self.assertTrue('url' in result)
     self.assertTrue('path' in result)
     result2 = t.edit('test_edit_page04', 'au_edit', '<p>edit test</p>')
     self.assertTrue('url' in result)
     self.assertTrue('path' in result)
     self.assertEqual(result['path'], result2['path'])
Example #18
0
def msgTelegraphToken(msg):
    source_id, shortname, longname = getSource(msg)
    if source_id in telegraph_tokens:
        p = TelegraphPoster(access_token=telegraph_tokens[source_id])
    else:
        p = TelegraphPoster()
        r = p.create_api_token(shortname, longname)
        telegraph_tokens[source_id] = r['access_token']
        saveTelegraphTokens()
    if source_id not in no_auth_link_users:
        msgAuthUrl(msg, p)
Example #19
0
async def post_to_telegraph(page_title, html_format_content):
    post_client = TelegraphPoster(use_api=True)
    auth_name = "CatUserbot"
    post_client.create_api_token(auth_name)
    post_page = post_client.post(
        title=page_title,
        author=auth_name,
        author_url="https://t.me/catuserbot17",
        text=html_format_content,
    )
    return post_page["url"]
Example #20
0
async def post_to_telegraph(page_title, html_format_content):
    post_client = TelegraphPoster(use_api=True)
    auth_name = "@mrdurden"
    post_client.create_api_token(auth_name)
    post_page = post_client.post(
        title=page_title,
        author=auth_name,
        author_url="https://t.me/mrxdurden",
        text=html_format_content
    )
    return post_page['url']
Example #21
0
def post_to_telegraph(a_title: str, content: str) -> str:
    """Create a Telegram Post using HTML Content"""
    post_client = TelegraphPoster(use_api=True)
    auth_name = "𝚙𝙾𝚙ʑ𝓩​🍁™"
    post_client.create_api_token(auth_name)
    post_page = post_client.post(
        title=a_title,
        author=auth_name,
        author_url="http://t.me/aj_pOpzZ",
        text=content,
    )
    return post_page["url"]
Example #22
0
def post_to_telegraph(a_title: str, content: str) -> str:
    """ Create a Telegram Post using HTML Content """
    post_client = TelegraphPoster(use_api=True)
    auth_name = "slam-mirrorbot"
    post_client.create_api_token(auth_name)
    post_page = post_client.post(
        title=a_title,
        author=auth_name,
        author_url="https://github.com/breakdowns/slam-mirrorbot",
        text=content,
    )
    return post_page["url"]
Example #23
0
def post_to_telegraph(title, html_format_content):
    post_client = TelegraphPoster(use_api=True)
    auth_name = "King-Userbot"
    auth_url = "https://github.com/apisuserbot/King-Userbot"
    post_client.create_api_token(auth_name)
    post_page = post_client.post(
        title=title,
        author=auth_name,
        author_url=auth_url,
        text=html_format_content,
    )
    return post_page["url"]
Example #24
0
def post_to_telegraph(a_title: str, content: str) -> str:
    """ Create a Telegram Post using HTML Content """
    post_client = TelegraphPoster(use_api=True)
    auth_name = "Torrent-Bot-LazyLeech"
    post_client.create_api_token(auth_name)
    post_page = post_client.post(
        title=a_title,
        author=auth_name,
        author_url="https://t.me/WeebZoneIndia",
        text=content,
    )
    return post_page["url"]
Example #25
0
def post_to_telegraph(title, html_format_content):
    post_client = TelegraphPoster(use_api=True)
    auth_name = "WeebProject"
    auth_url = "https://github.com/BianSepang/WeebProject"
    post_client.create_api_token(auth_name)
    post_page = post_client.post(
        title=title,
        author=auth_name,
        author_url=auth_url,
        text=html_format_content,
    )
    return post_page["url"]
Example #26
0
def post_to_telegraph(a_title: str, content: str) -> str:
    """ Create a Telegram Post using HTML Content """
    post_client = TelegraphPoster(use_api=True)
    auth_name = "USERGE-𝑿"
    post_client.create_api_token(auth_name)
    post_page = post_client.post(
        title=a_title,
        author=auth_name,
        author_url="https://t.me/x_xtest",
        text=content,
    )
    return post_page["url"]
Example #27
0
def translate(link):
    global url
    global text_nodes
    global text_strings
    global markup

    dest = "en"
    url = link
    parser = HtmlParser()
    response = requests.get(url)
    doc = Document(response.text)
    # tree = fromstring(r.content)
    title = doc.title()  # tree.findtext('.//title')
    lang = translator.detect(title).lang
    if lang == 'en':
        # print("The article appears to be in English already.")
        return 'null'
    title = translator.translate(title).text
    content = doc.summary()
    # print(content)
    soup = bs(content, 'lxml')
    text = str(soup.find('body'))
    # text = r.text.split('<body')[1].split('</body>')[0]
    repls = ('h1>', 'h3>'), ('h2>', 'h3>'), ('<h1', '<h3'), ('<h2', '<h3')
    text = reduce(lambda a, kv: a.replace(*kv), repls, text)
    text = emoji.get_emoji_regexp().sub(r'', text)  # removing the emojis
    # print(text)
    parser.feed(text)
    # print("text_nodes: ", text_nodes)
    # print(text_strings)
    # print(text)
    # print(markup)
    # print("STARTING TO TRANSLATE...", url)
    translations = translator.translate(text_strings, dest=str(dest))
    final_payload = []
    for translation in translations:
        scheme = [translation.text]
        # print(translation.origin, ' -> ', scheme[0])
        final_payload.extend(scheme)
    markup = markup.format(*final_payload)
    markup = re.sub(r'\s([?.!"](?:\s|$))', r'\1', markup)
    print("\n")
    # print(markup)
    access_token = os.environ.get("access_token")
    t = TelegraphPoster(
        access_token=access_token)
    article = t.post(title=str(title), author='lulz', text=str(markup))
    x = str(article).replace("'", '"')
    article = json.loads(x)
    text = "Your article is ready to read! {}".format(article['url'])
    return text
Example #28
0
async def ofox_(message):
    if not message.pattern_match.group(1):
        await edit_or_reply(message,
                            "`Provide a device codename to search recovery`")
        await asyncio.sleep(3)
        await message.delete()
        return
    t = TelegraphPoster(use_api=True)
    t.create_api_token('PepeBot')
    await edit_or_reply(message, "🔍 `Searching for recovery...`")
    await asyncio.sleep(2)
    await message.delete()
    photo = "https://i.imgur.com/582uaSk.png"
    API_HOST = 'https://api.orangefox.download/v2/device/'
    codename = message.pattern_match.group(1)
    try:
        cn = get(f"{API_HOST}{codename}")
        r = cn.json()
    except ValueError:
        await edit_or_reply(message, f"`Recovery not found for {codename}!`")
        await asyncio.sleep(3)
        await message.delete()
        return
    s = get(f"{API_HOST}{codename}/releases/stable/last").json()
    info = f"📱 <b>Device:</b> {r['fullname']}\n"
    info += f"👤 <b>Maintainer:</b> {r['maintainer']['name']}\n\n"
    recovery = f"🦊 <code>{s['file_name']}</code>\n"
    recovery += f"📅 {s['date']}\n"
    recovery += f"ℹ️ <b>Version:</b> {s['version']}\n"
    recovery += f"📌 <b>Build Type:</b> {s['build_type']}\n"
    recovery += f"🔰 <b>Size:</b> {s['size_human']}\n\n"
    recovery += "📍 <b>Changelog:</b>\n"
    recovery += f"<code>{s['changelog']}</code>\n\n"
    msg = info
    msg += recovery
    notes_ = s.get('notes')
    if notes_:
        notes = t.post(title='READ Notes', author="", text=notes_)
        msg += f"🗒️ <a href={notes['url']}>NOTES</a>\n"
    msg += f"⬇️ <a href={s['url']}>DOWNLOAD</a>"
    await borg.send_file(message.chat_id,
                         file=photo,
                         caption=msg,
                         parse_mode='HTML')
Example #29
0
def export(url,
           throw_exception=False,
           force=False,
           toSimplified=False,
           force_cache=False,
           noSourceLink=False,
           noAutoConvert=False):
    try:
        url = clearUrl(url)
        if not force and not isConfidentUrl(url):
            return
        p = _getPoster()
        if not force and _isEditable(p, url):
            return url
        article = getArticle(url,
                             throw_exception,
                             toSimplified=toSimplified,
                             force_cache=force_cache,
                             noAutoConvert=noAutoConvert)
        if not article.text or not article.text.text.strip():
            article.text = '<div>TO BE ADDED</div>'
        try:
            r = p.post(title=article.title,
                       author=getAuthorField(article.author, noSourceLink),
                       author_url=getAuthorUrl(article, url, noSourceLink),
                       text=str(article.text))
        except Exception as e:
            if 'CONTENT_TEXT_REQUIRED' in str(e):
                r = p.post(title=article.title,
                           author=getAuthorField(article.author, noSourceLink),
                           author_url=getAuthorUrl(article, url, noSourceLink),
                           text='<div>TO BE ADDED</div>')
            elif 'ACCESS_TOKEN_INVALID' in str(e):
                r = TelegraphPoster().post(
                    title=article.title,
                    author=getAuthorField(article.author, noSourceLink),
                    author_url=getAuthorUrl(article, url, noSourceLink),
                    text=str(article.text))
            else:
                raise e
        if force or isConfident(url, article.text):
            return _trimUrl(r['url'])
    except Exception as e:
        if throw_exception:
            raise e
    def test_edit_with_path(self):
        html = '<p>test paragraph</p>'
        t1 = TelegraphPoster(use_api=True, access_token=self.sandbox_access_token)
        t2 = TelegraphPoster(use_api=True, access_token=self.sandbox_access_token)
        result = t1.post('test_page0201', 'au', html)
        result2 = t2.edit(title='test_page0201_edit', text='<p>test paragraph edited</p>', path=result['path'])

        self.assertTrue('url' in result)
        self.assertTrue('path' in result)
        self.assertEqual(
            result['path'],
            result2['path']
        )