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

Unable to get a specific number of messages from history #31

Closed
mmartinortiz opened this issue Jul 2, 2015 · 4 comments
Closed

Unable to get a specific number of messages from history #31

mmartinortiz opened this issue Jul 2, 2015 · 4 comments
Labels

Comments

@mmartinortiz
Copy link

Hi,
I am trying to save the chat history into a file. However, when I use the execute_function function, I always get 40 results (the default number)

n_messages = 0
for message in sender.execute_function('history', 'my_contact', '10'):
    n_messages += 1
# It is always 40
print(n_messages)

What is the way for specify the size of the history?

Thanks!

@luckydonald
Copy link
Owner

I can reproduce that bug. I'll look into it.

from pytg.sender import Sender ; s = Sender("localhost", 4458)
n_messages = len(s.history('my_contact', '10'))
print("Length is {length}".format(length=n_messages))
#  40

@luckydonald
Copy link
Owner

I located the bug. The problem is that the '10' is a string, so the optional parameter limit which requires an int is skipped.

import logging ; logging.basicConfig(level=logging.DEBUG)
s.history('my_contact', '10')
# log shows:
DEBUG:pytg.sender:Parsing history: Argument user_name - <user> (needed)
DEBUG:pytg.sender:Parsing history: Argument 10 - [limit] (needed)
pytg.exceptions.ArgumentParseError: Not a int/long
DEBUG:pytg.sender:Skipping unfitting optional parameter #1 [limit] (type PositiveNumber) in function history.
DEBUG:pytg.sender:Parsing history: Argument 10 - [offset] (needed)
pytg.exceptions.ArgumentParseError: Not a int/long
DEBUG:pytg.sender:Skipping unfitting optional parameter #1 [offset] (type NonNegativeNumber) in function history.
DEBUG:pytg.sender:Sending command > [disable_preview] history user_name

@luckydonald luckydonald added the bug label Jul 2, 2015
@luckydonald
Copy link
Owner

So that works like intended, the actual problem is that the int as argument does not work (#32).

luckydonald added a commit that referenced this issue Jul 2, 2015
…that as well, so an int becomes a string in requested format. Fixes issue #32, and so closes issue #31
@luckydonald
Copy link
Owner

Fixed.

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

No branches or pull requests

2 participants