You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.0 KiB
55 lines
2.0 KiB
import twitter
|
|
from telegram import Update
|
|
from telegram.ext import CallbackContext
|
|
|
|
pepito_id = 333923305
|
|
last_status = None
|
|
pepito_groups = []
|
|
|
|
|
|
def get_twitter_instance():
|
|
twitter_config = {}
|
|
with open("config/twitter_config") as tmp_file:
|
|
for line in tmp_file:
|
|
(key, val) = line.split('=')
|
|
twitter_config[key] = val.replace('\n', '')
|
|
|
|
return twitter.Api(consumer_key=twitter_config['consumer_key'],
|
|
consumer_secret=twitter_config['consumer_secret'],
|
|
access_token_key=twitter_config['access_token_key'],
|
|
access_token_secret=twitter_config['access_token_secret'])
|
|
|
|
|
|
def toggle_pepito_for_group(update: Update, context: CallbackContext):
|
|
global pepito_groups
|
|
chat_id = update.message.chat_id
|
|
|
|
if chat_id in pepito_groups:
|
|
pepito_groups.remove(chat_id)
|
|
update.message.reply_text("Pepito is now disabled!")
|
|
else:
|
|
pepito_groups.append(update.message.chat_id)
|
|
update.message.reply_text("Pepito is now enabled!")
|
|
|
|
|
|
def check_pepito_and_post_auto(context: CallbackContext):
|
|
api = get_twitter_instance()
|
|
current_status = api.GetUserTimeline(pepito_id)[0]
|
|
global last_status
|
|
if last_status is None or last_status.AsDict()['id'] != current_status.AsDict()['id']:
|
|
for group_id in pepito_groups:
|
|
context.bot.send_message.send_message(chat_id=group_id, text=current_status.AsDict()['text'])
|
|
last_status = current_status
|
|
|
|
|
|
def check_pepito_and_post_manually(update: Update, context: CallbackContext):
|
|
api = get_twitter_instance()
|
|
current_status = api.GetUserTimeline(pepito_id)[0]
|
|
global last_status
|
|
|
|
if last_status.AsDict()['id'] != current_status.AsDict()['id']:
|
|
for group_id in pepito_groups:
|
|
context.bot.send_message(chat_id=group_id, text=current_status.AsDict()['text'])
|
|
last_status = current_status
|
|
else:
|
|
update.message.reply_text(current_status.AsDict()['text'])
|