def send_post(submission, r2t): channels_list = get_all_public_channels() for channel in channels_list: bd_party, years = is_birthday_today(r2t, channel) if bd_party and years > 0: time.sleep(10) r2t.t_channel = get_dev_channel() plural = 's' if years != 1 else '' r2t.send_text('{channel} is {years} year{s} old.'.format( channel=channel, years=years, s=plural)) time.sleep(10) r2t.t_channel = channel text_to_send = '🎂🎂🎂\nToday {channel} is {years_cnt} year{s} old. '.format( channel=channel, years_cnt=years, s=plural) text_to_send += 'Congratulations! 🎈🎉🎉\n\n' list_of_channels = generate_list_of_channels( channels_list, random_permutation=True) text_to_send += 'Other channels powered by @r_channels:\n{list_of_channels}\n\n'.format( list_of_channels='\n'.join(list_of_channels)) text_to_send += default_ending() r2t.send_text(text_to_send) time.sleep(10) r2t.t_channel = get_dev_channel() r2t.send_text(text_to_send) # It's not a proper supply, so just stop. return SupplyResult.STOP_THIS_SUPPLY
def send_post(submission, r2t): channels_list = get_all_public_channels(r2t) for channel in channels_list: bd_party, years = is_birthday_today(r2t, channel) if bd_party and years > 0: plural = 's' if years != 1 else '' # To the @r_channels time.sleep(10) r2t.t_channel = '@r_channels' text_to_send = '🎂🎂🎂\nToday {channel} is {years_cnt} year{s} old.\nCongratulations! 🎁'.format( channel=channel, years_cnt=years, s=plural) r2t.send_text(text_to_send) # To the dev channel time.sleep(10) r2t.t_channel = get_dev_channel() r2t.send_text(text_to_send) # To the channels itself time.sleep(10) r2t.t_channel = channel text1_to_send = '🎂🎂🎂\nToday {channel} is {years_cnt} year{s} old. '.format( channel=channel, years_cnt=years, s=plural) text1_to_send += 'Congratulations! 🎈🎉🎉\n\n' list_of_channels = generate_list_of_channels(channels_list, random_permutation=True) text3_to_send = default_ending() r2t.send_text(text1_to_send) time.sleep(2) text2_to_send = 'Other @reddit2telegram channels powered by @r_channels:\n' for l in chunker(list_of_channels, 100): text2_to_send += '\n'.join(l) r2t.send_text(text2_to_send) text2_to_send = '' time.sleep(2) r2t.send_text(text3_to_send) # To the dev channel again time.sleep(10) r2t.t_channel = get_dev_channel() r2t.send_text(text1_to_send) time.sleep(2) text2_to_send = 'Other @reddit2telegram channels powered by @r_channels:\n' for l in chunker(list_of_channels, 100): text2_to_send += '\n'.join(l) r2t.send_text(text2_to_send) text2_to_send = '' time.sleep(2) r2t.send_text(text3_to_send) # It's not a proper supply, so just stop. return SupplyResult.STOP_THIS_SUPPLY
def send_post(submission, r2t): channels_list = get_all_public_channels(r2t) for submodule_name in get_all_public_submodules(): submodule = importlib.import_module( 'channels.{}.app'.format(submodule_name)) channel = submodule.t_channel bd_party, years = is_birthday_today(r2t, channel) if bd_party and years > 0: plural = 's' if years != 1 else '' # To the @r_channels long_sleep() r2t.t_channel = '@r_channels' cakes = '🎂' * years text_to_send = '{cake}\n🎁 Today {channel} is {years_cnt} year{s} old.\n🎉 Congratulations! 🎈'.format( channel=channel, years_cnt=years, s=plural, cake=cakes) r2t.send_text(text_to_send) # To the dev channel long_sleep() r2t.t_channel = get_dev_channel() r2t.send_text(text_to_send) # To the channels itself long_sleep() r2t.t_channel = channel text1_to_send = text_to_send list_of_channels = generate_list_of_channels( channels_list, random_permutation=True) text3_to_send = default_ending() r2t.send_text(text1_to_send) short_sleep() text2_to_send = 'Other @reddit2telegram channels powered by @r_channels:\n' for l in chunker(list_of_channels, 100): text2_to_send += '\n'.join(l) r2t.send_text(text2_to_send) text2_to_send = '' short_sleep() r2t.send_text(text3_to_send) long_sleep() if channel != '@reddit2telegram': config = get_config() send_to_channel_from_subreddit( how_to_post=make_nice_submission, channel_to_post='@reddit2telegram', subreddit=submodule.subreddit, submodule_name_to_promte=submodule_name, submissions_ranking='top', submissions_limit=1000, config=config, extra_args=True, extra_ending=text_to_send) long_sleep() # It's not a proper supply, so just stop. return SupplyResult.STOP_THIS_SUPPLY
def send_post(submission, r2t): config_filename = 'configs/prod.yml' with open(config_filename) as config_file: config = yaml.load(config_file.read()) settings = pymongo.MongoClient( host=config['db']['host'])[config['db']['name']]['settings'] settings.ensure_index([('setting', pymongo.ASCENDING)]) last_update_doc = settings.find_one({ 'setting': SETTING_NAME, }) if last_update_doc is None: last_update_doc = {'last_update': 0} settings.insert_one({'setting': SETTING_NAME, 'last_update': 0}) updates = r2t.telepot_bot.getUpdates(offset=last_update_doc['last_update']) last_update = 0 for update in updates: # pprint(update) time.sleep(2) last_update = update['update_id'] if 'message' not in update: continue if 'chat' not in update['message']: continue if 'text' not in update['message']: continue user_id = update['message']['chat']['id'] if not isinstance(user_id, int) or user_id < 0: continue message_id = update['message']['message_id'] r2t.telepot_bot.forwardMessage(chat_id=get_dev_channel(), from_chat_id=user_id, message_id=message_id) settings.find_one_and_update({'setting': SETTING_NAME}, {'$set': { 'last_update': last_update }}) # It's not a proper supply, so just stop. return SupplyResult.STOP_THIS_SUPPLY
#encoding:utf-8 import time from utils import SupplyResult from utils.tech import is_birthday_today, get_all_public_channels, get_dev_channel from utils.tech import generate_list_of_channels, default_ending subreddit = 'all' t_channel = get_dev_channel() def send_post(submission, r2t): channels_list = get_all_public_channels(r2t) for channel in channels_list: bd_party, years = is_birthday_today(r2t, channel) if bd_party and years > 0: plural = 's' if years != 1 else '' # To the @r_channels time.sleep(10) r2t.t_channel = '@r_channels' text_to_send = '🎂🎂🎂\nToday {channel} is {years_cnt} year{s} old.\nCongratulations! 🎁'.format( channel=channel, years_cnt=years, s=plural) r2t.send_text(text_to_send) # To the dev channel time.sleep(10) r2t.t_channel = get_dev_channel() r2t.send_text(text_to_send) # To the channels itself time.sleep(10)
def send_post(submission, r2t): config_filename = 'configs/prod.yml' with open(config_filename) as config_file: config = yaml.safe_load(config_file.read()) settings = pymongo.MongoClient( host=config['db']['host'])[config['db']['name']]['settings'] settings.ensure_index([('setting', pymongo.ASCENDING)]) last_update_doc = settings.find_one({ 'setting': SETTING_NAME, }) if last_update_doc is None: last_update_doc = {'last_update': 0} settings.insert_one({'setting': SETTING_NAME, 'last_update': 0}) updates = r2t.telegram_bot.get_updates( offset=last_update_doc['last_update']) last_update = 0 for update in updates: # print(update) update = update.to_dict() # short_sleep() if 'qwerrty' in str(update): print(update) last_update = update['update_id'] if 'message' not in update: continue if 'chat' not in update['message']: continue if 'text' not in update['message']: continue # print(update) user_id = update['message']['chat']['id'] if not isinstance(user_id, int) or user_id < 0: continue message_id = update['message']['message_id'] r2t.telegram_bot.forward_message(chat_id=get_dev_channel(), from_chat_id=user_id, message_id=message_id) if int(update['message']['chat']['id']) == int( config['telegram']['papa']): # print('>>>>>>>>>>>>>>>>>^^^^^^^^^^^^^^') text = update['message']['text'] lines = text.split('\n') if 'please' not in lines[0].lower(): continue new_channel_name = lines[1].split(': ')[-1] new_subreddit = lines[2].split('/')[-1] new_tags = lines[3].split(': ')[-1] utils.channels_stuff.set_new_channel(new_channel_name, subreddit=new_subreddit, tags=new_tags) settings.find_one_and_update({'setting': SETTING_NAME}, {'$set': { 'last_update': last_update }}) # It's not a proper supply, so just stop. return SupplyResult.STOP_THIS_SUPPLY