Update some URLs

Some were out of date, some were examples pointing to a personal
link, which were replaced with generic examples.
This commit is contained in:
Lonami Exo 2020-02-20 11:19:39 +01:00
parent 3d32e16235
commit 7ffb87170b
8 changed files with 49 additions and 61 deletions

View File

@ -47,7 +47,7 @@ use these if possible.
message = await client.send_message(
'me',
'This message has **bold**, `code`, __italics__ and '
'a [nice website](https://lonamiwebs.github.io)!',
'a [nice website](https://example.com)!',
link_preview=False
)

View File

@ -360,6 +360,6 @@ Where can I read more?
======================
`Check out my blog post
<https://lonamiwebs.github.io/blog/asyncio/>`_ about `asyncio`, which
<https://lonami.dev/blog/asyncio/>`_ about `asyncio`, which
has some more examples and pictures to help you understand what happens
when the loop runs.

View File

@ -112,9 +112,9 @@ you're able to just do this:
dialogs = await client.get_dialogs()
# All of these work and do the same.
lonami = await client.get_entity('lonami')
lonami = await client.get_entity('t.me/lonami')
lonami = await client.get_entity('https://telegram.dog/lonami')
username = await client.get_entity('username')
username = await client.get_entity('t.me/username')
username = await client.get_entity('https://telegram.dog/username')
# Other kind of entities.
channel = await client.get_entity('telegram.me/joinchat/AAAAAEkk2WdoDrB4-Q8-gg')
@ -142,7 +142,7 @@ you're able to just do this:
All methods in the :ref:`telethon-client` call `.get_input_entity()
<telethon.client.users.UserMethods.get_input_entity>` prior
to sending the request to save you from the hassle of doing so manually.
That way, convenience calls such as `client.send_message('lonami', 'hi!')
That way, convenience calls such as `client.send_message('username', 'hi!')
<telethon.client.messages.MessageMethods.send_message>`
become possible.

View File

@ -8,82 +8,70 @@ does a result have? Well, the easiest thing to do is printing it:
.. code-block:: python
user = await client.get_entity('Lonami')
print(user)
entity = await client.get_entity('username')
print(entity)
That will show a huge **string** similar to the following:
.. code-block:: python
User(id=10885151, is_self=False, contact=False, mutual_contact=False, deleted=False, bot=False, bot_chat_history=False, bot_nochats=False, verified=False, restricted=False, min=False, bot_inline_geo=False, access_hash=123456789012345678, first_name='Lonami', last_name=None, username='Lonami', phone=None, photo=UserProfilePhoto(photo_id=123456789012345678, photo_small=FileLocation(dc_id=4, volume_id=1234567890, local_id=1234567890, secret=123456789012345678), photo_big=FileLocation(dc_id=4, volume_id=1234567890, local_id=1234567890, secret=123456789012345678)), status=UserStatusOffline(was_online=datetime.datetime(2018, 1, 2, 3, 4, 5, tzinfo=datetime.timezone.utc)), bot_info_version=None, restriction_reason=None, bot_inline_placeholder=None, lang_code=None)
Channel(id=1066197625, title='Telegram Usernames', photo=ChatPhotoEmpty(), date=datetime.datetime(2016, 12, 16, 15, 15, 43, tzinfo=datetime.timezone.utc), version=0, creator=False, left=True, broadcast=True, verified=True, megagroup=False, restricted=False, signatures=False, min=False, scam=False, has_link=False, has_geo=False, slowmode_enabled=False, access_hash=-6309373984955162244, username='username', restriction_reason=[], admin_rights=None, banned_rights=None, default_banned_rights=None, participants_count=None)
That's a lot of text. But as you can see, all the properties are there.
So if you want the username you **don't use regex** or anything like
splitting ``str(user)`` to get what you want. You just access the
So if you want the title you **don't use regex** or anything like
splitting ``str(entity)`` to get what you want. You just access the
attribute you need:
.. code-block:: python
username = user.username
title = entity.title
Can we get better than the shown string, though? Yes!
.. code-block:: python
print(user.stringify())
print(entity.stringify())
Will show a much better:
.. code-block:: python
User(
id=10885151,
is_self=False,
contact=False,
mutual_contact=False,
deleted=False,
bot=False,
bot_chat_history=False,
bot_nochats=False,
verified=False,
Channel(
id=1066197625,
title='Telegram Usernames',
photo=ChatPhotoEmpty(
),
date=datetime.datetime(2016, 12, 16, 15, 15, 43, tzinfo=datetime.timezone.utc),
version=0,
creator=False,
left=True,
broadcast=True,
verified=True,
megagroup=False,
restricted=False,
signatures=False,
min=False,
bot_inline_geo=False,
access_hash=123456789012345678,
first_name='Lonami',
last_name=None,
username='Lonami',
phone=None,
photo=UserProfilePhoto(
photo_id=123456789012345678,
photo_small=FileLocation(
dc_id=4,
volume_id=123456789,
local_id=123456789,
secret=-123456789012345678
),
photo_big=FileLocation(
dc_id=4,
volume_id=123456789,
local_id=123456789,
secret=123456789012345678
)
),
status=UserStatusOffline(
was_online=datetime.datetime(2018, 1, 2, 3, 4, 5, tzinfo=datetime.timezone.utc)
),
bot_info_version=None,
restriction_reason=None,
bot_inline_placeholder=None,
lang_code=None
scam=False,
has_link=False,
has_geo=False,
slowmode_enabled=False,
access_hash=-6309373984955162244,
username='username',
restriction_reason=[
],
admin_rights=None,
banned_rights=None,
default_banned_rights=None,
participants_count=None
)
Now it's easy to see how we could get, for example,
the ``was_online`` time. It's inside ``status``:
the ``year`` value. It's inside ``date``:
.. code-block:: python
online_at = user.status.was_online
channel_year = entity.date.year
You don't need to print everything to see what all the possible values
can be. You can just search in http://tl.telethon.dev/.
@ -96,5 +84,5 @@ to check the type of something. For example:
from telethon import types
if isinstance(user.status, types.UserStatusOffline):
print(user.status.was_online)
if isinstance(entity.photo, types.ChatPhotoEmpty):
print('Channel has no photo')

View File

@ -25,7 +25,7 @@ telethon_examples/
==================
`telethon_examples <https://github.com/LonamiWebs/Telethon/tree/master/telethon_examples>`_ /
`LonamiWebs' site <https://lonamiwebs.github.io>`_
`Lonami's site <https://lonami.dev>`_
This documentation is not the only place where you can find useful code
snippets using the library. The main repository also has a folder with

View File

@ -1995,7 +1995,7 @@ Internal changes
~~~~~~~~~~~~~~~~
- ``libssl`` is no longer an optional dependency. Use ``cryptg`` instead,
which you can find on https://github.com/Lonami/cryptg.
which you can find on https://pypi.org/project/cryptg/.

View File

@ -569,10 +569,10 @@ class DialogMethods:
# <you> Your name didn't have any letters! Try again
conv.send_message("Your name didn't have any letters! Try again")
# <usr> Lonami
# <usr> Human
name = conv.get_response().raw_text
# <you> Thanks Lonami!
# <you> Thanks Human!
conv.send_message('Thanks {}!'.format(name))
"""
return custom.Conversation(

View File

@ -634,7 +634,7 @@ class MessageMethods:
.. code-block:: python
# Markdown is the default
await client.send_message('lonami', 'Thanks for the **Telethon** library!')
await client.send_message('me', 'Hello **world**!')
# Default to another parse mode
client.parse_mode = 'html'
@ -668,7 +668,7 @@ class MessageMethods:
# Matrix of inline buttons
await client.send_message(chat, 'Pick one from this grid', buttons=[
[Button.inline('Left'), Button.inline('Right')],
[Button.url('Check this site!', 'https://lonamiwebs.github.io')]
[Button.url('Check this site!', 'https://example.com')]
])
# Reply keyboard