Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Delete stale movies by age
import requests
from datetime import datetime
from dateutil import parser
from dateutil.relativedelta import relativedelta
host = '<HOST NAME>'
port = 7171
token = '<USER TOKEN>'
get_movies_endpoint = '/api/movie_queue/?page=1&max=1000&queue_name=default&is_downloaded=false&sort_by=added&order=desc'
delete_movies_endpoint = '/api/movie_queue/{0}'
date_threshold_in_years = 4
url = 'http://{0}:{1}{2}'.format(host, port, get_movies_endpoint)
headers = {'Authorization': 'Token {0}'.format(token)}
response = requests.get(url=url, headers=headers).json()
movies = response['movies']
movies_for_deletion =[]
for movie in movies:
if relativedelta(,parser.parse(movie['added'],ignoretz=True)) >= date_threshold_in_years:
for movie in movies_for_deletion:
resp = requests.delete(delete_movies_endpoint.format(movie['id']))
if resp.status_code != 200:
print 'ERROR'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment