Fix if
This commit is contained in:
parent
7c0490a352
commit
11a84f9180
1 changed files with 14 additions and 5 deletions
|
@ -15,11 +15,11 @@ import smtplib
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import importlib
|
||||||
import click
|
import click
|
||||||
import click_config_file
|
import click_config_file
|
||||||
import requests
|
import requests
|
||||||
from jinja2 import Environment, select_autoescape, FileSystemLoader
|
from jinja2 import Environment, select_autoescape, FileSystemLoader
|
||||||
import importlib
|
|
||||||
|
|
||||||
class MastodonEmailBridge:
|
class MastodonEmailBridge:
|
||||||
'''CLass to redirect the Mastodon home timeline to email'''
|
'''CLass to redirect the Mastodon home timeline to email'''
|
||||||
|
@ -120,7 +120,8 @@ class MastodonEmailBridge:
|
||||||
result = self.session.get(url)
|
result = self.session.get(url)
|
||||||
# for header in result.headers:
|
# for header in result.headers:
|
||||||
# self._log.debug("%s = %s", header, result.headers[header])
|
# self._log.debug("%s = %s", header, result.headers[header])
|
||||||
if 'X-RateLimit-Remaining' in result.headers and int(result.headers['X-RateLimit-Remaining']) < 10:
|
if ('X-RateLimit-Remaining' in result.headers
|
||||||
|
and int(result.headers['X-RateLimit-Remaining']) < 10):
|
||||||
self._log.warning("X-RateLimit-Reset: %s", result.headers['X-RateLimit-Reset'])
|
self._log.warning("X-RateLimit-Reset: %s", result.headers['X-RateLimit-Reset'])
|
||||||
try:
|
try:
|
||||||
reset_time = time.mktime(
|
reset_time = time.mktime(
|
||||||
|
@ -165,7 +166,7 @@ class MastodonEmailBridge:
|
||||||
return next_url
|
return next_url
|
||||||
|
|
||||||
def _translate_data(self, data):
|
def _translate_data(self, data):
|
||||||
if self.config['libretranslate_url'] is None or self.config['libretranslate_url'] = '':
|
if self.config['libretranslate_url'] is None or self.config['libretranslate_url'] == '':
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
"Not translating data because no LibreTranslate URL was specified"
|
"Not translating data because no LibreTranslate URL was specified"
|
||||||
)
|
)
|
||||||
|
@ -183,7 +184,10 @@ class MastodonEmailBridge:
|
||||||
]
|
]
|
||||||
for field in fields_to_translate:
|
for field in fields_to_translate:
|
||||||
if field in data:
|
if field in data:
|
||||||
new_data[f"translated_{field}"] = self._translate(data[field], source_language=source_language)
|
new_data[f"translated_{field}"] = self._translate(
|
||||||
|
data[field],
|
||||||
|
source_language=source_language
|
||||||
|
)
|
||||||
return new_data
|
return new_data
|
||||||
|
|
||||||
def get_post(self, post_id):
|
def get_post(self, post_id):
|
||||||
|
@ -336,7 +340,12 @@ 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=60, 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(
|
@click.option(
|
||||||
'--recipient',
|
'--recipient',
|
||||||
'-r',
|
'-r',
|
||||||
|
|
Loading…
Reference in a new issue