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: 10
Joined: 14 Apr 2014, 19:55

History auto-purge

Post by ubt » 07 Jan 2016, 21:11

All it does is pull the history list whenever scheduler calls it, and delete any entry matching specified categories.

CleanHistory.py

Code: Select all

#!/usr/bin/env python2
#
####################################################################
### NZBGET SCHEDULER SCRIPT                                      ###

# This script removes items matching a category list from history.
#
# NOTE: This script requires Python to be installed on your system.

####################################################################
### OPTIONS                                                      ###

# Comma-delimited list of categories to match for history removal.
#Categories=Adult

# Permanently delete history? If disabled items will be hidden instead (0, 1).
#Permanent=1

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

import os
import sys
from jsonrpclib import jsonrpc

host = os.environ['NZBOP_CONTROLIP'];
port = os.environ['NZBOP_CONTROLPORT'];
username = os.environ['NZBOP_CONTROLUSERNAME'];
password = os.environ['NZBOP_CONTROLPASSWORD'];
catlist = os.environ['NZBPO_CATEGORIES'].split(',')
rpcUrl = 'http://%s:%s@%s:%s/jsonrpc' % (username, password, host, port)

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

if os.environ['NZBPO_PERMANENT'] == 1:
        delmethod = 'HistoryFinalDelete'
else:
        delmethod = 'HistoryDelete'

nzbget = jsonrpc.ServerProxy(rpcUrl)

for item in nzbget.history():
        for cat in catlist:
                if item['Category'] == cat.strip():
                        result = nzbget.editqueue(delmethod, 0, '', item['ID'])

sys.exit()
Last edited by ubt on 08 Jan 2016, 23:56, edited 2 times in total.

hugbug
Developer & Admin
Posts: 6587
Joined: 09 Sep 2008, 11:58
Location: Germany (NRW)

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: 10
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: 6587
Joined: 09 Sep 2008, 11:58
Location: Germany (NRW)

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: 10
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: 10
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: 6587
Joined: 09 Sep 2008, 11:58
Location: Germany (NRW)

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

Post by hugbug » 08 Jan 2016, 18:19

Should I merge the threads?

ubt
Posts: 10
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: 6587
Joined: 09 Sep 2008, 11:58
Location: Germany (NRW)

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: 10
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: Yahoo [Bot] and 3 guests