feat: filtering by software

Closes #51
pull/54/head
db0 2023-10-15 14:12:25 +02:00
parent ba8656eb9f
commit b899f46386
4 changed files with 14 additions and 1 deletions

View File

@ -1,5 +1,9 @@
# Changelog
# 0.20.1
* Allow filtering by software
# 0.20.0
* Added batching for adding/removing/modifying censures

View File

@ -12,6 +12,7 @@ class Whitelist(Resource):
get_parser.add_argument("endorsements", required=False, default=0, type=int, help="Limit to this amount of endorsements of more", location="args")
get_parser.add_argument("guarantors", required=False, default=1, type=int, help="Limit to this amount of guarantors of more", location="args")
get_parser.add_argument("tags_csv", required=False, type=str, help="A list of tags to filter.", location="args")
get_parser.add_argument("software_csv", required=False, type=str, help="show only instances running one of this software", location="args")
get_parser.add_argument("page", required=False, type=int, default=1, help="Which page of results to retrieve", location="args")
get_parser.add_argument("limit", required=False, type=int, default=100, help="Which page of results to retrieve", location="args")
get_parser.add_argument("csv", required=False, type=bool, help="Set to true to return just the domains as a csv. Mutually exclusive with domains", location="args")
@ -31,11 +32,15 @@ class Whitelist(Resource):
tags = None
if self.args.tags_csv is not None:
tags = [t.strip() for t in self.args.tags_csv.split(',')]
software = None
if self.args.software_csv is not None:
software = [s.strip() for s in self.args.software_csv.split(',')]
instance_details = []
for instance in database.get_all_instances(
min_endorsements=self.args.endorsements,
min_guarantors=self.args.guarantors,
tags=tags,
software=software,
page=self.args.page,
limit=self.args.limit,
):

View File

@ -13,6 +13,7 @@ def get_all_instances(
min_endorsements = 0,
min_guarantors = 1,
tags = None,
software = None,
include_decommissioned = True,
page=1,
limit=10,
@ -41,6 +42,9 @@ def get_all_instances(
# Convert tags to lowercase and filter instances that have any of the tags
lower_tags = [tag.lower() for tag in tags]
query = query.filter(Instance.tags.any(func.lower(InstanceTag.tag).in_(lower_tags)))
if software:
lower_sw = [sw.lower() for sw in software]
query = query.filter(Instance.software.in_(lower_sw))
page -= 1
if page < 0:
page = 0

View File

@ -235,7 +235,7 @@ class InstanceInfo():
if "*" in self.domain:
self.software = "wildcard"
else:
self.software = self.node_info["software"]["name"]
self.software = self.node_info["software"]["name"].lower()
software_map = {
"lemmy": self.get_lemmy_info,
"mastodon": self.get_mastodon_info,