Best Python code snippet using Kiwi_python
boj_17090.py
Source:boj_17090.py
1# ë§¤ì° ì¤ë ìê°ì´ ê±¸ë ¸ë¤.2# ì²ìë¶í° ì ëë¡ ì¤ê³ë¥¼ íì§ ìì¼ë©´ ë§¤ì° íë¤ì´ì§ ì ìë¤ë ê²ì ì´ ë¬¸ì 를 íµí´ì ìê² ëìë¤.3# íì 문ì ë¶ìê³¼ ì¤ê³ë¥¼ ì² ì í íìê³ ìê°íì§ë§ ì ì§í¤ì§ 못íëë°, ì´ë² 문ì 를 íµí´ì ê·¸ ì ì ë°ì±íê² ëìë¤...4# íì´ë 335ë² ì¤ ì´íë¶í°í°5# N x M ì¬ì´ì¦ì 미ë¡ìì U, D, L, Rì ëª
ë ¹ì ë°ë¼ ì´ëíì ë 미ë¡ì ê²½ê³ ë°ì¼ë¡ íì¶ì´ ê°ë¥íê² íë 칸ì ëªê°ì¼ê¹?6# íì¶ ê°ë¥í "칸"ì´ë¼ë ë° ì£¼ëª©í´ì¼ê² ë¤. BFSì²ë¼ íì ë°©í¥ì ë£ì´ê°ë ìì ì´ëì´ ìëë¼ ê·¸ 칸ì ëª
ë ¹ì ê·¸ëë¡ ë°ë¼ë§ ê°ì¼ íë¤.7# ê²°êµ ëª¨ë 칸ì ëí´ì íìì í´ì¼ í íìê° ì긴ë¤. ìê° ì´ê³¼ ìë ê¹? DFSë¡ êµ¬ì±íë¤ë©´ ìµë ì¬ê· ê¹ì´ë¥¼ ê°ë³ê² ëì´ë²ë¦´ ê² ê°ë¤.8# Nê³¼ M ì ë¶ ìµë ë°ì´í°ì¸ 500ì´ë¼ê³ ê°ì íì ë, ìµë 25,000칸ì ëí íìì í´ì¼ íë¤. ìê° ì íì 1ì´ë¤..9# ì°ì 기본ì ì¸ DFS를 ë§ë¤ì´ë³´ì. ì´ ë°©ìì ë¶ëª
ìê° ì´ê³¼ê° ë ê²ì´ë¤.10# ì¤ì ë¡ ìê° ì´ê³¼ê° ë¬ë¤.11# 1ì°¨ ìë12# import sys13# sys.setrecursionlimit(200000)14# dx = [-1, 1, 0, 0] # UDLR15# dy = [0, 0, -1, 1]16#17# def DFS(x, y):18# global cnt19# # print(cnt)20# visited[x][y] = 121# move_number = move_set.index(arr[x][y])22# tx, ty = x + dx[move_number], y + dy[move_number]23#24# if 0 > tx or tx >= N or 0 > ty or ty >= M: # 기본 ëª
ë ¹ : 0 <= tx < N and 0 <= ty < M25# cnt += 126# elif 0 <= tx < N and 0 <= ty < M and not visited[tx][ty]:27# DFS(tx, ty)28#29# N, M = map(int, sys.stdin.readline().split())30# arr = [list(sys.stdin.readline().rstrip()) for _ in range(N)]31#32# cnt = 033# move_set = ['U', 'D', 'L', 'R']34#35# for i in range(N):36# for j in range(M):37# visited = [[0] * M for _ in range(N)]38# DFS(i, j)39#40# print(cnt)41# ìê°í´ë³´ë, ìê°ì ì¤ì¼ë²í ìê°ì´ ë¤ìë¤.42# ì를 ë¤ì´, í ì¢íìì ëª
ë ¹ì ë°ë¼ ì´ëí´ ë¯¸ë¡ë¥¼ íì¶íë¤.43# ì¶íì 방문íë ë¤ë¥¸ ì¢íìì, ìì íì¶í ê²½ë¡ì ì§ì ì 방문íë¤ë©´, ê·¸ ì ìì íì¶ì´ ê°ë¥í ì ì´ ëì§ ììê¹?44# ì´ì°¨í¼ ê°ì ê²½ë¡ë¥¼ ë°ë¼ì ê° ê²ì´ê¸° ë문ì´ë¤.45# ëë íìì ììì ì´ íì¶ ê²½ë¡ ì¤ í ì ì¸ ê²½ì°, ë³¼ ê²ë ìì´ íì¶ì´ ê°ë¥í ì¢íì´ë¤.46# ì´ ë°©ë²ì ê´ê±´ì íì¶ì´ ê°ë¥í ì¢í를 ì¼ë§ë 빨리 ë§ëëëì´ë¤.47# ë§ì½ ë§¤ì° í° ì¬ì´ì¦ì 미ë¡ìì íì¶ ì§ì ì´ ê°ì¥ ë§ì§ë§ ì¢íë¼ë©´, ê²°êµ ì ë¶ ë¤ ìííê² ëëê±´ë° ê·¸ë¬ë©´ ëê°ì´ ìê°ì´ê³¼ê° ëë¤.48# ì°ì (0, 0)ë¶í° ì íìíë©´ì 방문íì를 ìë¡ê² íê³ , íì¶í ì§ì ì´ ëì¤ë©´ í´ë¹ 방문 ì¢í를 ë³ëì 리ì¤í¸ì ë´ëë¤.49# ë§ì½ íì¶íì§ ìì ê²½ì° ë°©ë¬¸íì를 ìí 리ì¤í¸ë¥¼ ì´ê¸°ííë¤.50# 2ì°¨ ìë51# 90% ìê°ì´ê³¼ ã
ã
ã
ã
ã
ã
52# í¹ì ììì ìê°íë 문ì (íì¶ì´ ê°ë¥í ì¢íê° ë°°ì´ì ìµíë°ë¶ìë§ ì¡´ì¬íë ê²½ì°)ê° ìì¸ì´ìë ì¶ì´ì (0, 0)ì´ ìë ê±°ê¾¸ë¡ íìíë ë°©ë²ì53# ìëíì§ë§.. ì¬ì í 90%ìì ì´ê³¼ê° ë¬ë¤. ëê° ë¤ë¥¸ ë°©ë²ì´ íìíë¤. BFSë¡ë ì´ë¨ê¹?54# import sys55# sys.setrecursionlimit(100000)56#57# dx = [-1, 1, 0, 0] # UDLR58# dy = [0, 0, -1, 1]59#60# def DFS(x, y):61# global cnt62# if (x, y) in escape_list:63# cnt += 164# return65#66# visited.add((x, y))67# move_number = move_set.index(arr[x][y])68# tx, ty = x + dx[move_number], y + dy[move_number]69#70# if 0 > tx or tx >= N or 0 > ty or ty >= M: # 기본 ëª
ë ¹ : 0 <= tx < N and 0 <= ty < M71# cnt += 172# elif 0 <= tx < N and 0 <= ty < M and (tx, ty) not in visited:73# DFS(tx, ty)74#75# N, M = map(int, sys.stdin.readline().split())76# arr = [list(sys.stdin.readline().rstrip()) for _ in range(N)]77# escape_list = set()78# cnt = 079# move_set = ['U', 'D', 'L', 'R']80#81# for i in range(N):82# for j in range(M):83# visited = set()84# temp = cnt85# DFS(i, j)86# if temp != cnt:87# escape_list = escape_list | visited88#89# print(cnt)90# 3ì°¨ ìë91# BFSë¡ ë°ê¾¸ì´ë³´ìì§ë§ ìì ê°ì ì§ì ìì ì¤í¨92# import sys93# from collections import deque94#95# dx = [-1, 1, 0, 0] # UDLR96# dy = [0, 0, -1, 1]97#98# def BFS(x, y):99# global cnt100# Q = deque()101# Q.append([x, y])102# visited.add((x, y))103#104# while Q:105# new_x, new_y = Q.popleft()106# move_number = move_set.index(arr[new_x][new_y])107# tx, ty = new_x + dx[move_number], new_y + dy[move_number]108#109# if 0 > tx or tx >= N or 0 > ty or ty >= M: # 기본 ëª
ë ¹ : 0 <= tx < N and 0 <= ty < M110# cnt += 1111# elif 0 <= tx < N and 0 <= ty < M and (tx, ty) not in visited:112# visited.add((tx, ty))113# Q.append(tx, ty)114#115# N, M = map(int, sys.stdin.readline().split())116# arr = [list(sys.stdin.readline().rstrip()) for _ in range(N)]117# escape_list = set()118# cnt = 0119# move_set = ['U', 'D', 'L', 'R']120#121# for i in range(N):122# for j in range(M):123# visited = set()124# temp = cnt125# BFS(i, j)126# if temp != cnt:127# escape_list = escape_list | visited128#129# print(cnt)130# 4ì°¨ ìë131# ì¤í¨íë ì§ì ì ì¢íë ì ì¥í´ëë©´ ì´ë¨ê¹...?132# import sys133# sys.setrecursionlimit(100000)134#135# dx = [-1, 1, 0, 0] # UDLR136# dy = [0, 0, -1, 1]137#138# def DFS(x, y):139# global cnt140# if (x, y) in escape_list:141# cnt += 1142# return143#144# if (x, y) not in escape_list and (x, y) in fail_list:145# return146#147# visited.add((x, y))148# move_number = move_set.index(arr[x][y])149# tx, ty = x + dx[move_number], y + dy[move_number]150#151# if 0 > tx or tx >= N or 0 > ty or ty >= M: # 기본 ëª
ë ¹ : 0 <= tx < N and 0 <= ty < M152# cnt += 1153# elif 0 <= tx < N and 0 <= ty < M and (tx, ty) not in visited:154# DFS(tx, ty)155#156# N, M = map(int, sys.stdin.readline().split())157# arr = [list(sys.stdin.readline().rstrip()) for _ in range(N)]158# escape_list = set()159# fail_list = set()160# cnt = 0161# move_set = ['U', 'D', 'L', 'R']162#163# for i in range(N):164# for j in range(M):165# visited = set()166# temp = cnt167# DFS(i, j)168# if temp != cnt:169# escape_list = escape_list | visited170# else:171# fail_list = fail_list | visited172#173# print(cnt)174#175#176#177# import sys178# from collections import deque179#180# dx = [-1, 1, 0, 0] # UDLR181# dy = [0, 0, -1, 1]182#183#184# def BFS(x, y):185# global cnt186# Q = deque()187# Q.append([x, y])188# escape_list = set()189# escape_list.add((x, y))190# visited[x][y] = 1191#192# while Q:193# new_x, new_y = Q.popleft()194# if check[x][y]:195# for a, b in escape_list:196# check[a][b] = 1197# cnt += 1198# return199#200# move_number = move_set.index(arr[new_x][new_y])201# tx, ty = new_x + dx[move_number], new_y + dy[move_number]202#203#204# # if 0 > tx or tx >= N or 0 > ty or ty >= M:205# if (not (0 <= tx < N)) or (not (0 <= ty < M)):206# for a, b in escape_list:207# check[a][b] = 1208# cnt += 1209# elif check[tx][ty] == -1:210# for a, b in escape_list:211# check[a][b] = -1212# return213# elif not visited[tx][ty]:214# visited[tx][ty] = 1215# escape_list.add((tx, ty))216# Q.append((tx, ty))217#218# for a, b in escape_list:219# check[a][b] = -1220# return221#222# N, M = map(int, sys.stdin.readline().split())223# arr = [list(sys.stdin.readline().rstrip()) for _ in range(N)]224# visited = [[0] * M for _ in range(N)]225# check = [[0] * M for _ in range(N)]226# cnt = 0227# move_set = ['U', 'D', 'L', 'R']228#229# for i in range(N):230# for j in range(M):231# if check[i][j] == -1:232# continue233# elif check[i][j]:234# cnt += 1235# continue236#237# BFS(i, j)238#239# print(cnt)240#241# #242# import collections243# import sys244# from collections import deque245# def bfs(y, x):246# global cnt247# q = deque([(y, x)])248#249# # dpì íì¶í ì ìë ì¬ë¶ë¥¼ íìí기 ìí course250# course = set()251# course.add((y, x))252# # 방문 ì²´í¬253# # visited = [[0] * m for _ in range(n)]254# visited[y][x] = 1255# while q:256# y, x = q.popleft()257# # íì¶í ì ìë ê³³ì´ë©´ ì¬íê¹ì§ 방문íë ê³³ì dpì íì258# if dp[y][x]:259# for value in course:260# dp[value[0]][value[1]] = 1261# cnt += 1262# return263# # ì¡°ê±´ì ë°ë¼ ìì§ì264# if area[y][x] == 'U':265# y -= 1266# elif area[y][x] == 'R':267# x += 1268# elif area[y][x] == 'D':269# y += 1270# else:271# x -= 1272#273# # íì¶ íë¤ë©´ 방문í ê³³ì dpì íì274# if (not (0 <= y < n)) or (not (0 <= x < m)):275# for value in course:276# dp[value[0]][value[1]] = 1277# cnt += 1278# # íì¶ ë¶ê°ë¥ íë¤ë©´ 방문í ê³³ì dpì íì279# elif (dp[y][x] == -1):280# for value in course:281# dp[value[0]][value[1]] = -1282# return283# # ìëë©´ ë¤ì ê³¼ì 284# elif not visited[y][x]:285# visited[y][x] = 1286# course.add((y, x))287# q.append((y, x))288# # ì¬ê¸°ê¹ì§ ìì¼ë©´ íì¶ ë¶ê°ë¥íë¯ë¡ dpì íì289# for value in course:290# dp[value[0]][value[1]] = -1291# return292#293#294# n, m = map(int, sys.stdin.readline().split())295# area = [sys.stdin.readline() for _ in range(n)]296# dp = [[0] * m for _ in range(n)]297# visited = [[0] * m for _ in range(n)]298# cnt = 0299# for i in range(n):300# for j in range(m):301# # íì¶í ì ìë ê³³ì¸ì§?302# if (dp[i][j] == -1):303# continue304# # íì¶í ì ìë ê³³ì¸ì§?305# elif dp[i][j]:306# cnt += 1307# continue308#309# # ë ë¤ ìëë©´310# bfs(i, j)311# print(cnt)312import sys313from collections import deque314dx = [-1, 1, 0, 0] # UDLR315dy = [0, 0, -1, 1]316def find(x, y):317 global cnt318 # ë§ì½ í´ë¹ ì¢íê° ì´ì ì¢í를 íìíë ê³¼ì ìì íì¶ì´ ê°ë¥í ê²½ë¡ë¡ ì´ë¯¸ ì¶ê°ëìë¤ë©´, ë°ë¡ ì¢
ë£ìì¼ ë¶íìí ì°ì°ì ì¤ì¸ë¤.319 if (x, y) in success: return320 Q = deque()321 Q.append([x, y])322 # visit = [[0] * m for _ in range(n)]323 # visit[x][y] = 1324 move_number = move_set.index(area[x][y]) # 구ì 칸ì ìì¹í ëª
ë ¹(ë°©í¥)ì ì¸ì325 tx, ty = x + dx[move_number], y + dy[move_number] # ë°©í¥ì ë§ê² ìì¹ë¥¼ ì¡°ì 326 if not (0 <= tx < n) or not (0 <= ty < m): # 미ë¡ë¥¼ íì¶íìê¹?327 success.add((x, y)) # íì¶íë¤ë©´ í´ë¹ ì¢í를 íì¶ ë¦¬ì¤í¸ì ì¶ê°íê³ 328 cnt += 1 # íì¶ ê°ë¥í 칸ì ì를 ì¶ê°í´ì£¼ì329 # í´ë¹ 구ì ì¢íë¡ íì¶ì´ ê°ë¥í ê²ì íì¸íë¤.330 # ì´ì ì¸ì í ë°©í¥ì ì¢íë¤ì íì¸í´ëê° ì°¨ë¡ì´ë¤! ë§ì½ ì¸ì í ì¢íì ëª
ë ¹ì´ íì¶ì´ ê°ë¥í 구ì ì¢íì´ê±°ë,331 # í´ë¹ 구ì ì¢í를 í¥í´ ê° ì ìë ê³³ì´ë¼ë©´ 구ìì´ ìë ê·¸ ì¢íë ìì íì¶í ì ìë ì¢íê° ëë¤.332 # (ì¢í를 ë°ë¼ ê°ë©´ íì¶ì´ ê°ë¥í 구ì ì¢í를 ë§ë ê²ì´ê³ , ê·¸ë¬ë©´ íì¶ì´ ê°ë¥í기 ë문ì)333 while Q:334 Q_x, Q_y = Q.popleft()335 for k in range(4):336 new_tx, new_ty = Q_x + dx[k], Q_y + dy[k] # ìëì ì¢íì ì¸ì í ë¤ ë°©í¥ì ì¢í를 ìì°¨ì ì¼ë¡ íìíë¤.337 if 0 <= new_tx < n and 0 <= new_ty < m: # ì¸ì í ë°©í¥ì ì¢íê° ë°°ì´ì ë²ì를 ë²ì´ëì§ ìì ê²½ì°338 target_number = move_set.index(area[new_tx][new_ty])339 target_x, target_y = new_tx + dx[target_number], new_ty + dy[target_number] # ì¸ì í ì¢íì ëª
ë ¹ì ë°ë¼ ì´ëí ìë¡ì´ ì¢í340 # ë§ì½ ìë¡ê² ì´ëí ì¢íê° ê¸°ì¡´ì Q_x, Q_yì ëì¼íë¤ë©´?341 # Q_x, Q_yë¡ë¶í° ì¸ì í ì¢íì¸ new_tx, new_ty ìì íì¶ì´ ê°ë¥í ì¢íë¼ë ê²ì ì미íë¤.342 # ë°ë¼ì Qì new_tx, new_ty를 ì¶ê°í´ ì¶ê°ì ì¸ íì¶ ê²½ë¡ê° ìëì§ íìí´ëê°ë¤.343 if target_x == Q_x and target_y == Q_y:344 success.add((new_tx, new_ty))345 cnt += 1346 # visit[new_tx][new_ty] = 1347 Q.append([new_tx, new_ty])348n, m = map(int, sys.stdin.readline().split())349area = [sys.stdin.readline() for _ in range(n)]350# visit = [[0] * m for _ in range(n)]351corner = [] # 구ì ì¢í를 ë´ê¸° ìí 리ì¤í¸352success = set() # íì¶ì ì±ê³µíê±°ë, íì¶ì´ ê°ë¥í ê²½ë¡ì¸ ê²½ì° í´ë¹ ì¢í를 ë´ê¸° ìí ì§í©353cnt = 0354move_set = ['U', 'D', 'L', 'R'] # ìíì¢ì°ì ììì´ê³ , ì¶í ì¸ì í ë°©í¥ì ì°¾ìëê° ë í´ë¹ ì¢íììì ë°©í¥ê°ì ì¸ë±ì¤ë¡ íì©í기 ìí´ ì¬ì©355# 구ì ì¢íë§ ë°ë¡ 모ì주ë ê³¼ì 356for i in range(n):357 for j in range(m):358 if i == 0 or i == n - 1:359 corner.append([i, j])360 elif j == 0 and area[i][j] not in corner or j == m - 1 and area[i][j] not in corner:361 corner.append([i, j])362# 구ì ì¢íë¤ì ëìì¼ë¡ ê²ì¬363for i, j in corner:364 find(i, j)365# íì¶í ì ìë 칸ì ê°ì를 ì¶ë ¥...
main.py
Source:main.py
1import re2import logging3from asyncio import shield4from typing import NoReturn5import discord6from discord import ChannelType as ct, Option7from discord.utils import escape_markdown8import metallum9from decouple import config10logger = logging.getLogger("discord")11logger.setLevel(logging.DEBUG)12handler = logging.FileHandler(13 filename="discord.log", encoding="utf-8", mode="w"14)15handler.setFormatter(16 logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")17)18logger.addHandler(handler)19BOT_TOKEN = config("BOT_TOKEN")20BASE_URL = "https://metal-archives.com/"21PRE_M = ":heavy_minus_sign:\n\n"22SUF_M = "\n\n:heavy_minus_sign:"23HELP_STANDARD = (24 ":regional_indicator_h: :regional_indicator_a: :regional_indicator_i:"25 " :regional_indicator_l: :bangbang: \t:metal: :robot:\n\nUse the command"26 " `/metallum` to perform a search.\n\nParameters:\n__query:__ the text"27 " used in the search.\n\n__exact:__ whether to search for the exact query"28 " or not (more info below). Must be either **True** or"29 " **False**.\n\n__**STANDARD SEARCH**__:\n\nWhen the __exact__ parameter"30 " is **True**, searching for 'black sabbath' will only find bands named"31 " EXACTLY 'Black Sabbath' (case-insensitive, though).\n\nHowever, when"32 " __exact__ is **False**, the same search will find all bands with BOTH"33 " 'black' and 'sabbath' in their names, regardless of any other words and"34 " in whatever order, like the band 'Sabbath Black Heretic'.\n\nIf the"35 " first part of the __query__ is a number, you may find a band registered"36 " under that __ID__ on the website, if there's any (the ID is the number"37 " at the end of the band's URL). The search will then continue to look for"38 " bands matching the entire query (including that number) in their"39 " names.\n\nFor example: `/metallum query: 7 sins exact: True` would give"40 " you the band with ID '7', which is 'Entombed' and then search for bands"41 " called '7 Sins' (exact match, in this case).\nNote that searching for"42 " '13' will give you both the band with ID '13' and the band called"43 " '13'.\n\n"44)45HELP_ADVANCED = (46 "__**ADVANCED SEARCH**__:\n\nThe options below only work when"47 " __exact__ is set to **False**...\n\nIn addition to those results"48 " describe above, if you also want bands that contain EITHER 'black' OR"49 " 'sabbath' (not necessarily both), you can search for `black || sabbath`"50 " (or `sabbath || black`, for that matter).\n\nNote, however, that those"51 " words must appear in their entirety in the band's name. Meaning a 'hell'"52 " search won't find 'helloween', for instance.\nBut don't worry, you can"53 " use __asterisks__ as wildcards: `hell*`, `*hell` and `*hell*` are all"54 " valid queries. The asterisk means that the word can be extended by any"55 " amount of characters **in that direction**.\n\nFinally, another thing"56 " you can do is exclude words from the results: `black -sabbath` will find"57 " bands with the word 'black', but exclude those with the word"58 " 'sabbath'.\n\nYou can also combine all of the above, of course!"59)60class Band:61 def __init__(self, band: metallum.Band, albums: bool = True):62 escaped_band = self.escape_band(band)63 self.name: str = escaped_band["name"]64 # print(self.name)65 self.genres: str = escaped_band["genres"]66 # print(self.genres)67 self.status: str = escaped_band["status"]68 # print(self.status)69 self.location: str = escaped_band["location"]70 # print(self.location)71 self.country: str = escaped_band["country"]72 # print(self.country)73 self.formed_in: str = escaped_band["formed_in"]74 # print(self.formed_in)75 self.themes: str = escaped_band["themes"]76 if albums:77 full_albums = band.albums.search(type="full-length")78 # print("Full albums: " + str(full_albums))79 self.albums: str = (80 "This band has no full-length albums. Check their page below"81 " for other releases."82 if full_albums == []83 else "\n".join(84 [85 f"**({str(a.year)})** {escape_markdown(a.title)}"86 for a in full_albums87 ]88 )89 )90 # print(self.albums)91 self.url: str = escape_markdown(BASE_URL + band.url)92 # print(self.url)93 self._info: str = "\n\n".join(94 [95 f"__**{self.name}**__",96 f"__*GENRES*__: {self.genres}",97 f"__*LOCATION*__: {self.location}, {self.country}",98 f"__*FORMED IN*__: {self.formed_in}",99 f"__*STATUS*__: {self.status}",100 f"__*THEMES*__: {self.themes}",101 (f"__*ALBUMS*__: \n{self.albums}" if albums else ""),102 f"__*PAGE*__: {self.url}",103 ]104 ).replace("\n\n\n\n", "\n\n")105 def __str__(self):106 return self._info107 def escape_band(self, band: metallum.Band):108 escape_list = list(109 map(110 lambda x: escape_markdown(x),111 [112 band.name,113 ", ".join(band.genres),114 band.status,115 band.location,116 band.country,117 band.formed_in,118 ", ".join(band.themes),119 ],120 )121 )122 escaped_band = {123 "name": escape_list[0],124 "genres": escape_list[1],125 "status": escape_list[2],126 "location": escape_list[3],127 "country": escape_list[4],128 "formed_in": escape_list[5],129 "themes": escape_list[6],130 }131 return escaped_band132class Search:133 def __init__(134 self,135 query: str,136 send_to: discord.ApplicationContext.channel,137 strict: bool = True,138 albums: bool = True,139 page_start: int = 0,140 ):141 self.query = query142 self.send_to = send_to143 self.strict = strict144 self.albums = albums145 self.page_start = page_start146 async def search(self) -> NoReturn:147 await shield(148 self.send_to.send(149 PRE_M150 + (151 "Performing strict search!"152 if self.strict153 else (154 "Performing advanced search:"155 f" {escape_markdown(self.query)}"156 )157 )158 )159 )160 try:161 band_list = metallum.band_search(162 self.query, strict=self.strict, page_start=self.page_start163 )164 if not band_list:165 raise IndexError166 await shield(167 self.send_to.send(168 f"{PRE_M}Found {band_list.result_count} band(s)!\n\nHere"169 " we go!"170 )171 )172 for i, band_result in enumerate(band_list):173 band = Band(band_result.get(), self.albums)174 band_pos = f"{i+1+self.page_start}/{band_list.result_count}"175 print(band)176 bot_response = "\n\n".join(177 [178 str(band),179 band_pos,180 ]181 )182 await shield(self.send_to.send(f"{PRE_M}{bot_response}"))183 if (i + 1) % 200 == 0:184 new_search = Search(185 self.query,186 self.send_to,187 self.strict,188 self.albums,189 self.page_start + 200,190 )191 await shield(new_search.search())192 return193 except IndexError:194 await shield(195 self.send_to.send(196 f"{PRE_M}No band was found. Remember, I only know METAL"197 " bands! \U0001F918\U0001F916"198 )199 )200bot = discord.Bot()201@bot.event202async def on_ready():203 print("Logged on as {0}!".format(bot.user))204@bot.slash_command(205 name="helper",206 description="Learn how to search!",207)208async def helper(ctx: discord.ApplicationContext):209 await shield(ctx.respond(HELP_STANDARD))210 await shield(ctx.respond(HELP_ADVANCED))211@bot.slash_command(212 name="metallum",213 description="Use /helpers for instructions!",214)215async def metallum_search(216 ctx: discord.ApplicationContext,217 query: Option(str, "The search you wanna perform", required=True),218 exact: Option(219 bool,220 description=(221 "Whether the search results should match the exact query."222 " True or False."223 ),224 ),225):226 try:227 print(228 "\n\n"229 + "*" * 10230 + f"\n\nSearch by: {ctx.author}\nQuery: {query}\nExact:"231 f" {exact}\nData: {ctx.interaction.data}\n\n"232 + "*" * 10233 + "\n\n"234 )235 except Exception as e:236 print(f"Debug exception: {e}")237 try:238 send_to = await shield(239 ctx.interaction.channel.create_thread(240 name=f"Metallum search, query='{query}', exact={exact}",241 type=ct.public_thread,242 auto_archive_duration=60,243 )244 )245 await shield(246 ctx.respond(247 "Search initiated, please refer to the thread:"248 f" {send_to.mention}"249 )250 )251 await shield(252 send_to.send(253 f"{ctx.author} used: `/metallum query: '{query}'"254 f" exact: '{exact}'` \n\nStandby for results! \U0001F916"255 )256 )257 except (258 discord.Forbidden,259 discord.HTTPException,260 discord.InvalidArgument,261 ) as e:262 print(f"Exception in thread handling: {e}")263 await shield(ctx.respond("Something went wrong!"))264 send_to = ctx.interaction.channel265 except AttributeError as ae:266 print(f"Thread attribute error: {ae}")267 send_to = ctx.interaction.channel268 await shield(ctx.respond("Search initialized!"))269 args = query.split()270 if re.search(r"^\d+$", args[0]):271 try:272 result = metallum.band_for_id(args[0])273 if result.id != args[0]:274 raise ValueError275 band = Band(result)276 print(band)277 await send_to.send(278 f"{PRE_M}Found a band with ID: '{args[0]}'\n\n{band}"279 )280 except ValueError as v:281 print(f"ValueError in search: {v}")282 except (283 discord.Forbidden,284 discord.HTTPException,285 discord.InvalidArgument,286 ) as e:287 print(f"Exception sending band_for_id result: {e}")288 name_search = Search(query, send_to, exact)289 await shield(name_search.search())290 try:291 await shield(292 ctx.interaction.edit_original_message(293 content=(294 "Search **completed**, please refer to the thread:"295 f" {send_to.mention}"296 )297 )298 )299 except Exception as e:300 print(f"Failed to edit response: {e}")...
eval.py
Source:eval.py
...95 score.append((loss_val, loss_test, acc_val, acc_test))96 # save97 save_to_csv(filename=score_filename, header=[98 'val_loss', 'test_loss', 'val_accuracy', 'test_accuracy', ], list_to_save=score, data_type='float,float,float,float')99def get_escape_list(infl_filename, n_to_remove):100 infl_list = read_csv(infl_filename)101 infl_arr = np.array(infl_list)102 header = infl_list[0]103 idx_ds = header.index('datasource_index')104 escape_list = infl_arr[1:1+n_to_remove, idx_ds].astype(int).tolist()105 return escape_list106def run_train_for_eval(model_info_dict, file_dir_dict, n_to_remove, retrain_all):107 os.environ['NNABLA_CUDNN_DETERMINISTIC'] = '1'108 os.environ['NNABLA_CUDNN_ALGORITHM_BY_HEURISTIC'] = '1'109 # files and dirs110 infl_filename = file_dir_dict['infl_filename']111 # gpu/cpu112 ctx = get_context(model_info_dict['device_id'])113 nn.set_default_context(ctx)114 # train115 escape_list = get_escape_list(infl_filename, n_to_remove)116 retrain(model_info_dict, file_dir_dict,...
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!!