Best Python code snippet using robotframework-pageobjects_python
user_utils.py
Source:user_utils.py
1from functools import wraps2from src.backoffice.definitions import UI_message_accept_privacy_rules_to_continue, UI_message_disabled_account, \3 BOT_LOGS_CHAT_ID4from src.backoffice.models import TelegramUser5from src.telegram_bot.ormlayer import orm_get_telegram_user, orm_add_telegram_user, orm_get_telegram_log_group6def basic_user_checks(update, context):7 try:8 telegram_user_id = update.message.chat.id9 except AttributeError:10 try:11 telegram_user_id = update.edited_message.chat.id12 except AttributeError:13 print(update)14 if telegram_user_id == BOT_LOGS_CHAT_ID:15 telegram_user = orm_get_telegram_log_group(telegram_user_id)16 else:17 telegram_user = orm_get_telegram_user(telegram_user_id)18 must_return = False19 if check_if_user_is_disabled(telegram_user, update, context):20 must_return = True21 if check_user_privacy_approval(telegram_user, update, context):22 # privacy not yet approved by user23 must_return = True24 return telegram_user_id, telegram_user, must_return25def check_user_privacy_approval(telegram_user: TelegramUser, update, context):26 """return True if user has not yet approved the bot's privacy policy"""27 if telegram_user is None or not telegram_user.has_accepted_privacy_rules:28 print("check_user_privacy_approval - PRIVACY NOT APPROVED telegram_user_id=" + str(telegram_user.user_id))29 update.message.reply_text(UI_message_accept_privacy_rules_to_continue)30 return True31 else:32 return False33def check_if_user_is_disabled(telegram_user: TelegramUser, update, context):34 if not telegram_user.enabled:35 update.message.reply_text(36 UI_message_disabled_account37 )38 return True39 else:40 return False41def standard_user_checks(func):42 @wraps(func)43 def wrapped(update, context, *args, **kwargs):44 telegram_user_id, telegram_user, must_return = basic_user_checks(update, context)45 if must_return:46 return47 else:48 return func(update, context, telegram_user_id, telegram_user, *args, **kwargs)...
update_video_metadata.py
Source:update_video_metadata.py
1from django.core.management.base import BaseCommand2from videos.models import Video3from videos.metadata_manager import update_metadata4from time import sleep5import logging 6import sys7from time import sleep8import math9logger = logging.getLogger(__name__)10class Command(BaseCommand):11 12 def handle(self, *args, **kwargs):13 print 'Run update_metadata command'14 targets = Video.objects.all()15 percent_printed = 016 num = targets.count()17 count = 018 print "%s videos to go " % num19 must_return = False20 for x in targets.iterator():21 try:22 update_metadata(x.pk)23 percent = (((count * 1.0) / num) * 100)24 count +=1 25 if int(percent) > percent_printed:26 percent_printed = int(percent)27 print "Done %2s %%" % (percent_printed)28 except (KeyboardInterrupt, SystemExit):29 must_return = True30 except:31 print "failed for pk %s" % x.pk32 logger.exception("metadata import")33 if must_return:34 print "stopped at %s" % count35 return...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!