Allow to set requests limit

This commit is contained in:
Antonio J. Delgado 2024-08-03 10:27:05 +03:00
parent 0de622561b
commit 783eecd9a2
2 changed files with 18 additions and 13 deletions

View file

@ -50,3 +50,6 @@ Customize the templates (if you know HTML, CSS and Jinja2) and run the command.
--config FILE Read configuration from FILE.
--help Show this message and exit.
```
## Notes
- Clean the folder ~/.mastodon_email_bridge_sent_items every now and then, but you can check the generated HTML files to test new templates.
- The posts that have been sent by email are stored in an SQLite3 database in ~/.mastodon_email_bridge_sent_items.db if you want a post to be sent again you can remove it from there and run again the script.

View file

@ -74,10 +74,11 @@ class MastodonEmailBridge:
self.session.headers.update({'Authorization': f"Bearer {self.config['token']}"})
count=1
self._log.debug(
"Getting URL 'https://%s/api/v1/timelines/home?limit=1'",
self.config['server']
"Getting URL 'https://%s/api/v1/timelines/home?limit=%s'",
self.config['server'],
self.config['limit_per_request']
)
next_url = f"https://{self.config['server']}/api/v1/timelines/home?limit=1"
next_url = f"https://{self.config['server']}/api/v1/timelines/home?limit={self.config['limit_per_request']}"
next_url = self.process_url(next_url)
while next_url != "" and (count < self.config['limit'] or self.config['limit'] == 0):
count = count + 1
@ -127,7 +128,7 @@ class MastodonEmailBridge:
error
)
return url
data = result.json()[0]
for data in result.json():
if int(data['id']) not in self.sent_items:
self.send_mail(data)
else:
@ -246,6 +247,7 @@ class MastodonEmailBridge:
help='Mastodon server full qualified name.'
)
@click.option('--limit', '-L', default=0, help='Mastodon token with read access.')
@click.option('--limit-per-request', '-R', default=40, help='Mastodon token with read access.')
@click.option('--wait', '-w', default=5, help='Seconds to wait between requests to avoid rate limits.')
@click.option('--recipient', '-r', required=True, help='Recipient email to get the posts.')
@click.option(