Allow to set requests limit
This commit is contained in:
parent
0de622561b
commit
783eecd9a2
2 changed files with 18 additions and 13 deletions
|
@ -50,3 +50,6 @@ Customize the templates (if you know HTML, CSS and Jinja2) and run the command.
|
||||||
--config FILE Read configuration from FILE.
|
--config FILE Read configuration from FILE.
|
||||||
--help Show this message and exit.
|
--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.
|
||||||
|
|
|
@ -74,10 +74,11 @@ class MastodonEmailBridge:
|
||||||
self.session.headers.update({'Authorization': f"Bearer {self.config['token']}"})
|
self.session.headers.update({'Authorization': f"Bearer {self.config['token']}"})
|
||||||
count=1
|
count=1
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
"Getting URL 'https://%s/api/v1/timelines/home?limit=1'",
|
"Getting URL 'https://%s/api/v1/timelines/home?limit=%s'",
|
||||||
self.config['server']
|
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)
|
next_url = self.process_url(next_url)
|
||||||
while next_url != "" and (count < self.config['limit'] or self.config['limit'] == 0):
|
while next_url != "" and (count < self.config['limit'] or self.config['limit'] == 0):
|
||||||
count = count + 1
|
count = count + 1
|
||||||
|
@ -127,7 +128,7 @@ class MastodonEmailBridge:
|
||||||
error
|
error
|
||||||
)
|
)
|
||||||
return url
|
return url
|
||||||
data = result.json()[0]
|
for data in result.json():
|
||||||
if int(data['id']) not in self.sent_items:
|
if int(data['id']) not in self.sent_items:
|
||||||
self.send_mail(data)
|
self.send_mail(data)
|
||||||
else:
|
else:
|
||||||
|
@ -246,6 +247,7 @@ class MastodonEmailBridge:
|
||||||
help='Mastodon server full qualified name.'
|
help='Mastodon server full qualified name.'
|
||||||
)
|
)
|
||||||
@click.option('--limit', '-L', default=0, help='Mastodon token with read access.')
|
@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('--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('--recipient', '-r', required=True, help='Recipient email to get the posts.')
|
||||||
@click.option(
|
@click.option(
|
||||||
|
|
Loading…
Reference in a new issue