How to use now_utc method in localstack

Best Python code snippet using localstack_python

__init__.py

Source:__init__.py Github

copy

Full Screen

1import time2from pytz import timezone3import nonebot4from nonebot import on_command5from nonebot.adapters import Bot, Event6from nonebot.rule import to_me7from nonebot.typing import T_State8from datetime import datetime91011from .config import Config1213global_config = nonebot.get_driver().config14plugin_config = Config(**global_config.dict())151617Cooky_time = on_command("", priority=5)1819t = time.localtime()20current_time = time.strftime("%H:%M:%S", t)2122format = "%H:%M"232425@Cooky_time.handle()26async def handle_first_receive(bot: Bot, event: Event, state: T_State):27 args = str(event.get_message()).strip() # 首次发送命令时跟随的参数,例:/时间 上海,则args为上海28 if args:29 state["city"] = args.replace("时间", "") # 如果用户发送了参数则直接赋值303132@Cooky_time.got("city", prompt="你想查询哪里的时间呢?")33async def handle_city(bot: Bot, event: Event, state: T_State):34 city = state["city"]35 #if city not in ["诺森德", "银色试炼场","北风苔原", "索拉查盆地","冬拥湖", "冰冠冰川","冰封王座","晶歌森林", "龙骨荒野", "风暴峭壁", "祖达克","灰熊丘陵", "嚎风峡湾",36 # "暴风城","诺莫瑞根","铁炉堡","幽暗城","银月城","藏宝湾","南海镇","通灵学院","斯坦索姆", "闪金镇","提瑞斯法领地", "银松森林", "艾尔文森林", "西部荒野",37 # "西瘟疫之地","奥特兰克山脉","希尔斯布莱德丘陵","阿拉斯高地","丹莫罗","炽热峡谷","燃烧平原","荆棘谷","逆风小径","奎尔丹纳斯岛","永歌森林","幽魂之地",38 # "东瘟疫之地","辛特兰","湿地","洛克莫丹","荒芜之地","赤脊山","悲伤沼泽","诅咒之地",39 # "奥格瑞玛","回音群岛","达纳苏斯","加基森","雷霆崖","泰达希尔","时光之穴","秘蓝岛","秘血岛","埃索达","月光林地","黑海岸","灰谷","费伍德森林","石爪山脉","凄凉之地","菲拉斯","希利苏斯",40 # "莫高雷","安戈洛","千针石林","莫高雷","贫瘠之地","海加尔山","冬泉谷","艾萨拉","尘泥沼泽","塔纳利斯","杜隆塔尔",41 # "七星殿","螳螂高原","恐惧废土","昆莱山","锦绣谷","四风谷","卡桑琅丛林","翡翠林","雷神岛",42 # "库尔提拉斯","伯拉勒斯","德鲁斯瓦","斯托颂谷地","提拉加德海峡","麦卡贡",43 # "赞达拉","达萨罗","沃顿","纳兹米尔","祖达萨","纳沙塔尔"44 # "大漩涡","科赞","破碎群岛"]:4546 # await Cooky_time.reject("你想查询的地区暂不支持,请重新输入!")47 city_time = await get_time(city)48 await Cooky_time.finish(city_time)495051async def get_time(city: str):52 if city in ["潘达利亚","七星殿" , "锦绣谷" , "四风谷" , "昆莱山" , "卡桑琅丛林" , "翡翠林" , "诺森德" , "银色试炼场" , "晶歌森林" , "龙骨荒野" , "风暴峭壁" , "祖达克" , "灰熊丘陵" , "嚎风峡湾"]:53 now_utc = datetime.now(timezone('UTC'))54 where_time = now_utc.astimezone(timezone('Asia/Shanghai'))55 now_gmt_8 = (where_time.strftime(format))5657 return f"现在是{city}时间" + now_gmt_85859 elif city in ["赞达拉" , "达萨罗" , "沃顿" , "纳兹米尔" , "祖达萨" , "纳沙塔尔"]:60 now_utc = datetime.now(timezone('UTC'))61 where_time = now_utc.astimezone(timezone('Pacific/Auckland'))62 now_gmt_12 = (where_time.strftime(format))6364 return f"现在是{city}时间" + now_gmt_126566 elif city in ["库尔提拉斯" , "伯拉勒斯" , "德鲁斯瓦" , "斯托颂谷地" , "提拉加德海峡" , "麦卡贡"]:67 now_utc = datetime.now(timezone('UTC'))68 where_time = now_utc.astimezone(timezone('Pacific/Niue'))69 now_gmt_n11 = (where_time.strftime(format))7071 return f"现在是{city}时间" + now_gmt_n117273 elif city in ["螳螂高原" , "恐惧废土" , "北风苔原" , "索拉查盆地" , "冬拥湖" , "冰冠冰川" , "冰封王座" , "雷神岛" , "大漩涡" , "科赞" , "破碎群岛"]:74 now_utc = datetime.now(timezone('UTC'))75 where_time = now_utc.astimezone(timezone('Asia/Tokyo'))76 now_gmt_9 = (where_time.strftime(format))7778 return f"现在是{city}时间" + now_gmt_97980 elif city in ["秘蓝岛" , "秘血岛" , "埃索达"]:81 now_utc = datetime.now(timezone('UTC'))82 where_time = now_utc.astimezone(timezone('Europe/London'))83 now_gmt_0 = (where_time.strftime(format))8485 return f"现在是{city}时间" + now_gmt_08687 elif city in ["达纳苏斯" , "泰达希尔" , "月光林地" , "黑海岸" , "灰谷" , "费伍德森林" , "石爪山脉" , "凄凉之地" ,"菲拉斯" , "希利苏斯"]:88 now_utc = datetime.now(timezone('UTC'))89 where_time = now_utc.astimezone(timezone('Europe/Berlin'))90 now_gmt_1 = (where_time.strftime(format))9192 return f"现在是{city}时间" + now_gmt_19394 elif city in ["莫高雷" , "安戈洛" , "千针石林" , "莫高雷" , "贫瘠之地" , "海加尔山" , "冬泉谷" , "雷霆崖"]:95 now_utc = datetime.now(timezone('UTC'))96 where_time = now_utc.astimezone(timezone('Europe/Warsaw'))97 now_gmt_2 = (where_time.strftime(format))9899 return f"现在是{city}时间" + now_gmt_2100101 elif city in ["艾萨拉" , "尘泥沼泽" , "塔纳利斯" , "杜隆塔尔" , "奥格瑞玛" , "回音群岛" , "加基森" , "时光之穴"]:102 now_utc = datetime.now(timezone('UTC'))103 where_time = now_utc.astimezone(timezone('Europe/Moscow'))104 now_gmt_3 = (where_time.strftime(format))105106 return f"现在是{city}时间" + now_gmt_3107108 elif city in ["暴风城" , "诺莫瑞根" , "铁炉堡" , "闪金镇" , "藏宝湾" , "西部荒野" , "艾尔文森林" , "暮色森林","提瑞斯法领地", "银松森林", "艾尔文森林"]:109 now_utc = datetime.now(timezone('UTC'))110 where_time = now_utc.astimezone(timezone('America/Vancouver'))111 now_gmt_n8 = (where_time.strftime(format))112113 return f"现在是{city}时间" + now_gmt_n8114115 elif city in ["幽暗城" , "南海镇" , "通灵学院" , "西瘟疫之地", "奥特兰克山脉" , "希尔斯布莱德丘陵" , "阿拉斯高地" , "丹莫罗" , "炽热峡谷" , "燃烧平原" , "荆棘谷" , "逆风小径"]:116 now_utc = datetime.now(timezone('UTC'))117 where_time = now_utc.astimezone(timezone('America/Edmonton'))118 now_gmt_n7 = (where_time.strftime(format))119120 return f"现在是{city}时间" + now_gmt_n7121122 elif city in ["银月城" , "斯坦索姆" , "奎尔丹纳斯岛" , "永歌森林" , "幽魂之地" ,"东瘟疫之地" , "辛特兰" , "湿地" , "洛克莫丹" , "荒芜之地" , "赤脊山" , "悲伤沼泽" , "诅咒之地"]:123 now_utc = datetime.now(timezone('UTC'))124 where_time = now_utc.astimezone(timezone('America/Winnipeg'))125 now_gmt_n6 = (where_time.strftime(format))126127 return f"现在是{city}时间" + now_gmt_n6 ...

Full Screen

Full Screen

scheduler.py

Source:scheduler.py Github

copy

Full Screen

1import pendulum2from datetime import datetime, timedelta3class Scheduler:4 class StartDate:5 @staticmethod6 def yesterday():7 now_utc = pendulum.now("utc")8 return now_utc.subtract(days=1, hours=now_utc.hour, minutes=now_utc.minute, seconds=now_utc.second,9 microseconds=now_utc.microsecond)10 @staticmethod11 def yesterday_usa_central_timezone():12 yesterday = pendulum.now("America/Chicago")13 return yesterday.subtract(days=1, hours=yesterday.hour, minutes=yesterday.minute, seconds=yesterday.second,14 microseconds=yesterday.microsecond)15 @staticmethod16 def one_hour_ago():17 now_utc = pendulum.now("utc")18 return now_utc.subtract(hours=1, minutes=now_utc.minute, seconds=now_utc.second,19 microseconds=now_utc.microsecond)20 class RetryDelay:21 @staticmethod22 def five_minutes():...

Full Screen

Full Screen

DU-Time.py

Source:DU-Time.py Github

copy

Full Screen

1from datetime import datetime2from pytz import timezone , all_timezones3now_date = datetime(2001,2,3,4,5,6,7)4now_date = datetime.now()5now_utc=now_date.replace(tzinfo=timezone('UTC'))6print('Date:',str(now_date.strftime("%Y-%m-%d %H:%M:%S (%Z) (%z)")))7print('Date:',str(now_utc.strftime("%Y-%m-%d %H:%M:%S (%Z) (%z)")))8print('Year:',str(now_utc.strftime("%Y")))9print('MonthName:',str(now_utc.strftime("%B")))10print('Month:',str(now_utc.strftime("%m")))11print('Day:',str(now_utc.strftime("%d")))12print('Hour:',str(now_utc.strftime("%H")))13print('Minute:',str(now_utc.strftime("%M")))14print('Second:',str(now_utc.strftime("%S")))15print('milliSecond:',str(now_utc.strftime("%f")))16print('weekday:',str(now_utc.strftime("%w")))17print('week of year:',str(now_utc.strftime("%YW%WD%w")))18print('Day of year:',str(now_utc.strftime("%Y/%j")))19print('Zones:',len(all_timezones))20#for zone in all_timezones:...

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 localstack 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