Skip to content

Commit

Permalink
Adicionada a variável HIDE_BUTTON
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielRF committed Mar 15, 2023
1 parent f3a0ea0 commit 8baa4dc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
URL: ${{ vars.URL }}
EMOJIS: ${{ vars.EMOJIS }}
TOPIC: ${{ vars.TOPIC }}
HIDE_BUTTON: ${{ vars.HIDE_BUTTON }}
MESSAGE_TEMPLATE: ${{ vars.MESSAGE_TEMPLATE }}
BUTTON_TEXT: ${{ vars.BUTTON_TEXT }}
PARAMETERS: ${{ vars.PARAMETERS }}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Defina as variáveis na aba `Variables` do repositório:

`TOPIC`: (opcional) ID do tópico em que a mensagem será enviada. Necessário para grupos com a opção de tópicos ativada. [Como obter um ID de um tópico](#id-de-tópico)

`HIDE_BUTTON`: (opcional) Caso definida, desabilita o botão no envio, permitindo assim a existência do `Leitura Rápida`.

### Opções de variáveis

`{SITE_NAME}`: Nome do site;
Expand Down
27 changes: 16 additions & 11 deletions rss2telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get_variable(variable):
BOT_TOKEN = os.environ.get('BOT_TOKEN')
EMOJIS = os.environ.get('EMOJIS', '🗞,📰,🗒,🗓,📋,🔗,📝,🗃')
PARAMETERS = os.environ.get('PARAMETERS', False)
HIDE_BUTTON = os.environ.get('HIDE_BUTTON', False)
DRYRUN = os.environ.get('DRYRUN')
TOPIC = os.environ.get('TOPIC', False)

Expand Down Expand Up @@ -81,19 +82,23 @@ def send_message(topic, button):
btn = types.InlineKeyboardButton(f'{button}', url=topic['link'])
btn_link.row(btn)

if topic['photo']:
response = requests.get(topic['photo'], headers = {'User-agent': 'Mozilla/5.1'})
open('img', 'wb').write(response.content)
if HIDE_BUTTON:
for dest in DESTINATION.split(','):
photo = open('img', 'rb')
try:
bot.send_photo(dest, photo, caption=MESSAGE_TEMPLATE, parse_mode='HTML', reply_markup=btn_link, reply_to_message_id=TOPIC)
except telebot.apihelper.ApiTelegramException:
topic['photo'] = False
send_message(topic, button)
bot.send_message(dest, MESSAGE_TEMPLATE, parse_mode='HTML', reply_to_message_id=TOPIC)
else:
for dest in DESTINATION.split(','):
bot.send_message(dest, MESSAGE_TEMPLATE, parse_mode='HTML', reply_markup=btn_link, disable_web_page_preview=True, reply_to_message_id=TOPIC)
if topic['photo']:
response = requests.get(topic['photo'], headers = {'User-agent': 'Mozilla/5.1'})
open('img', 'wb').write(response.content)
for dest in DESTINATION.split(','):
photo = open('img', 'rb')
try:
bot.send_photo(dest, photo, caption=MESSAGE_TEMPLATE, parse_mode='HTML', reply_markup=btn_link, reply_to_message_id=TOPIC)
except telebot.apihelper.ApiTelegramException:
topic['photo'] = False
send_message(topic, button)
else:
for dest in DESTINATION.split(','):
bot.send_message(dest, MESSAGE_TEMPLATE, parse_mode='HTML', reply_markup=btn_link, disable_web_page_preview=True, reply_to_message_id=TOPIC)
print(f'... {topic["title"]}')
time.sleep(0.2)

Expand Down

0 comments on commit 8baa4dc

Please sign in to comment.