Skip to content

Commit

Permalink
add price min max filters
Browse files Browse the repository at this point in the history
  • Loading branch information
datawhores committed Dec 17, 2023
1 parent fefe083 commit 66c9a4c
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 31 deletions.
70 changes: 70 additions & 0 deletions ofscraper/filters/models/date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
date filters
"""

import logging

import arrow

import ofscraper.utils.args as args_


def dateFilters(filterusername):
log = logging.getLogger("shared")

log.debug(f"Last Seen After Filter: {args_.getargs().last_seen_after}")
if args_.getargs().last_seen_after:
filterusername = list(
filter(
lambda x: x.final_last_seen >= args_.getargs().last_seen_after,
filterusername,
)
)
log.debug(f"last seen after username count: {len(filterusername)}")
log.debug(f"Last Seen Before Filter: {args_.getargs().last_seen_before}")
if args_.getargs().last_seen_before:
filterusername = list(
filter(
lambda x: x.final_last_seen <= args_.getargs().last_seen_before,
filterusername,
)
)
log.debug(f"last seen before username count: {len(filterusername)}")

log.debug(f"Subscribed After Filter: {args_.getargs().subscribed_after}")
if args_.getargs().subscribed_after:
filterusername = list(
filter(
lambda x: arrow.get(x.subscribed) >= args_.getargs().subscribed_after,
filterusername,
)
)
log.debug(f"subscribed after username count: {len(filterusername)}")
log.debug(f"Subscribed Before Filter: {args_.getargs().subscribed_before}")
if args_.getargs().subscribed_before:
filterusername = list(
filter(
lambda x: x.final_last_seen <= args_.getargs().subscribed_before,
filterusername,
)
)
log.debug(f"subscribed before username count: {len(filterusername)}")
log.debug(f"Expired After Filter: {args_.getargs().expired_after}")
if args_.getargs().expired_after:
filterusername = list(
filter(
lambda x: arrow.get(x.expired) >= args_.getargs().expired_after,
filterusername,
)
)
log.debug(f"expired after username count: {len(filterusername)}")
log.debug(f"Expired Before Filter: {args_.getargs().expired_before}")
if args_.getargs().expired_before:
filterusername = list(
filter(
lambda x: arrow.get(x.expired) <= args_.getargs().expired_before,
filterusername,
)
)
log.debug(f"expired before username count: {len(filterusername)}")
return filterusername
20 changes: 1 addition & 19 deletions ofscraper/filters/models/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,6 @@

def otherFilters(filterusername):
log = logging.getLogger("shared")

log.debug(f"Last Seen After Filter: {args_.getargs().last_seen_after}")
if args_.getargs().last_seen_after:
filterusername = list(
filter(
lambda x: x.final_last_seen >= args_.getargs().last_seen_after,
filterusername,
)
)
log.debug(f"last seen after username count: {len(filterusername)}")
log.debug(f"Last Seen Before Filter: {args_.getargs().last_seen_before}")
if args_.getargs().last_seen_before:
filterusername = list(
filter(
lambda x: x.final_last_seen <= args_.getargs().last_seen_before,
filterusername,
)
)
log.debug(f"last seen befpre username count: {len(filterusername)}")
log.debug(f"Excluded usernames: {args_.getargs().excluded_username}")
if len(args_.getargs().excluded_username) > 0:
filterusername = list(
Expand All @@ -36,5 +17,6 @@ def otherFilters(filterusername):
filterusername,
)
)
log.debug(f"excluded username count: {len(filterusername)}")

return filterusername
82 changes: 82 additions & 0 deletions ofscraper/filters/models/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,86 @@ def pricePaidFreeFilterHelper(filterusername):
)
)
log.debug(f"free promo filter username count: {len(filterusername)}")
filterusername = priceMinMaxFilters(filterusername)

return filterusername


def priceMinMaxFilters(filterusername):
log = logging.getLogger("shared")
log.debug(f"Promo Price min Filter: {args_.getargs().promo_price_min}")
if args_.getargs().promo_price_min:
filterusername = list(
filter(
lambda x: x.final_promo_price >= args_.getargs().promo_price_min,
filterusername,
)
)
log.debug(f"currently promo min filter: {len(filterusername)}")
log.debug(f"Promo Price max Filter: {args_.getargs().promo_price_max}")
if args_.getargs().promo_price_max:
filterusername = list(
filter(
lambda x: x.final_promo_price <= args_.getargs().promo_price_max,
filterusername,
)
)
log.debug(f"currently promo max filter: {len(filterusername)}")

log.debug(f"Regular Price min Filter: {args_.getargs().regular_price_min}")
if args_.getargs().regular_price_min:
filterusername = list(
filter(
lambda x: x.final_regular_price >= args_.getargs().regular_price_min,
filterusername,
)
)
log.debug(f"currently regular min filter: {len(filterusername)}")
log.debug(f"Regular Price max Filter: {args_.getargs().regular_price_max}")
if args_.getargs().regular_price_max:
filterusername = list(
filter(
lambda x: x.final_regular_price <= args_.getargs().regular_price_max,
filterusername,
)
)
log.debug(f"currently regular max filter: {len(filterusername)}")

log.debug(f"Renewal Price min Filter: {args_.getargs().renewal_price_min}")
if args_.getargs().renewal_price_min:
filterusername = list(
filter(
lambda x: x.final_renewal_price >= args_.getargs().renewal_price_min,
filterusername,
)
)
log.debug(f"currently renewal min filter: {len(filterusername)}")
log.debug(f"Renewal Price max Filter: {args_.getargs().renewal_price_max}")
if args_.getargs().renewal_price_max:
filterusername = list(
filter(
lambda x: x.final_renewal_price <= args_.getargs().renewal_price_max,
filterusername,
)
)
log.debug(f"currently renewal max filter: {len(filterusername)}")

log.debug(f"Current Price min Filter: {args_.getargs().current_price_min}")
if args_.getargs().current_price_min:
filterusername = list(
filter(
lambda x: x.final_current_price >= args_.getargs().current_price_min,
filterusername,
)
)
log.debug(f"currently current min filter: {len(filterusername)}")
log.debug(f"Current Price max Filter: {args_.getargs().current_price_max}")
if args_.getargs().current_price_max:
filterusername = list(
filter(
lambda x: x.final_current_price <= args_.getargs().current_price_max,
filterusername,
)
)
log.debug(f"currently current max filter: {len(filterusername)}")
return filterusername
2 changes: 2 additions & 0 deletions ofscraper/filters/models/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time

import ofscraper.constants as constants
import ofscraper.filters.models.date as date_
import ofscraper.filters.models.flags as flags
import ofscraper.filters.models.other as other
import ofscraper.filters.models.price as price
Expand Down Expand Up @@ -89,6 +90,7 @@ def filterNSort(usernames):
filterusername = subtype.subType(usernames)
filterusername = price.pricePaidFreeFilterHelper(filterusername)
filterusername = flags.promoFilterHelper(filterusername)
filterusername = date_.dateFilters(filterusername)
filterusername = other.otherFilters(filterusername)

log.debug(f"final username count with all filters: {len(filterusername)}")
Expand Down
24 changes: 20 additions & 4 deletions ofscraper/prompts/model_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,29 @@ def getPriceHelper(x):
"promo-price",
}:
value = re.sub("-", "_", args_.getargs().sort).replace("-", "_")
if args_.getargs().promo_price:
if (
args_.getargs().promo_price
or args_.getargs().promo_price_min
or args_.getargs().promo_price_max
):
value2 = "promo_price"
elif args_.getargs().regular_price:
elif (
args_.getargs().regular_price
or args_.getargs().regular_price_min
or args_.getargs().regular_price_max
):
value2 = "regular_price"
elif args_.getargs().renewal_price:
elif (
args_.getargs().renewal_price
or args_.getargs().renewal_price_min
or args_.getargs().renewal_price_max
):
value2 = "renewal_price"
elif args_.getargs().current_price:
elif (
args_.getargs().current_price
or args_.getargs().current_price_min
or args_.getargs().current_price_max
):
value2 = "current_price"
final_value = value or value2 or "current_price"
key = f"final_{final_value}"
Expand Down
114 changes: 106 additions & 8 deletions ofscraper/utils/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,23 @@ def create_parser(input=None):
choices=["paid", "free"],
)

# filters.add_argument(
# "-mcp",
# "--min-current-price",
# help="Filter accounts by the min current price of the account",
# default=None,
# required=False,
# type=int
# )
filters.add_argument(
"-cpn",
"--current-price-min",
help="Filter accounts where the current regular price matches or falls above the provided value",
default=False,
required=False,
type=int,
)

filters.add_argument(
"-cpm",
"--current-price-max",
help="Filter accounts where the current price matches or falls below the provided value",
default=False,
required=False,
type=int,
)

filters.add_argument(
"-rp",
Expand All @@ -299,6 +308,24 @@ def create_parser(input=None):
choices=["paid", "free"],
)

filters.add_argument(
"-rpn",
"--renewal-price-min",
help="Filter accounts where the renewal regular price matches or falls above the provided value",
default=False,
required=False,
type=int,
)

filters.add_argument(
"-rpm",
"--renewal-price-max",
help="Filter accounts where the renewal price matches or falls below the provided value",
default=False,
required=False,
type=int,
)

filters.add_argument(
"-pm",
"--promo",
Expand Down Expand Up @@ -328,6 +355,24 @@ def create_parser(input=None):
choices=["paid", "free"],
)

filters.add_argument(
"-gpn",
"--regular-price-min",
help="Filter accounts where the regular price matches or falls above the provided value",
default=False,
required=False,
type=int,
)

filters.add_argument(
"-gpm",
"--regular-price-max",
help="Filter accounts where the regular price matches or falls below the provided value",
default=False,
required=False,
type=int,
)

filters.add_argument(
"-lsb",
"--last-seen-before",
Expand Down Expand Up @@ -374,6 +419,24 @@ def create_parser(input=None):
type=str.lower,
choices=["paid", "free"],
)

filters.add_argument(
"-ppn",
"--promo-price-min",
help="Filter accounts where the lowest promo price matches or falls above the provided value",
default=False,
required=False,
type=int,
)

filters.add_argument(
"-ppm",
"--promo-price-max",
help="Filter accounts where the lowest promo price matches or falls below the provided value",
default=False,
required=False,
type=int,
)
filters.add_argument(
"-rw",
"--renewal",
Expand All @@ -383,6 +446,23 @@ def create_parser(input=None):
type=str.lower,
choices=["active", "disabled"],
)

filters.add_argument(
"-ea",
"--expired-after",
help="Filter Accounts by expiration/renewal being before the given date",
default=False,
required=False,
type=arrow_helper,
)
filters.add_argument(
"-eb",
"--expired-before",
help="Filter Accounts by expiration/renewal being before the given date",
default=False,
required=False,
type=arrow_helper,
)
filters.add_argument(
"-mp",
"--sub-status",
Expand All @@ -392,6 +472,24 @@ def create_parser(input=None):
type=str.lower,
choices=["active", "expired"],
)

filters.add_argument(
"-sa",
"--subscribed-after",
help="Filter Accounts by subscription date being before the given date",
default=False,
required=False,
type=arrow_helper,
)
filters.add_argument(
"-sb",
"--subscribed-before",
help="Filter Accounts by sub date being before the given date",
default=False,
required=False,
type=arrow_helper,
)

filters.add_argument(
"-ul",
"--user-list",
Expand Down

0 comments on commit 66c9a4c

Please sign in to comment.