Skip to content

Commit

Permalink
added support for deleting reviews by itemname
Browse files Browse the repository at this point in the history
  • Loading branch information
jake authored and jake committed Jan 6, 2023
1 parent 24036f6 commit 84e7630
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions internetarchive/cli/ia_reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
usage:
ia reviews <identifier>
ia reviews <identifier> --delete [--username=<username> | --screenname=<screenname>]
ia reviews <identifier> --delete [--username=<username> | --screenname=<screenname>
| --itemname=<itemname>]
ia reviews <identifier> --title=<title> --body=<body> [--stars=<stars>]
ia reviews --help
Expand All @@ -39,6 +40,8 @@
given username (must be used with --delete).
-S, --screenname=<screenname> Delete reviews for a specific user
given screenname (must be used with --delete).
-I, --itemname=<itemname> Delete reviews for a specific user
given itemname (must be used with --delete).
examples:
ia reviews nasa
Expand All @@ -57,7 +60,8 @@ def main(argv, session: ArchiveSession) -> None:
item = session.get_item(args['<identifier>'])
if args['--delete']:
r = item.delete_review(username=args['--username'],
screenname=args['--screenname'])
screenname=args['--screenname'],
itemname=args['--itemname'])
elif not args['--body']:
try:
r = item.get_review()
Expand Down
4 changes: 3 additions & 1 deletion internetarchive/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,16 @@ def get_review(self) -> Response:
r.raise_for_status()
return r

def delete_review(self, username=None, screenname=None) -> Response:
def delete_review(self, username=None, screenname=None, itemname=None) -> Response:
u = f'{self.session.protocol}//{self.session.host}/services/reviews.php'
p = {'identifier': self.identifier}
d = None
if username:
d = {'username': username}
elif screenname:
d = {'screenname': screenname}
elif itemname:
d = {'itemname': itemname}
a = S3Auth(self.session.access_key, self.session.secret_key)
r = self.session.delete(u, params=p, data=d, auth=a)
r.raise_for_status()
Expand Down

0 comments on commit 84e7630

Please sign in to comment.