Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make json viewer more clear #2334

Closed
wants to merge 1 commit into from
Closed

make json viewer more clear #2334

wants to merge 1 commit into from

Conversation

z44d
Copy link
Contributor

@z44d z44d commented Jul 3, 2024

make printing types understandable by using json.dumps, and ignore fields with None value, as Bot API did.

  • I tested it here
@bot.message_handler(content_types=["text"])
async def on_text_message(m):
    print(m)
  • This was the result before ( so annoying and not clear )
{'content_type': 'text', 'id': 1484, 'message_id': 1484, 'from_user': {'id': 5117901887, 'is_bot': False, 'first_name': 'Zaid', 'username': '...', 'last_name': None, 'language_code': 'en', 'can_join_groups': None, 'can_read_all_group_messages': None, 'supports_inline_queries': None, 'is_premium': True, 'added_to_attachment_menu': None, 'can_connect_to_business': None}, 'date': 1720041051, 'chat': {'id': 5117901887, 'type': 'private', 'title': None, 'username': '...', 'first_name': 'Zaid', 'last_name': None, 'is_forum': None, 'max_reaction_count': None, 'photo': None, 'bio': None, 'join_to_send_messages': None, 'join_by_request': None, 'has_private_forwards': None, 'has_restricted_voice_and_video_messages': None, 'description': None, 'invite_link': None, 'pinned_message': None, 'permissions': None, 'slow_mode_delay': None, 'message_auto_delete_time': None, 'has_protected_content': None, 'sticker_set_name': None, 'can_set_sticker_set': None, 'linked_chat_id': None, 'location': None, 'active_usernames': None, 'emoji_status_custom_emoji_id': None, 'has_hidden_members': None, 'has_aggressive_anti_spam_enabled': None, 'emoji_status_expiration_date': None, 'available_reactions': None, 'accent_color_id': None, 'background_custom_emoji_id': None, 'profile_accent_color_id': None, 'profile_background_custom_emoji_id': None, 'has_visible_history': None, 'unrestrict_boost_count': None, 'custom_emoji_sticker_set_name': None, 'business_intro': None, 'business_location': None, 'business_opening_hours': None, 'personal_chat': None, 'birthdate': None}, 'sender_chat': None, 'is_automatic_forward': None, 'reply_to_message': None, 'via_bot': None, 'edit_date': None, 'has_protected_content': None, 'media_group_id': None, 'author_signature': None, 'text': 'Hi', 'entities': None, 'caption_entities': None, 'audio': None, 'document': None, 'photo': None, 'sticker': None, 'video': None, 'video_note': None, 'voice': None, 'caption': None, 'contact': None, 'location': None, 'venue': None, 'animation': None, 'dice': None, 'new_chat_members': None, 'left_chat_member': None, 'new_chat_title': None, 'new_chat_photo': None, 'delete_chat_photo': None, 'group_chat_created': None, 'supergroup_chat_created': None, 'channel_chat_created': None, 'migrate_to_chat_id': None, 'migrate_from_chat_id': None, 'pinned_message': None, 'invoice': None, 'successful_payment': None, 'connected_website': None, 'reply_markup': None, 'message_thread_id': None, 'is_topic_message': None, 'chat_background_set': None, 'forum_topic_created': None, 'forum_topic_closed': None, 'forum_topic_reopened': None, 'has_media_spoiler': None, 'forum_topic_edited': None, 'general_forum_topic_hidden': None, 'general_forum_topic_unhidden': None, 'write_access_allowed': None, 'users_shared': None, 'chat_shared': None, 'story': None, 'external_reply': None, 'quote': None, 'link_preview_options': None, 'giveaway_created': None, 'giveaway': None, 'giveaway_winners': None, 'giveaway_completed': None, 'forward_origin': None, 'boost_added': None, 'sender_boost_count': None, 'reply_to_story': None, 'sender_business_bot': None, 'business_connection_id': None, 'is_from_offline': None, 'effect_id': None, 'show_caption_above_media': None, 'json': {'message_id': 1484, 'from': {'id': 5117901887, 'is_bot': False, 'first_name': 'Zaid', 'username': '...', 'language_code': 'en', 'is_premium': True}, 'chat': {'id': 5117901887, 'first_name': 'Zaid', 'username': '...', 'type': 'private'}, 'date': 1720041051, 'text': 'Hi'}}
  • After my pull request the result will be like this, so clear and understandable. ( maybe i have to ignore json attr too, but i didn't know that's attribute is exist anyway haha )
{
  "content_type": "text",
  "id": 1482,
  "message_id": 1482,
  "from_user": {
    "id": 5117901887,
    "is_bot": false,
    "first_name": "Zaid",
    "username": "...",
    "language_code": "en",
    "is_premium": true
  },
  "date": 1720040975,
  "chat": {
    "id": 5117901887,
    "type": "private",
    "username": "...",
    "first_name": "Zaid"
  },
  "text": "Hi",
  "json": {
    "message_id": 1482,
    "from": {
      "id": 5117901887,
      "is_bot": false,
      "first_name": "Zaid",
      "username": "...",
      "language_code": "en",
      "is_premium": true
    },
    "chat": {
      "id": 5117901887,
      "first_name": "Zaid",
      "username": "...",
      "type": "private"
    },
    "date": 1720040975,
    "text": "Hi"
  }
}

@z44d z44d changed the title make printing types more clear make print types more clear Jul 3, 2024
@Badiboy
Copy link
Collaborator

Badiboy commented Jul 4, 2024

  • so annoying and not clear

It is usefull when dumping, for example, in file, because does not produce lot of lines and can be easily copied to interactive json viewer.

However it looks reasonable for some cases. I'll take a look how to make it optional.

@coder2020official
Copy link
Collaborator

Yes, better make it optional.

@Badiboy
Copy link
Collaborator

Badiboy commented Jul 4, 2024

I propose adding

JSONDESERIALIZABLE_PARSE_OUTPUT = False
JSONDESERIALIZABLE_SKIP_NONE = False

in top of types.py:
image

And make new output proposal work for JSONDESERIALIZABLE_PARSE_OUTPUT == True. And ignore None-s on JSONDESERIALIZABLE_SKIP_NONE == True.

@coder2020official ?

@z44d
Copy link
Contributor Author

z44d commented Jul 4, 2024

And ignore None-s on JSONDESERIALIZABLE_SKIP_NONE == True.

i don’t think it should be optional, because bot api ignoring them, pytba should be close to bot api.

@Badiboy
Copy link
Collaborator

Badiboy commented Jul 4, 2024

It should be optional. You can set it to True by default if you want to.

@coder2020official
Copy link
Collaborator

I think skipping Nones should be True. API does not provide them, so what is the point of having them?
also, maybe we should store json_string instead?

@z44d
Copy link
Contributor Author

z44d commented Jul 4, 2024

I think skipping Nones should be True. API does not provide them, so what is the point of having them? also, maybe we should store json_string instead?

hmm, json_string doesn’t contain all currently info, like from_user atrribute is only from in json_string

@z44d z44d changed the title make print types more clear make json viewer more clear Jul 7, 2024
@Badiboy
Copy link
Collaborator

Badiboy commented Jul 8, 2024

"from" is a keyword in Python, so it was changed to "from_user" in spite of being in API.

@z44d
Copy link
Contributor Author

z44d commented Jul 9, 2024

"from" is a keyword in Python, so it was changed to "from_user" in spite of being in API.

i know, but json viewer must view the object attributes, not the json_string from bot api

@z44d z44d closed this by deleting the head repository Jul 13, 2024
@coder2020official
Copy link
Collaborator

Why was this closed again? This should've been re-implemented to be optional?

@z44d
Copy link
Contributor Author

z44d commented Jul 21, 2024

Why was this closed again? This should've been re-implemented to be optional?

i removed the repo by mistake, i forgot about this PR it was disappeared from recent activities so, if you want me to open new pr just tell me

@coder2020official
Copy link
Collaborator

I propose:

  • Storing json_string, with 'from' being changed to 'from_user'
  • When printing an object, this json_string should be printed.

@Badiboy need your opinion. This way, users will be able to see a CLEAR response from Telegram.

@coder2020official
Copy link
Collaborator

And then, we can add some JSON_FORMATTED = FALSE or something like this to types.

@coder2020official
Copy link
Collaborator

coder2020official commented Jul 21, 2024

@2ei please recreate PR, I will re-comment my comments on the new PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants