Skip to content

Instantly share code, notes, and snippets.

@qiwichupa
Created February 23, 2024 00:35
Show Gist options
  • Save qiwichupa/62fb50cbe6f5e35c5514f81fbd7b8657 to your computer and use it in GitHub Desktop.
Save qiwichupa/62fb50cbe6f5e35c5514f81fbd7b8657 to your computer and use it in GitHub Desktop.
sending to telegram channel: tsend.py <channel id> "<message>"
#!/usr/bin/python3
import time
import config
import telebot
import sys
import os
from emoji import emojize
bottoken="<token>"
proxy = '<IP>:<PORT>'
os.environ['http_proxy'] = proxy
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy
# it is for usergate (ssl cert check disable)
os.environ['CURL_CA_BUNDLE'] = ''
os.environ['PYTHONWARNINGS'] = 'ignore:Unverified HTTPS request'
bot = telebot.TeleBot(bottoken)
def send_new_post(chat_id, item):
try:
emoj = emojize(item, use_aliases=True)
result = bot.send_message(chat_id, emoj)
time.sleep(1)
return 0
except:
print("Error: " + str(sys.exc_info()[0]))
print(str(sys.exc_info()[1]))
return 1
if __name__ == '__main__':
f = open('/var/log/tsend.log', 'a')
chat_id = sys.argv[1]
message = sys.argv[2]
f.write('\n-\n' + chat_id + ' ' + message + '\n')
exitcode = send_new_post(chat_id, message)
f.closed
sys.exit(exitcode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment