lint: reformat python code with black
This commit is contained in:
parent
331beb01b4
commit
a406a7974b
88 changed files with 2579 additions and 1608 deletions
|
@ -20,12 +20,12 @@ def generate_subqueries():
|
|||
deprecations_24hr_subquery = (
|
||||
db.session.query(
|
||||
DeprecationAlias.resource_id,
|
||||
func.count(DeprecationAlias.resource_id).label('deprecations_24hr')
|
||||
func.count(DeprecationAlias.resource_id).label("deprecations_24hr"),
|
||||
)
|
||||
.filter(
|
||||
DeprecationAlias.reason.like('block_%'),
|
||||
DeprecationAlias.reason.like("block_%"),
|
||||
DeprecationAlias.deprecated_at >= now - timedelta(hours=24),
|
||||
DeprecationAlias.resource_type == 'Proxy'
|
||||
DeprecationAlias.resource_type == "Proxy",
|
||||
)
|
||||
.group_by(DeprecationAlias.resource_id)
|
||||
.subquery()
|
||||
|
@ -33,12 +33,12 @@ def generate_subqueries():
|
|||
deprecations_72hr_subquery = (
|
||||
db.session.query(
|
||||
DeprecationAlias.resource_id,
|
||||
func.count(DeprecationAlias.resource_id).label('deprecations_72hr')
|
||||
func.count(DeprecationAlias.resource_id).label("deprecations_72hr"),
|
||||
)
|
||||
.filter(
|
||||
DeprecationAlias.reason.like('block_%'),
|
||||
DeprecationAlias.reason.like("block_%"),
|
||||
DeprecationAlias.deprecated_at >= now - timedelta(hours=72),
|
||||
DeprecationAlias.resource_type == 'Proxy'
|
||||
DeprecationAlias.resource_type == "Proxy",
|
||||
)
|
||||
.group_by(DeprecationAlias.resource_id)
|
||||
.subquery()
|
||||
|
@ -52,13 +52,23 @@ def countries_report():
|
|||
return (
|
||||
db.session.query(
|
||||
Country,
|
||||
func.coalesce(func.sum(deprecations_24hr_subquery.c.deprecations_24hr), 0).label('total_deprecations_24hr'),
|
||||
func.coalesce(func.sum(deprecations_72hr_subquery.c.deprecations_72hr), 0).label('total_deprecations_72hr')
|
||||
func.coalesce(
|
||||
func.sum(deprecations_24hr_subquery.c.deprecations_24hr), 0
|
||||
).label("total_deprecations_24hr"),
|
||||
func.coalesce(
|
||||
func.sum(deprecations_72hr_subquery.c.deprecations_72hr), 0
|
||||
).label("total_deprecations_72hr"),
|
||||
)
|
||||
.join(Origin, Country.origins)
|
||||
.join(Proxy, Origin.proxies)
|
||||
.outerjoin(deprecations_24hr_subquery, Proxy.id == deprecations_24hr_subquery.c.resource_id)
|
||||
.outerjoin(deprecations_72hr_subquery, Proxy.id == deprecations_72hr_subquery.c.resource_id)
|
||||
.outerjoin(
|
||||
deprecations_24hr_subquery,
|
||||
Proxy.id == deprecations_24hr_subquery.c.resource_id,
|
||||
)
|
||||
.outerjoin(
|
||||
deprecations_72hr_subquery,
|
||||
Proxy.id == deprecations_72hr_subquery.c.resource_id,
|
||||
)
|
||||
.group_by(Country.id)
|
||||
.all()
|
||||
)
|
||||
|
@ -70,12 +80,22 @@ def origins_report():
|
|||
return (
|
||||
db.session.query(
|
||||
Origin,
|
||||
func.coalesce(func.sum(deprecations_24hr_subquery.c.deprecations_24hr), 0).label('total_deprecations_24hr'),
|
||||
func.coalesce(func.sum(deprecations_72hr_subquery.c.deprecations_72hr), 0).label('total_deprecations_72hr')
|
||||
func.coalesce(
|
||||
func.sum(deprecations_24hr_subquery.c.deprecations_24hr), 0
|
||||
).label("total_deprecations_24hr"),
|
||||
func.coalesce(
|
||||
func.sum(deprecations_72hr_subquery.c.deprecations_72hr), 0
|
||||
).label("total_deprecations_72hr"),
|
||||
)
|
||||
.outerjoin(Proxy, Origin.proxies)
|
||||
.outerjoin(deprecations_24hr_subquery, Proxy.id == deprecations_24hr_subquery.c.resource_id)
|
||||
.outerjoin(deprecations_72hr_subquery, Proxy.id == deprecations_72hr_subquery.c.resource_id)
|
||||
.outerjoin(
|
||||
deprecations_24hr_subquery,
|
||||
Proxy.id == deprecations_24hr_subquery.c.resource_id,
|
||||
)
|
||||
.outerjoin(
|
||||
deprecations_72hr_subquery,
|
||||
Proxy.id == deprecations_72hr_subquery.c.resource_id,
|
||||
)
|
||||
.filter(Origin.destroyed.is_(None))
|
||||
.group_by(Origin.id)
|
||||
.order_by(desc("total_deprecations_24hr"))
|
||||
|
@ -83,26 +103,37 @@ def origins_report():
|
|||
)
|
||||
|
||||
|
||||
@report.app_template_filter('country_name')
|
||||
@report.app_template_filter("country_name")
|
||||
def country_description_filter(country_code):
|
||||
country = Country.query.filter_by(country_code=country_code).first()
|
||||
return country.description if country else None
|
||||
|
||||
|
||||
@report.route("/blocks", methods=['GET'])
|
||||
@report.route("/blocks", methods=["GET"])
|
||||
def report_blocks() -> ResponseReturnValue:
|
||||
blocked_today = db.session.query( # type: ignore[no-untyped-call]
|
||||
Origin.domain_name,
|
||||
Origin.description,
|
||||
Proxy.added,
|
||||
Proxy.deprecated,
|
||||
Proxy.deprecation_reason
|
||||
).join(Origin, Origin.id == Proxy.origin_id
|
||||
).filter(and_(Proxy.deprecated > datetime.now(tz=timezone.utc) - timedelta(days=1),
|
||||
Proxy.deprecation_reason.like('block_%'))).all()
|
||||
blocked_today = (
|
||||
db.session.query( # type: ignore[no-untyped-call]
|
||||
Origin.domain_name,
|
||||
Origin.description,
|
||||
Proxy.added,
|
||||
Proxy.deprecated,
|
||||
Proxy.deprecation_reason,
|
||||
)
|
||||
.join(Origin, Origin.id == Proxy.origin_id)
|
||||
.filter(
|
||||
and_(
|
||||
Proxy.deprecated > datetime.now(tz=timezone.utc) - timedelta(days=1),
|
||||
Proxy.deprecation_reason.like("block_%"),
|
||||
)
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
||||
return render_template("report_blocks.html.j2",
|
||||
blocked_today=blocked_today,
|
||||
origins=sorted(origins_report(), key=lambda o: o[1], reverse=True),
|
||||
countries=sorted(countries_report(), key=lambda c: c[0].risk_level, reverse=True),
|
||||
)
|
||||
return render_template(
|
||||
"report_blocks.html.j2",
|
||||
blocked_today=blocked_today,
|
||||
origins=sorted(origins_report(), key=lambda o: o[1], reverse=True),
|
||||
countries=sorted(
|
||||
countries_report(), key=lambda c: c[0].risk_level, reverse=True
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue