Increase wait between requests to 1min

This commit is contained in:
Antonio J. Delgado 2024-08-03 12:39:44 +03:00
parent 78390c4140
commit e4c8c916b7

View file

@ -129,6 +129,12 @@ class MastodonEmailBridge:
) )
return url return url
for data in result.json(): for data in result.json():
if data['in_reply_to_id']:
self._log.debug(
"This post is a reply to '%s', fetching it",
data['in_reply_to_id']
)
data['meb_reply_to'] = self.get_post(data['in_reply_to_id'])
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:
@ -140,10 +146,25 @@ class MastodonEmailBridge:
next_url = slink[0].replace('<', '').replace('>', '') next_url = slink[0].replace('<', '').replace('>', '')
return next_url return next_url
def get_post(self, post_id):
'''Get a single post'''
post = {}
self._log.debug(
"Getting post URL 'https://%s/api/v1/statuses/%s'...",
self.config['server'],
post_id
)
result = self.session.get(f"https://{self.config['server']}/api/v1/statuses/{post_id}")
post = result.json()
return post
def send_mail(self, data): def send_mail(self, data):
'''Send an email with the post composed''' '''Send an email with the post composed'''
msg = MIMEMultipart('alternative') msg = MIMEMultipart('alternative')
msg['Subject'] = f"FediPost from {data['account']['display_name']} ({data['account']['username']})" if data['in_reply_to_id']:
msg['Subject'] = f"FediReply from {data['account']['display_name']} ({data['account']['username']})"
else:
msg['Subject'] = f"FediPost from {data['account']['display_name']} ({data['account']['username']})"
msg['From'] = self.config['sender'] msg['From'] = self.config['sender']
msg['To'] = self.config['recipient'] msg['To'] = self.config['recipient']
html_template = self.j2env.get_template("new_post.html.j2") html_template = self.j2env.get_template("new_post.html.j2")
@ -248,7 +269,7 @@ class MastodonEmailBridge:
) )
@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('--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=60, 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(
'--sender', '--sender',