Created
February 15, 2016 08:48
-
-
Save liiight/f6225f640080bd387104 to your computer and use it in GitHub Desktop.
Delete stale movies by age
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(datetime.now(),parser.parse(movie['added'],ignoretz=True)) >= date_threshold_in_years: | |
movies_for_deletion.append(movie) | |
for movie in movies_for_deletion: | |
resp = requests.delete(delete_movies_endpoint.format(movie['id'])) | |
if resp.status_code != 200: | |
print 'ERROR' | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment