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.
|
||||
--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']}"})
|
||||
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,16 +128,16 @@ class MastodonEmailBridge:
|
|||
error
|
||||
)
|
||||
return url
|
||||
data = result.json()[0]
|
||||
if int(data['id']) not in self.sent_items:
|
||||
self.send_mail(data)
|
||||
else:
|
||||
self._log.debug("Skipping post %s that was sent in the past", data['id'])
|
||||
if 'Link' in result.headers:
|
||||
for link in result.headers['Link'].split(', '):
|
||||
slink = link.split('; ')
|
||||
if slink[1] == 'rel="next"':
|
||||
next_url = slink[0].replace('<', '').replace('>', '')
|
||||
for data in result.json():
|
||||
if int(data['id']) not in self.sent_items:
|
||||
self.send_mail(data)
|
||||
else:
|
||||
self._log.debug("Skipping post %s that was sent in the past", data['id'])
|
||||
if 'Link' in result.headers:
|
||||
for link in result.headers['Link'].split(', '):
|
||||
slink = link.split('; ')
|
||||
if slink[1] == 'rel="next"':
|
||||
next_url = slink[0].replace('<', '').replace('>', '')
|
||||
return next_url
|
||||
|
||||
def send_mail(self, data):
|
||||
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue