robertoszek / pleroma-bot

Bot for mirroring one or multiple Twitter accounts in Pleroma/Mastodon/Misskey.
https://robertoszek.github.io/pleroma-bot
MIT License
104 stars 18 forks source link

Do not ask to enter date when --forceDate is provided #70

Open nemobis opened 2 years ago

nemobis commented 2 years ago

I have to populate a number of accounts for the first time, so it's annoying to have to require manual input like this:

ℹ 2022-04-03 13:35:08,271 - pleroma_bot - INFO - ====================================== 
ℹ 2022-04-03 13:35:08,271 - pleroma_bot - INFO - Processing user:       108067315577208905 
ℹ 2022-04-03 13:35:08,272 - pleroma_bot - INFO - It seems like pleroma-bot is running for the first time for this Twitter user: eucopresident 
ℹ 2022-04-03 13:35:10,628 - pleroma_bot - INFO - How far back should we retrieve tweets from the Twitter account? 
ℹ 2022-04-03 13:35:10,629 - pleroma_bot - INFO - 
Enter a date (YYYY-MM-DD):
[Leave it empty to retrieve *ALL* tweets or enter 'continue'
if you want the bot to execute as normal (checking date of 
last post in the Fediverse account)]

Am I supposed to use --forceDate together with --skipChecks the first time? Currently I'm using a silly patch like this in _utils.py after logger.info(date_msg):

    # input_date = input()
    if True:

I don't quite understand what cli.py is trying to do here:

            if (
                (args.forceDate and args.forceDate in user.twitter_username)
                or args.forceDate == "all"
                or user.first_time
            ) and not args.skipChecks:
                date_pleroma = user.force_date()
            else:
                if user.instance == "misskey":  # pragma
                    date_pleroma = user.get_date_last_misskey_post()
                else:
                    date_pleroma = user.get_date_last_pleroma_post()

It feels like date_pleroma is never set to args.forceDate.

robertoszek commented 2 years ago

Hmm yeah, I see how can be annoying when setting up multiple users for the first time.

I'm trying to think what would be an elegant solution in this usecase, maybe passing the date value directly to the command would be preferable?

Right now the forceDate value can be one of the twitter_username listed on your config so you force it just for that user, but we could evaluate the value in case it doesn't match any user and you pass a date instead.

So, it would look like along the lines of this, force it just for one user (current behaviour):

$ pleroma-bot --forceDate WoolieWoolz

Or, force a specific date for all users in your config:

$ pleroma-bot --forceDate 2020-12-01

If the date is present, it would be used to gather tweets from that date onwards, without asking for any input.

Would that work for you?

nemobis commented 2 years ago

Thank you for your thoughtful reply.

Il 03/04/22 17:33, robertoszek ha scritto:

If the date is present, it would be used to gather tweets from that date onwards, without asking for any input.

Yes, this would be intuitive for me. Indeed that's how I thought this flag already worked: I was running

pleroma-bot --forceDate 2022-04-03

No idea why I misunderstood the documentation this way, maybe just wishful thinking.

robertoszek commented 2 years ago

I also included this change in 1.0.3rc8, feel free to give it a try:

pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple pleroma-bot==1.0.3rc8

It should work as you expected before (with the date format being YYYY-MM-DD):

$ pleroma-bot --forceDate 2020-12-01
nemobis commented 2 years ago

Thank you! However I may have misunderstood what you meant: I see that duplicate toots are posted as the forced date takes precedence over the last toot, so I can't use that option twice for the same user.

What I really want is perhaps to override this in the force_date() function:

    if input_date == "continue":
        if self.posts != "none_found":
            date = self.get_date_last_post()
        else:
            date = datetime.strftime(
                datetime.now() - timedelta(days=2), "%Y-%m-%dT%H:%M:%SZ"
            )

I'd like to be able to pass a command line flag which will automatically select "continue", and maybe configure the timedelta.

realkinetix commented 1 year ago

forceDate doesn't seem to take a username now, it wants something in the date format

robertoszek commented 1 year ago

@realkinetix which version are you on? I'm trying to replicate it to no avail.

It expects the twitter_username and it will only ask the date for the user matching that twitter_username on your config. Perhaps it led to confusion that the other users will complain about it?

For example: pleroma-bot --forceDate twitterUsername

ℹ 2022-12-19 20:30:41,805 - pleroma_bot - INFO - config path: config-test.yml
ℹ 2022-12-19 20:30:41,805 - pleroma_bot - INFO - tweets temp folder: /home/test/pleroma-bot/tweets
ℹ 2022-12-19 20:30:41,816 - pleroma_bot - INFO - ====================================== 
ℹ 2022-12-19 20:30:41,816 - pleroma_bot - INFO - Processing user:       test_pleroma
✖ 2022-12-19 20:30:45,238 - pleroma_bot - ERROR - Exception occurred for user, skipping... (cli.py:711)
Traceback (most recent call last):
File "/mnt/c/Users/chamorr1/Documents/git/pleroma-bot/pleroma_bot/cli.py", line 572, in main
raise Exception(
Exception: Invalid forceDate format, use "YYYY-mm-dd"
ℹ 2022-12-19 20:30:45,241 - pleroma_bot - INFO - ======================================
ℹ 2022-12-19 20:30:45,241 - pleroma_bot - INFO - Processing user:       109452890846928419
ℹ 2022-12-19 20:30:47,360 - pleroma_bot - INFO - How far back should we retrieve tweets from the Twitter account?
ℹ 2022-12-19 20:30:47,361 - pleroma_bot - INFO -
Enter a date (YYYY-MM-DD):
[Leave it empty to retrieve *ALL* tweets or enter 'continue'
if you want the bot to execute as normal (checking date of
last post in the Fediverse account)]                                                                                                                                                                                                                                                                                                                                                                                                                                                     

For a config such as this one:

[...]
users:
- twitter_username: github
  pleroma_username: test_pleroma
  pleroma_token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- twitter_username: twitterUsername
  pleroma_username: 109452890846928419
  pleroma_token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
realkinetix commented 1 year ago

Hmm. I've apparently fooled around enough with the version I'm using to have broken the breakage I was seeing. My apologies for not posting the version and output at the time. I am seeing 1.1.1rc1 via pip and 1.1.0 (from git master branch) behaving pretty much as you've shown.