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...
Check out the latest blogs from LambdaTest on this topic:
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Building a website is all about keeping the user experience in mind. Ultimately, it’s about providing visitors with a mind-blowing experience so they’ll keep coming back. One way to ensure visitors have a great time on your site is to add some eye-catching text or image animations.
Agile has unquestionable benefits. The mainstream method has assisted numerous businesses in increasing organizational flexibility as a result, developing better, more intuitive software. Distributed development is also an important strategy for software companies. It gives access to global talent, the use of offshore outsourcing to reduce operating costs, and round-the-clock development.
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
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!!