Compare commits

..

No commits in common. "search-operators" and "main" have entirely different histories.

2 changed files with 19 additions and 37 deletions

View File

@ -70,24 +70,13 @@ def search_by_pssh_or_kid(search_filter):
try: try:
with mysql.connector.connect(**get_db_config()) as conn: with mysql.connector.connect(**get_db_config()) as conn:
cursor = conn.cursor() cursor = conn.cursor()
if search_filter.lower().startswith("kid:"): like_filter = f"%{search_filter}%"
value = search_filter[4:]
cursor.execute('SELECT PSSH, KID, `Key` FROM licenses WHERE KID = %s', (value,))
results.update(cursor.fetchall())
elif search_filter.lower().startswith("pssh:"):
value = search_filter[5:]
cursor.execute('SELECT PSSH, KID, `Key` FROM licenses WHERE PSSH LIKE %s', (f"%{value}%",)) cursor.execute('SELECT PSSH, KID, `Key` FROM licenses WHERE PSSH LIKE %s', (like_filter,))
results.update(cursor.fetchall()) results.update(cursor.fetchall())
else:
like_filter = f"%{search_filter}%"
cursor.execute('SELECT PSSH, KID, `Key` FROM licenses WHERE PSSH LIKE %s', (like_filter,)) cursor.execute('SELECT PSSH, KID, `Key` FROM licenses WHERE KID LIKE %s', (like_filter,))
results.update(cursor.fetchall()) results.update(cursor.fetchall())
cursor.execute('SELECT PSSH, KID, `Key` FROM licenses WHERE KID LIKE %s', (like_filter,))
results.update(cursor.fetchall())
final_results = [{'PSSH': row[0], 'KID': row[1], 'Key': row[2]} for row in results] final_results = [{'PSSH': row[0], 'KID': row[1], 'Key': row[2]} for row in results]
return final_results[:20] return final_results[:20]

View File

@ -43,28 +43,21 @@ def search_by_pssh_or_kid(search_filter):
# Initialize a set to store unique matching records # Initialize a set to store unique matching records
results = set() results = set()
if search_filter.lower().startswith("kid:"): # Search for records where PSSH contains the search_filter
value = search_filter[4:] cursor.execute('''
SELECT * FROM licenses WHERE PSSH LIKE ?
''', ('%' + search_filter + '%',))
rows = cursor.fetchall()
for row in rows:
results.add((row[1], row[2], row[3])) # (PSSH, KID, Key)
# Search for records where KID matches the operator value # Search for records where KID contains the search_filter
cursor.execute('SELECT PSSH, KID, `Key` FROM licenses WHERE KID = ?', (value,)) cursor.execute('''
results.update(cursor.fetchall()) SELECT * FROM licenses WHERE KID LIKE ?
elif search_filter.lower().startswith("pssh:"): ''', ('%' + search_filter + '%',))
value = search_filter[5:] rows = cursor.fetchall()
for row in rows:
# Search for records where PSSH contains the operator results.add((row[1], row[2], row[3])) # (PSSH, KID, Key)
cursor.execute('SELECT PSSH, KID, `Key` FROM licenses WHERE PSSH LIKE ?', (f"%{value}%",))
results.update(cursor.fetchall())
else:
like_filter = f"%{search_filter}%"
# Search for records where PSSH contains the search_filter
cursor.execute('SELECT PSSH, KID, `Key` FROM licenses WHERE PSSH LIKE ?', (like_filter,))
results.update(cursor.fetchall())
# Search for records where KID contains the search_filter
cursor.execute('SELECT PSSH, KID, `Key` FROM licenses WHERE KID LIKE ?', (like_filter,))
results.update(cursor.fetchall())
# Convert the set of results to a list of dictionaries for output # Convert the set of results to a list of dictionaries for output
final_results = [{'PSSH': result[0], 'KID': result[1], 'Key': result[2]} for result in results] final_results = [{'PSSH': result[0], 'KID': result[1], 'Key': result[2]} for result in results]