History auto-purge

Share your scripts or request scripts with specific features.
Forum rules
Please keep the forum clean - one topic per script. Questions not related to a specific script should be posted in Support forum.
ubt
Posts: 12
Joined: 14 Apr 2014, 19:55

History auto-purge

Post by ubt » 07 Jan 2016, 21:11

UPDATED

This is a Scheduler script that deletes history of items from specified categories. You must create a Scheduler task to use it. It is not a Post-Processing script.

CleanHistory.py

Code: Select all

#!/usr/bin/env python
#
####################################################################
### TASK TIME: *, *:00, *:15, *:30, *:45                         ###
####################################################################
### NZBGET SCHEDULER SCRIPT                                      ###
####################################################################
# Clean History
#
# A Scheduler script that removes items matching a Category list 
# from history. You must create a Scheduler Task to run this script.
#
# Suggested TaskX.Time is "*, *:00, *:15, *:30, *:45".
#
# Why not a Post-Processing script you ask? Because a
# post-processing script cannot act upon the history of an item
# currently being processed in queue. In other words, it can't
# delete itself.
####################################################################
### OPTIONS                                                      ###

# Category List
#
# A comma-delimited list of Categories to match for history removal. Matches are case-sensitive.
#Categories=Adult, XXX

# Category History Delete Method (hide, delete).
#
# Select whether to permanently delete items from history, or
# just simply hide them. 
#Method=hide

### NZBGET SCHEDULER SCRIPT                                      ###
####################################################################

import os
import sys
from urllib2 import quote
from xmlrpclib import ServerProxy

host = os.environ['NZBOP_CONTROLIP']
port = os.environ['NZBOP_CONTROLPORT']
username = os.environ['NZBOP_CONTROLUSERNAME']
password = os.environ['NZBOP_CONTROLPASSWORD']

categories = [item.strip() for item in os.environ['NZBPO_CATEGORIES'].split(',')]

if os.environ['NZBPO_METHOD'] == 'delete':
  delete_method = 'HistoryFinalDelete'
else:
  delete_method = 'HistoryDelete'

if host == '0.0.0.0': host = '127.0.0.1'

rpcUrl = 'http://%s:%s@%s:%s/xmlrpc' % (quote(username), quote(password), host, port)

server = ServerProxy(rpcUrl)

for item in server.history():
  for this_category in categories:
    if item['Category'] == this_category:
      result = server.editqueue(delete_method, '', item['ID'])

sys.exit(93)
Last edited by ubt on 21 Feb 2020, 03:07, edited 4 times in total.

hugbug
Developer & Admin
Posts: 7539
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: History auto-purge

Post by hugbug » 07 Jan 2016, 21:34

Very useful ;)

Make it to scheduler script:

Code: Select all

### NZBGET SCHEDULER SCRIPT
See https://github.com/nzbget/nzbget/wiki/Extension-scripts for details.

Then it can be managed from within NZBGet and you can add configurable options to define categories.
And you can read host, port username and password from passed configuration, see Logger.py as example.

ubt
Posts: 12
Joined: 14 Apr 2014, 19:55

Re: History auto-purge

Post by ubt » 07 Jan 2016, 23:06

That's a good idea, I'm looking at that now. Is there a way to tell NZBGet to run the scheduler script on demand to make testing easier?

hugbug
Developer & Admin
Posts: 7539
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: History auto-purge

Post by hugbug » 07 Jan 2016, 23:13

No, but you can test from terminal. Setup required environment variables, which nzbget usually do and which your script reads. Then you can start script from that terminal and the script will think it was started from nzbget.

ubt
Posts: 12
Joined: 14 Apr 2014, 19:55

Re: History auto-purge

Post by ubt » 07 Jan 2016, 23:36

<redundant>
Last edited by ubt on 08 Jan 2016, 23:57, edited 1 time in total.

ubt
Posts: 12
Joined: 14 Apr 2014, 19:55

[Scheduler-Script] CleanHistory - Remove downloads from hist

Post by ubt » 08 Jan 2016, 17:52

<redundant>
Last edited by ubt on 08 Jan 2016, 23:57, edited 1 time in total.

hugbug
Developer & Admin
Posts: 7539
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: [Scheduler-Script] CleanHistory - Remove downloads from

Post by hugbug » 08 Jan 2016, 18:19

Should I merge the threads?

ubt
Posts: 12
Joined: 14 Apr 2014, 19:55

Re: [Scheduler-Script] CleanHistory - Remove downloads from

Post by ubt » 08 Jan 2016, 18:22

Yes please, sorry for the dupe.

hugbug
Developer & Admin
Posts: 7539
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: [Scheduler-Script] CleanHistory - Remove downloads from

Post by hugbug » 08 Jan 2016, 18:41

Merged.
The posts are displayed in timestamp order. Feel free to edit the first post as you like.
Thank you for the script, nice work.

ubt
Posts: 12
Joined: 14 Apr 2014, 19:55

Re: [Scheduler-Script] CleanHistory - Remove downloads from

Post by ubt » 08 Jan 2016, 23:58

hugbug wrote:Merged.
The posts are displayed in timestamp order. Feel free to edit the first post as you like.
Thank you for the script, nice work.
Thanks, it was good to get my feet wet with Python a little bit.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests