Skip to content

Commit

Permalink
Added PARAMETERS option
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielRF committed Jul 16, 2022
1 parent 64e8c3a commit 510a2e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Defina as variáveis na aba `Secrets` do repositório:

`URL`: Endereços de feeds RSS separados por vírgulas;

`PARAMETERS`: (opcional) Parâmetros que serão adicionados ao fim do link;

`MESSAGE_TEMPLATE`: (opcional) Texto da mensagem. Valor padrão: `<b>{TITLE}</b>` ([ver opções](#opções-de-variáveis));

`BUTTON_TEXT`: (opcional) Texto do botão com o link. Sugestão: `{SITE_NAME}`. Se esta variável não for criada não será enviado um botão. ([Ver opções](#opções-de-variáveis));
Expand Down
12 changes: 11 additions & 1 deletion rss2telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DESTINATION = os.environ.get('DESTINATION')
BOT_TOKEN = os.environ.get('BOT_TOKEN')
EMOJIS = os.environ.get('EMOJIS', '🗞,📰,🗒,🗓,📋,🔗,📝,🗃')
PARAMETERS = os.environ.get('PARAMETERS', False)

bot = telebot.TeleBot(BOT_TOKEN)

Expand Down Expand Up @@ -72,12 +73,21 @@ def get_img(url):
photo = False
return photo

def define_link(link, PARAMETERS):
if PARAMETERS:
if '?' in link:
return f'{link}&{PARAMETERS}'
return f'{link}?{PARAMETERS}'
return f'{link}'



def set_env_vars(text, topic):
cases = {
'SITE_NAME': topic['site_name'],
'TITLE': topic['title'],
'SUMMARY': re.sub('<[^<]+?>', '', topic['summary']),
'LINK': topic['link'],
'LINK': define_link(topic['link'], PARAMETERS),
'EMOJI': random.choice(EMOJIS.split(","))
}
for word in re.split('{|}', text):
Expand Down

0 comments on commit 510a2e6

Please sign in to comment.