How to use post_message method in SeleniumBase

Best Python code snippet using SeleniumBase

morgenbot.py

Source:morgenbot.py Github

copy

Full Screen

...26time = []27in_progress = False28current_user = ''29absent_users = []30def post_message(text, attachments=[]):31 slack.chat.post_message(channel = channel,32 text = text,33 username = username,34 parse = 'full',35 link_names = 1,36 attachments = attachments,37 icon_emoji = icon_emoji)38def get_user(id):39 user = slack.users.info(id).body40 return user['user']['name']41def get_channel(id):42 channel = slack.channels.info(id).body43 return channel['channel']['name']44def init():45 global users46 global topics47 global time48 global in_progress49 if len(users) != 0:50 post_message('Looks like we have a standup already in process.')51 return52 users = standup_users()53 topics = []54 time = []55 in_progress = True56 post_message('%s, @channel! Please type !start when you are ready to stand up.' % init_greeting)57def start():58 global time59 if len(time) != 0:60 post_message('But we\'ve already started!')61 return62 time.append(datetime.datetime.now())63 post_message('Let\'s get started! %s\nWhen you\'re done, please type !next' % start_message)64 next()65def cancel():66 tabled()67 post_message('Standup is cancelled. Bye!')68 reset()69def done():70 global time71 time.append(datetime.datetime.now())72 standup_time()73 tabled()74 post_message('Bye!')75 reset()76def reset():77 global users78 global topics79 global time80 global in_progress81 global current_user82 del users[:]83 del topics[:]84 del time[:]85 in_progress = False86 current_user = ''87def standup_users():88 global ignore_users89 global absent_users90 ignore_users_array = eval(ignore_users)91 channel_id = '';92 channel_name = channel.replace('#', '') # for some reason we skip the # in this API call93 all_channels = slack.channels.list(1) # 1 means we skip any archived rooms94 for one_channel in all_channels.body['channels']:95 if one_channel['name'] == channel_name:96 channel_id = one_channel['id']97 standup_room = slack.channels.info(channel_id).body['channel']98 standup_users = standup_room['members']99 active_users = []100 for user_id in standup_users:101 user_name = slack.users.info(user_id).body['user']['name']102 is_deleted = slack.users.info(user_id).body['user']['deleted']103 if not is_deleted and user_name not in ignore_users_array and user_name not in absent_users:104 active_users.append(user_name)105 # don't forget to shuffle so we don't go in the same order every day!106 random.shuffle(active_users)107 return active_users108def next():109 global users110 global current_user111 if len(users) == 0:112 done()113 else:114 current_user = users.pop()115 post_message('@%s, you\'re up' % current_user)116def standup_time():117 if len(time) != 2: return118 seconds = (time[1] - time[0]).total_seconds()119 minutes = seconds / 60120 post_message('That\'s everyone! Standup took us %d minutes.' % minutes)121def left():122 if len(users) == 0:123 post_message('That\'s everyone!')124 else:125 post_message('Here\'s who\'s left: @' + ', @'.join(users))126def ignore(user):127 global ignore_users128 global absent_users129 active_users = standup_users()130 if user == '':131 post_message('Who should I ignore?')132 return133 user = user[1:]134 if user not in active_users and user not in ignore_users and user not in absent_users:135 post_message('I don\'t recognize that user.')136 elif user in ignore_users or user in absent_users:137 post_message('I\'m already ignoring that user.')138 elif user in active_users:139 absent_users.append(user)140 post_message('I won\'t call on @%s again until I am told to using !heed <username>.' % user)141def heed(user):142 global ignore_users143 global absent_users144 active_users = standup_users()145 if user == '':146 post_message('Who should I heed?')147 return148 user = user[1:]149 if user not in active_users and user not in ignore_users and user not in absent_users:150 post_message('I don\'t recognize that user.')151 elif user in ignore_users:152 post_message('We never call on that user. Try asking my admin to heed that username.')153 elif user in active_users:154 post_message('I\'m not ignoring that user.')155 elif user in absent_users:156 absent_users.remove(user)157 post_message('I\'ll start calling on @%s again at the next standup.' % user)158def ignoring():159 global ignore_users160 global absent_users161 if len(ignore_users) == 0 and len(absent_users) == 0:162 post_message('We\'re not ignoring anyone.')163 return164 if len(ignore_users) != 0:165 post_message('Here\'s who we never call on: ' + ignore_users)166 if len(absent_users) != 0:167 post_message('Here\'s who we\'re ignoring for now: ' + ', '.join(absent_users))168def skip():169 post_message('Skipping @%s.' % current_user)170 next()171 172def later():173 post_message('We\'ll call on @%s later.' % current_user)174 users.append(current_user)175 next()176def table(topic_user, topic):177 global topics178 channels = re.findall(r"<#(.*?)>", topic)179 users = re.findall(r"<@(.*?)>", topic)180 for channel in channels:181 channel_name = get_channel(channel)182 topic = topic.replace('<#%s>' % channel, '#%s' % channel_name)183 for user in users:184 user_name = get_user(user)185 topic = topic.replace('<@%s>' % user, '@%s' % user_name)186 post_message('@%s: Tabled.' % topic_user)187 topics.append(str(topic))188def tabled():189 if len(topics) == 0: return190 post_message('Tabled topics:')191 for topic in topics:192 post_message('-%s' % topic)193def giphy(text):194 url = 'http://api.giphy.com/v1/gifs/search?q=%s&api_key=dc6zaTOxFJmzC&limit=1' % urllib2.quote(text.encode("utf8"))195 response = urllib2.urlopen(url)196 data = json.loads(response.read())197 if len(data['data']) == 0:198 post_message('Not sure what "%s" is.' % text)199 else:200 attachments = [{201 'fallback': text,202 'title': text,203 'title_link': data['data'][0]['url'],204 'image_url': data['data'][0]['images']['fixed_height']['url']205 }]206 post_message('Not sure what "%s" is.' % text, json.dumps(attachments))207def ready(msguser):208 global ignore_users209 global absent_users210 global current_user211 global users212 active_users = standup_users()213 if msguser == '':214 post_message('Your username is blank. Are you a ghost?')215 return216 if msguser not in active_users and msguser not in ignore_users and msguser not in absent_users:217 post_message('I don\'t recognize you. How did you get in here?')218 elif msguser in ignore_users:219 post_message('I\'m ignoring you. Try asking my admin to heed you.')220 elif msguser in absent_users:221 post_message('I\'ll come back to you, @%s' % current_user)222 users.append(current_user)223 current_user = msguser224 absent_users.remove(msguser)225 post_message('Welcome back, @%s. We will call on you from now on.' % msguser)226 elif msguser in users:227 post_message('I\'ll come back to you, @%s' % current_user)228 users.append(current_user)229 current_user = msguser230 users.remove(msguser)231 post_message('Alright @%s, go ahead' % msguser)232 elif msguser == current_user:233 post_message('It\'s already your turn. Go ahead.')234 else:235 post_message('You already went during this standup')236def help(topic=''):237 if topic == '':238 post_message('My commands are !standup, !start, !cancel, !next, !ready, !skip, !later, !table, !left, !ignore, !heed, and !ignoring.\nAsk me "!help <command> to learn what they do.')239 return240 topic = topic[1:]241 if topic == 'standup' or topic == '!standup':242 post_message('Type !standup to initiate a new standup')243 elif topic == 'start' or topic == '!start':244 post_message('Type !start to get started with standup once everyone is ready')245 elif topic == 'cancel' or topic == '!cancel':246 post_message('Type !cancel if you\'d like to stop the standup entirely.')247 elif topic == 'next' or topic == '!next':248 post_message('Type !next to call on the next person when you\'re done standing up')249 elif topic == 'skip' or topic == '!skip':250 post_message('Type !skip to skip someone who isn\'t standing up that day')251 elif topic == 'later' or topic == '!later':252 post_message('Type !later to move someone who isn\'t ready yet to the end of the list')253 elif topic == 'table' or topic == '!table':254 post_message('Type !table <topic> to save a topic for later discussion. I\'ll list these for you when standup is over.')255 elif topic == 'left' or topic == '!left':256 post_message('Type !left to find out who is left in the standup')257 elif topic == 'ignore' or topic == '!ignore':258 post_message('Type !ignore <username> to temporarily skip a user during standup for a while')259 elif topic == 'heed' or topic == '!heed':260 post_message('Type !heed <username> to add an ignored user back, starting with the next standup')261 elif topic == 'ignoring' or topic == '!ignoring':262 post_message('Type !ignoring to find out who we\'re skipping over for standups')263 elif topic == 'ready' or topic == '!ready':264 post_message('Type !ready to skip ahead in the queue and give your standup immediately')265 else:266 post_message('Not sure what "%s" is.' % topic)267 if giphy:268 post_message('/giphy %s' % topic)269@app.route("/", methods=['POST'])270def main():271 # ignore message we sent272 msguser = request.form.get("user_name", "").strip()273 if msguser == username or msguser.lower() == "slackbot": return274 text = request.form.get("text", "")275 match = re.findall(r"^!(\S+)", text)276 if not match: return277 command = match[0]278 args = text[text.find("!%s" % command) + len(command) + 1:]279 command = command.lower()280 if command not in commands:281 if giphy:282 giphy("%s %s" % (command, args))283 else:284 post_message('Not sure what "%s" is.' % command)285 return json.dumps({ })286 elif not in_progress and command != 'standup' and command != 'help' and command != 'ignore' and command != 'heed' and command != 'ignoring':287 post_message('Looks like standup hasn\'t started yet. Type !standup.')288 return json.dumps({ })289 if command == 'standup':290 init()291 elif command == 'start':292 start()293 elif command == 'cancel':294 cancel()295 elif command == 'next':296 next()297 elif command == 'skip':298 skip()299 elif command == 'later':300 later()301 elif command == 'table':...

Full Screen

Full Screen

test_process.py

Source:test_process.py Github

copy

Full Screen

...5 _nullmsg = MessageEngine()6 chm = ProcessChamber(0)7 chm.post_chamber_message("message", ">>")8 pr1 = chm.add(Process(1, _nullmsg))9 pr1.post_message(ProcessMessage("A"))10 pr1.post_message(ProcessMessage("B"))11 pr1.post_message(ProcessMessage("C"))12 pr1.finish()13 chm.handle_messages()14 pr2 = chm.add(Process(2, _nullmsg))15 pr2.post_message(ProcessMessage("い"))16 pr2.post_message(ProcessMessage("ろ"))17 pr2.post_message(ProcessMessage("は"))18 pr2.finish()19 chm.handle_messages()20 pr3 = chm.add(Process(3, _nullmsg))21 pr3.post_message(ProcessMessage("金"))22 pr3.post_message(ProcessMessage("土"))23 pr3.post_message(ProcessMessage("日"))24 return chm25def test_handle_messages():26 chm = ten_messages_chamber_zero()27 assert [x.text for x in chm.get_handled_messages()] == [28 ">>", "A", "B", "C", "い", "ろ", "は"29 ]30 chm.handle_messages()31 assert [x.text for x in chm.get_handled_messages()] == [32 ">>", "A", "B", "C", "い", "ろ", "は", "金", "土", "日"33 ]34def test_drop_process():35 chm = ten_messages_chamber_zero()36 # プロセス3を開始する37 chm.get_process(3)._start_infinite_thread(TempSpirit())38 39 chm.drop_processes()40 # 稼働中のプロセスは停止されない41 assert [x.index for x in chm.get_processes()] == [3]42 chm.handle_messages()43 assert [x.text for x in chm.get_handled_messages()] == [44 ">>", "金", "土", "日"45 ]46def test_drop_process_if():47 chm = ten_messages_chamber_zero()48 chm.get_process(3).finish()49 chm.handle_messages()50 chm.drop_processes(pred=lambda x: x.index % 2 == 1) # 奇数IDのプロセスのみ削除する51 52 assert [x.index for x in chm.get_processes()] == [2]53 chm.handle_messages()54 assert [x.text for x in chm.get_handled_messages()] == [55 ">>", "い", "ろ", "は"56 ]57def test_handle_messages_gradually():58 chm = ProcessChamber(0)59 60 chm.post_chamber_message("message", "1")61 chm.post_chamber_message("message", "2")62 chm.post_chamber_message("message", "3")63 pr1 = chm.add(Process(1, MessageEngine()))64 pr1.post_message(ProcessMessage("A"))65 pr1.post_message(ProcessMessage("B"))66 pr1.post_message(ProcessMessage("C"))67 pr1.post_message(ProcessMessage("D"))68 pr1.post_message(ProcessMessage("E"))69 pr1.post_message(ProcessMessage("F"))70 pr1.post_message(ProcessMessage("G"))71 pr1.post_message(ProcessMessage("H"))72 pr1.post_message(ProcessMessage("I"))73 pr1.post_message(ProcessMessage("J"))74 msgs = chm.handle_messages(5)75 assert [x.text for x in msgs] == [76 "1", "2", "3", "A", "B"77 ]78 msgs = chm.handle_messages(5)79 assert [x.text for x in msgs] == [80 "C", "D", "E", "F", "G"81 ]82 msgs = chm.handle_messages(5)83 assert [x.text for x in msgs] == [84 "H", "I", "J"...

Full Screen

Full Screen

session.py

Source:session.py Github

copy

Full Screen

...10 email='davin@appliomics.com', bio='Chemist, Teacher, Father', photo='davin-potts-200.png')11set_user('selik', displayname='Michael Selik', password='newlywed7',12 email='mselik@example.com', bio='All problems are data science problems', photo='selik.jpg')13now = time()14post_message('raymondh', '#python tip: use named tuples', now-3600*48)15post_message('barry', 'join a band today', now-3600)16post_message('selik', 'gradient descent save me money on travel', now-2500)17post_message('raymondh', '#python tip: develop interactively', now-500)18post_message('barry', 'learn emacs', now-80)19post_message('davin', 'teaching #python today', now-50)20post_message('selik', 'have you ever wanted to unpack mappings?', now-46)21post_message('raymondh', '#python tip: have fun programming', now-40)22post_message('davin', '#camping tip: always take water', now-30)23post_message('barry', 'enums rock', now-20)24post_message('raymondh', '#python tip: never mutate while iterating', now-10)25post_message('davin', 'coriander and cilantro come from the same plant', now)26follow('davin', followed_user='raymondh')27follow('davin', followed_user='barry')28follow('selik', followed_user='davin')29follow('raymondh', followed_user='selik')30follow('raymondh', followed_user='barry')31if __name__ == '__main__':32 from pubsub import posts, followers, following, user_info33 from pubsub import posts_by_user, posts_for_user, search34 from pubsub import get_followers, get_followed, get_user, check_user, age35 assert check_user('raymondh', password='superman123')36 assert not check_user('davin', password='passw0rd')37 print()38 pprint(list(posts))39 print('\nFollowers')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful