diff --git a/README.md b/README.md index 7621ac9..7262834 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/mastodon_email_bridge/mastodon_email_bridge.py b/mastodon_email_bridge/mastodon_email_bridge.py index de6880f..2bc7844 100755 --- a/mastodon_email_bridge/mastodon_email_bridge.py +++ b/mastodon_email_bridge/mastodon_email_bridge.py @@ -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(