-1

I'm trying to automate publishing some texts in Telegram using Telegraph and Python. I need to make links that will be clickable on Telegraph.

I made this only for Telegraph file with one link. Here is the code:

from telegraph import Telegraph
from telegraph.utils import html_to_content
telegraph = Telegraph('<access_token>')
account = telegraph.create_account(short_name='216')
html_string = '<a href="https://www.hse.ru">school</a>'
content = html_to_content(html_string)
new_page = telegraph.create_page(title="Formed Digest", content=content)
print(new_page[1])

But I need to have some other text that will not be clickable.

  • Actually what is with the combination of libraries. There is one called "Telegraph" and another called "telegraph_client". I can't get telegraph.utils to work at all. telegraph.create_page() gives you a response but where will the html get created? – Sin Han Jinn Dec 15 '22 at 02:03
  • If you mention the above is working for you, and your question is on how to add a clickable link in between text, it's just got to do with writing the html. You can refer to how to write them here > https://www.w3schools.com/html/default.asp. I'll give you a sample in the answers. – Sin Han Jinn Dec 15 '22 at 02:05

1 Answers1

0

Like mentioned in the comments, I don't see the picture of why there are two telegraph & telegraph_client libraries in use. Also unsure of where the html is getting created add. There's no relation with your question which is how to add a link in between text. Just giving you a sample html string below.

html_string = '<html>\n<head>\n<title> \nOutput Data in an HTML file \
           </title>\n</head> <body><h1>Welcome to <a href="https://www.hse.ru">School!</a></h1>\
           \nTesting out writing a second line</h2> \n</body></html>'
f= open("test.html","w+")
f.write(html_string);
f.close();

Output where the "School" is clickable: enter image description here

Sin Han Jinn
  • 574
  • 3
  • 18