Skip to content

twitter_bot: Solve retweet issue. #557

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

orientor
Copy link
Collaborator

The twitter bot initially posted all kind of tweets. Change it
so that on encountering a retweet either post the original tweet
if it hasn't been posted before. Else try to edit the number of
retweets in the message of the original tweet.

# do nothing.
if edit_message is True:
message_data = {
"message_id": message_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message_id exists only when the try code above doesn't raise an exception, which means it only exists within that scope. Shouldn't message_id be initialized to have a default value of 0 first?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added accordingly.

@rht
Copy link
Contributor

rht commented Mar 21, 2020

From my reading of the current state of the PR, there is no adding a number of retweets in the body of the message yet (a). What happens is that the message is being edited with the message_id pointing to the latest message. Is feature (a) too unwieldy to implement?

@orientor
Copy link
Collaborator Author

orientor commented Mar 21, 2020

From my reading of the current state of the PR, there is no adding a number of retweets in the body of the message yet (a). What happens is that the message is being edited with the message_id pointing to the latest message. Is feature (a) too unwieldy to implement?

@rht I am storing the twitter id: message id key-value pairs for tweets that have been posted in the config file. So message_id will point to the older message and that will be edited. I didn't understand the "pointing to latest message" part. And if the message is a retweet I am adding the number of retweets to the url variable. I will add the retweets part to the general tweet too.

@orientor
Copy link
Collaborator Author

Screenshot from 2020-03-21 23-57-20
@rht Added number of retweets to all messages.

The twitter bot initially posted all kind of tweets. Change it
so that on encountering a retweet either post the original tweet
if it hasn't been posted before. Else try to edit the number of
retweets in the message of the original tweet.
if status.retweeted_status is None:
config_internal.set('twitter', str(status.id), str(ret['id']))
else:
config_internal.set('twitter', str(status.retweeted_status.id), str(ret['id']))
Copy link
Contributor

@rht rht Mar 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that the config file content will grow larger with the number of retweeted messages? What about reading the tweet count from the message body instead?

Copy link
Collaborator Author

@orientor orientor Mar 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am using it as a kind of database to store the message id of the message in which that tweet was published. I am reading the tweet count from the message body. I am storing the message id so that I can later edit that message if I get its retweet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the message id should be stored in a separate dedicated key-value database?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that would be better. Can you suggest what I should use for the key-value database?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't come up with any solution on top of my head. Haven't seen any being used by python-zulip-api bots before. But if other bots will become more complex to require a db, they might be using the same db we would use here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a quick search, I found pickledb, a nosql key-value db in pure python. Unfortunately I can't be decisive about this, given that there are several alternatives. Maybe we should discuss in czo.

@PIG208
Copy link
Member

PIG208 commented Jun 14, 2021

Perhaps it will be feasible to use bot storage to store the key-value pairs.

@zulipbot
Copy link
Member

Heads up @orientor, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

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

Successfully merging this pull request may close these issues.

4 participants