Skip to content

Commit

Permalink
add most sorts with defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
datawhores committed Aug 28, 2024
1 parent cdce636 commit 7b20ea3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion ofscraper/commands/managers/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,20 @@ def get_max_post(self):
self.media=medias
def sort_media(self):
medias=self.media
medias=sorted(medias,key=lambda x:arrow.get(x["posted_at"]),reverse=True)
reversed=not read_args.retriveArgs().db_asc
sort=read_args.retriveArgs().db_sort
if sort=="posted":
medias=sorted(medias,key=lambda x:arrow.get(x["posted_at"] or 0),reverse=reversed)
elif sort=="created":
medias=sorted(medias,key=lambda x:arrow.get(x["created_at"] or 0),reverse=reversed)
elif sort=="filename":
medias=sorted(medias,key=lambda x: x["filename"] or "",reverse=reversed)
elif sort=="postid":
medias=sorted(medias,key=lambda x: x["post_id"],reverse=reversed)
elif sort=="mediaid":
medias=sorted(medias,key=lambda x: x["media_id"],reverse=reversed)
elif sort=="size":
medias=sorted(medias,key=lambda x: x["size"] or 0,reverse=reversed)
self.media=medias


Expand Down
4 changes: 2 additions & 2 deletions ofscraper/utils/args/parse/arguments/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@

db_desc_option = click.option(
"-bdc",
"--db-desc",
"--db-asc",
help=
"""
Change the sort order of table to reverse
Change the sort order of table to ascending
""",
is_flag=True,
default=False,
Expand Down

0 comments on commit 7b20ea3

Please sign in to comment.