Best Python code snippet using lettuce-tools_python
gift.py
Source:gift.py
1# encoding: utf-82from common import uid, qz_path, pprint3import sys4sys.path.insert(0, qz_path)5import apps.settings_stg as settings_stg6from django.core.management import setup_environ7setup_environ(settings_stg)8from apps.models.user_gift import UserGift9from apps.models.user_login import UserLogin10from apps.models.user_base import UserBase11from apps.config.game_config import game_config12from apps.models.user_cards import UserCards13from apps.models.user_property import UserProperty14from apps.models.user_dungeon import UserDungeon15from apps.models.user_pack import UserPack16from apps.models.user_property import UserProperty17from apps.models.user_equips import UserEquips18from apps.models.collection import UserCollection19import json20import copy21import datetime22from apps.common.utils import create_gen_id23from apps.common import utils, tools24import time25from apps.models import data_log_mod26from apps.models import GameModel27ug = UserGift.get_instance(uid)28rk_user = UserBase.get(uid)29ul = rk_user.user_login30def show_gift():31 ug = UserGift.get_instance(uid)32 pprint(ug.gift_list)33def add_gift():34 ug = UserGift.get_instance(uid)35 ug.add_open_server_gift({'gold': 50, '1_card':1}, 8)36 ug.do_put()37#add_gift()38def get_gift():39 ug.get_gift('2')40 ug.do_put()41#get_gift()42#show_gift()43def clear_all_gifts():44 ug.gift_list = {}45 ug.do_put()46#clear_all_gifts()47def clear_open_server():48 49 #print(ug.open_server_record)50 #ug.clear_open_server_gift()51 #ug.do_put()52 print(ug.open_server_record)53#clear_open_server()54def _got_days(ug):55 '''å·²é¢åå¼æå¥å±ç天æ°'''56 days = 057 for info in ug.open_server_record['gifts'].values():58 if info['has_got']:59 days += 160 return days61def show_open_server_gift(rk_user, params):62 '''63 è¿åå¼æå¥å±ç礼å
64 '''65 ug = rk_user.user_gift66 ul = rk_user.user_login67 add_time = utils.timestamp_toDatetime(rk_user.add_time)68 now = datetime.datetime.now()69 today = utils.get_today_str()70 # åå§å71 if not ug.open_server_record:72 # 'gifts'æé¢å天æ°è®°å½å¥å±æ¯å¦é¢åï¼æ¯å¦ç»å½è¿10天ï¼ä½åªé¢è¿ä¸æ¬¡ï¼è¿æ¶giftsè®°å½çæ¯['1']['has_got']=True ,å
¶ä»ä¸ºFalse73 # å 为æ¯å¤©åªè½é¢åä¸æ¬¡ï¼'date_info'ç¨æ¥ææ¥æè®°å½åªå¤©æ¯å¦å·²é¢è¿ä¸æ¬¡74 ug.open_server_record = {'gifts': {}, 'date_info': {}}75 for day in range(1, 32):76 ug.open_server_record['gifts'].setdefault(str(day), {})['has_got'] = False77 ug.do_put()78 # è´¦å·æ³¨å已达45天ï¼å
æ¬æ³¨åå½å¤©ï¼ï¼æè
å
¨é¨é¢åäºï¼åæ¸
空å
¨é¨å¼æ礼å
79 if (now - add_time).days + 1 > 45 or ug.has_got_all_open_server_gifts():80 ug.clear_open_server_gift()81 return 11, {'msg': utils.get_msg('gift','clear_open_server')}82 awards = game_config.loginbonus_config['open_server_gift'].get('awards', {})83 data = {'gifts': {}}84 for days, award in awards.items():85 data['gifts'].setdefault(days, {})['awards'] = award86 #data['gifts'][days]['has_got'] = ug.open_server_record.setdefault(days, {}).setdefault('has_got', False)87 data['gifts'][days]['has_got'] = ug.open_server_record['gifts'][days]['has_got']88 # ç»å端ç°å®è½å¦é¢åï¼ä¸éåå¨modelä¸89 #data['gifts'][days]['can_get'] = True if ul.total_login_num >= int(days) else False90 if int(days) == _got_days(ug)+1 and not ug.open_server_record['date_info'].get(today, False):91 data['gifts'][days]['can_get'] = True92 else:93 data['gifts'][days]['can_get'] = False 94 ug.do_put()95 return 0, data96#pprint(show_open_server_gift(rk_user, {}))97def get_open_server_gift(rk_user, params):98 '''99 é¢åå¼æ礼å
ä¸çå¥å±100 åæ°101 params['day'] 第å 次é¢102 '''103 #day = params['day']104 day = '5'105 ug = rk_user.user_gift106 ul = rk_user.user_login107 awards = game_config.loginbonus_config['open_server_gift'].get('awards', {})108 if day not in awards.keys():109 return 11, {'msg': utils.get_msg('gift', 'gift_not_exist')}110 the_gift = ug.open_server_record['gifts'][day]111 if the_gift['has_got']:112 return 11, {'msg': utils.get_msg('gift', 'gift_has_got')}113 today = utils.get_today_str()114 if ug.open_server_record['date_info'].get(today, False):115 return 11, {'msg': utils.get_msg('gift', 'today_has_signed_in')}116 # æ顺åºé¢å117 if int(day) != _got_days(ug)+1:118 return 11, {'msg': utils.get_msg('gift', 'signin_in_turn')}119 data = tools.add_things(120 rk_user, 121 [{"_id": goods, "num": awards[goods]} for goods in awards if goods],122 where="open_server_gift"123 )124 the_gift['has_got'] = True125 # å 为æ¯å¤©åªè½é¢åä¸æ¬¡ï¼'date_info'ç¨æ¥ææ¥æè®°å½åªå¤©æ¯å¦å·²é¢è¿ä¸æ¬¡126 ug.open_server_record['date_info'][today] = True 127 ug.do_put()128 return 0, data129#print('get_open_server_gift(rk_user, {})')130#pprint(get_open_server_gift(rk_user, {}))131#print('show_open_server_gift(rk_user, {})')132#pprint(show_open_server_gift(rk_user, {}))133def test_clear_open_server_gift():134 ug.clear_open_server_gift()135 ug.do_put()136#test_clear_open_server_gift()137def test_init_open_server_gift():138 ul.init_open_server_gift()139 ug.do_put() 140#test_init_open_server_gift()141def test_has_got_today_gift():142 return ug.has_got_today_open_server_gift()143#print 'has got: ',test_has_got_today_gift()144def _get_total_sign_in_days(ug):145 days = 0146 for info in ug.sign_in_record.values():147 if info['has_got']:148 days += 1149 return days150def get_sign_in_gift(rk_user, params):151 '''152 é¢åç¾å°å¥å±153 params['day'] å½ææ¥æï¼ä½ä¸ºid使ç¨154 '''155 day = '5' 156 ug = rk_user.user_gift157 now = datetime.datetime.now()158 month = str(now.month)159 today = str(now.day)160 print ' _get_total_sign_in_days(ug)', _get_total_sign_in_days(ug)161 if day != str(_get_total_sign_in_days(ug) + 1):162 return 11, {'msg': utils.get_msg('gift', 'signin_in_turn')}163 if ug.sign_in_record[day]['has_got']:164 return 11, {'msg': utils.get_msg('gift', 'gift_has_got')}165 if ug.sign_in_record[today].get('today_has_signed_in', False):166 return 11, {'msg': utils.get_msg('gift', 'today_has_signed_in')} 167 # æ·»å å¥å±168 awards = game_config.loginbonus_config['sign_in_bonus'].get(month, {}).get(day, {})169 data = tools.add_things(170 rk_user, 171 [{"_id": goods, "num": awards[goods]} for goods in awards if goods],172 where="open_server_gift"173 )174 ug.sign_in_record[day]['has_got'] = True175 # æ¯å¤©åªè½ç¾å°ä¸æ¬¡ï¼æ¤å段ç¨æ¥å端å¤æå½å¤©æ¯å¦å·²ç¾å°è¿176 ug.sign_in_record[today]['today_has_signed_in'] = True177 ug.do_put() 178 rk_user.user_property.do_put()179 rk_user.user_pack.do_put()180 rk_user.user_cards.do_put()181 rk_user.user_equips.do_put() 182 return 0, data183#pprint(ug.sign_in_record)184pprint(get_sign_in_gift(rk_user, {}))185def show_sign_in_gift(rk_user, params):186 '''187 è¿åå端å½æç¾å°å¥å±ä¿¡æ¯188 '''189 now = datetime.datetime.now()190 month = str(now.month)191 #month = '1' 192 today = str(now.day)193 awards = game_config.loginbonus_config['sign_in_bonus'].get(month, {})194 if not awards:195 return 11, {'msg': utils.get_msg('gift', 'no_sign_in_gift')}196 data = {'gifts': {}}197 ug = rk_user.user_gift198 # å½ææ»ç¾å°å¤©æ°199 sign_in_days = _get_total_sign_in_days(ug)200 # å½ææ»ç»é天æ°201 month_login_days = rk_user.user_login.month_total_login202 # æ°çæ份ï¼é¢åä¿¡æ¯å
¨é¨ç½®False203 if today == '1':204 for n in range(31):205 ug.sign_in_record[str(n)]['has_got'] = False206 ug.sign_in_record[str(n)]['today_has_signed_in'] = False207 for day, award in awards.items():208 data['gifts'].setdefault(day, {})['awards'] = award209 data['gifts'][day]['has_got'] = ug.sign_in_record.setdefault(day, {}).setdefault('has_got', False)210 #if int(day) == sign_in_days+1:211 if int(day) == sign_in_days+1 and not ug.sign_in_record.setdefault(today, {}).setdefault('today_has_signed_in', False):212 data['gifts'][day]['can_get'] = True213 else:214 data['gifts'][day]['can_get'] = False215 ug.do_put()216 data['total_sign_in_days'] = _get_total_sign_in_days(ug)217 data['month_login_days'] = month_login_days218 return 0, data ...
property.py
Source:property.py
1# encoding: utf-82from common import uid, qz_path, pprint3import sys4sys.path.insert(0, qz_path)5import apps.settings_stg as settings_stg6from django.core.management import setup_environ7setup_environ(settings_stg)8from apps.models.user_gift import UserGift9from apps.models.user_login import UserLogin10from apps.models.user_base import UserBase11from apps.config.game_config import game_config12from apps.models.user_cards import UserCards13from apps.models.user_property import UserProperty14from apps.models.user_dungeon import UserDungeon15from apps.models.user_pack import UserPack16from apps.models.user_property import UserProperty17from apps.models.user_equips import UserEquips18from apps.models.collection import UserCollection19from apps.models.user_souls import UserSouls20import json21import copy22import datetime23from apps.common.utils import create_gen_id24from apps.common import utils25import time26from apps.models import data_log_mod27from apps.models import GameModel28#uid = '9100214781'29game_config.subareas_conf()30game_config.set_subarea('1')31up = UserProperty.get_instance(uid)32pprint(up.property_info)33def show_property_fields():34 user_property_obj = UserProperty.get_instance(uid)35 print 'user_property_obj.property_info','-'*5036 pprint(user_property_obj.property_info)37 #user_property_obj.property_info['wipe_out_times'] = 038 #user_property_obj.do_put()39 '''40 print 'user_property_obj.charge_award_info','-'*5041 print user_property_obj.charge_award_info42 print 'user_property_obj.consume_award_info','-'*5043 print user_property_obj.consume_award_info44 print 'user_property_obj.month_item_info','-'*5045 print user_property_obj.month_item_info46 '''47show_property_fields()48def modify_today_str():49 up.property_info['recover_times']['today_str'] = '2014-11-15'50 up.do_put()51#modify_today_str()52def add_stamina():53 up.add_stamina(100)54 up.do_put()55#add_stamina()56def t_give_award():57 user_property_obj = UserProperty.get_instance(uid)58 user_property_obj.give_award({'gold':3})59 user_property_obj.do_put()60#t_give_award()61def property_real_pvp():62 user_property_obj = UserProperty.get_instance(uid)63 user_real_pvp = user_property_obj.user_base.user_real_pvp64 print user_real_pvp65#property_real_pvp()66def ttest_give_award():67 user_property = UserProperty.get_instance(uid)68 uc = UserCards.get_instance(uid) 69 ue = UserEquips.get_instance(uid) 70 up = UserPack.get_instance(uid)71 us = UserSouls.get_instance(uid) 72 #award = {'card':{'1_card':1}}73 #award = {'equip':{'13001_equip': 2}}74 #award = {'props':{'1_props':2}}75 #award = {'soul':{'card':{'1_card':1}}}76 award = {'soul':{'equip':{'13001_equip':1}}}77 print user_property.test_give_award(award)78 uc.do_put() 79 ue.do_put()80 up.do_put()81 us.do_put()82#ttest_give_award()83 84def add_vip_lv():85 user_property = UserProperty.get_instance(uid)86 user_property.add_charge_sumcoin(10) # vip lv 187 #user_property.property_info["charge_sumcoin"] = 0 # vip lv 0 88 user_property.do_put() 89#add_vip_lv()90def modify_vip_lv(lv):91 '''vipç级æ¯éè¿ç©å®¶å
å¼å
å®çæ»æ°æ¥å¤æçï¼æ²¡vipç级è¿ä¸ªå段ï¼æ以æ¯é´æ¥æ¹'''92 vip_conf = game_config.user_vip_config[str(lv)] 93 coin = vip_conf['coin']94 up = UserProperty.get_instance(uid)95 #up.add_charge_sumcoin(coin)96 up.property_info["charge_sumcoin"] = coin97 up.do_put()98#modify_vip_lv(1)99def set_newbie():100 upp = up.property_info101 #upp['newbie'] = False 102 #upp['newbie_steps'] = 63 103 #upp['stamina'] = 100104 up.do_put()105 print upp['newbie_steps'], upp['newbie']106#set_newbie()107def get_info():108 print up.property_info109 print up.vip_cur_level110#get_info() 111 112def modify_attr():113 up = UserProperty.get_instance(uid)114 up.property_info['lv'] = 43115 up.do_put()...
new_account.py
Source:new_account.py
1# encoding: utf-82from common import uid, qz_path3import sys4sys.path.insert(0, qz_path)5import apps.settings_stg as settings_stg6from django.core.management import setup_environ7setup_environ(settings_stg)8from apps.models.user_gift import UserGift9from apps.models.user_login import UserLogin10from apps.models.user_base import UserBase11from apps.config.game_config import game_config12from apps.models.user_cards import UserCards13from apps.models.user_property import UserProperty14from apps.models.user_dungeon import UserDungeon15from apps.models.user_pack import UserPack16from apps.models.user_property import UserProperty17from apps.models.user_equips import UserEquips18from apps.models.collection import UserCollection19from apps.models.user_souls import UserSouls20from apps.models.user_real_pvp import UserRealPvp21import json22import copy23import datetime24from apps.common.utils import create_gen_id25from apps.common import utils26import time27from apps.models import data_log_mod28from apps.models import GameModel29game_config.subareas_conf()30game_config.set_subarea('1')31up = UserProperty.get_instance(uid)32def add_honor():33 urp = UserRealPvp.get_instance(uid)34 urp.add_honor(99999)35 urp.do_put()36 print urp.honor37def add_vip_lv():38 user_property = UserProperty.get_instance(uid)39 user_property.add_charge_sumcoin(10) # vip lv 140 #user_property.property_info["charge_sumcoin"] = 0 # vip lv 0 41 user_property.do_put() 42#add_vip_lv()43def set_newbie():44 upp = up.property_info45 upp['newbie'] = False 46 upp['newbie_steps'] = 63 47 #upp['stamina'] = 10048 up.do_put()49 print upp['newbie_steps'], upp['newbie']50def set_user_lv():51 up.property_info['lv'] = 40 52 up.do_put()53'''æ°è´¦å·åä¸äºæä½ï¼æ¹ä¾¿è°è¯'''54def add_equip():55 ue = UserEquips.get_instance(uid)56 ue.add_equip('12001_equip') # 4个è£
å¤é½æ¯ç«äºå¥57 ue.add_equip('22001_equip')58 ue.add_equip('32001_equip')59 ue.add_equip('42001_equip')60 ue.add_equip('53003_equip') # è¯ç»61 ue.add_equip('63003_equip') # æ²éé£62 ue.do_put()63def new_account():64 add_equip()65 set_newbie()66 add_honor()67 set_user_lv()68 pass69new_account()...
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!!