Reverse engineering and modifying existing python script for new purpose [on hold]












0












$begingroup$


I am trying to reverse engineer and modify to work in reverse the python script radarrsync.



Its new purpose is to pull a list from two seperate radarrs via api, comparing for matches, to display the 'tmdbid', the 'hasFile' value (true/false), the 'id' and the 'path' values from the slave radarr of any matches and then to send a delete request to the slave radarr using the 'id' if just the 'tmdbid' match and use the modified path value to send a remove command to the actual file on top of the delete request if the 'hasFile' value == true.



Currently if I comment out the 'hasFile' if line the script runs but errors "message": "MethodNotAllowed" and doesn't delete anything (although tries to delete everything in the list), and when running with the 'hasFile' if statement it exits early as its unable to evaluate it.



Can anyone take a look and see what I have missed please



import os
import logging
import json
import sys
import requests
import configparser
import argparse
import shutil
import time

parser = argparse.ArgumentParser(description='RadarrClean. Compare two Radarr servers and clean matches from the slave.')
parser.add_argument('--config', action="store", type=str, help='Location of config file.')
parser.add_argument('--debug', help='Enable debug logging.', action="store_true")
parser.add_argument('--whatif', help="Read-Only. What would happen if I ran this. No posts are sent. Should be used with --debug", action="store_true")
args = parser.parse_args()

def ConfigSectionMap(section):
dict1 = {}
options = Config.options(section)
for option in options:
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
logger.debug("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1

Config = configparser.ConfigParser()
settingsFilename = os.path.join(os.getcwd(), 'Config.txt')
if args.config:
settingsFilename = args.config
elif not os.path.isfile(settingsFilename):
print("Creating default config. Please edit and run again.")
shutil.copyfile(os.path.join(os.getcwd(), 'Config.default'), settingsFilename)
sys.exit(0)
Config.read(settingsFilename)

print(ConfigSectionMap('Radarr_PQ')['rootfolders'].split(';'))

########################################################################################################################
logger = logging.getLogger()
if ConfigSectionMap("General")['log_level'] == 'DEBUG':
logger.setLevel(logging.DEBUG)
elif ConfigSectionMap("General")['log_level'] == 'VERBOSE':
logger.setLevel(logging.VERBOSE)
else:
logger.setLevel(logging.INFO)
if args.debug:
logger.setLevel(logging.DEBUG)

logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s")

fileHandler = logging.FileHandler(ConfigSectionMap('General')['log_path'],'w','utf-8')
fileHandler.setFormatter(logFormatter)
logger.addHandler(fileHandler)

consoleHandler = logging.StreamHandler(sys.stdout)
consoleHandler.setFormatter(logFormatter)
logger.addHandler(consoleHandler)
########################################################################################################################

session = requests.Session()
session.trust_env = False

radarr_url = ConfigSectionMap("RadarrMaster")['url']
radarr_key = ConfigSectionMap("RadarrMaster")['key']
radarrMovies = session.get('{0}/api/movie?apikey={1}'.format(radarr_url, radarr_key))
if radarrMovies.status_code != 200:
logger.error('Master Radarr server error - response {}'.format(radarrMovies.status_code))
sys.exit(0)

servers = {}
for section in Config.sections():
section = str(section)
if "Radarr_" in section:
server = (str.split(section,'Radarr_'))[1]
servers[server] = ConfigSectionMap(section)
movies = session.get('{0}/api/movie?apikey={1}'.format(servers[server]['url'], servers[server]['key']))
if movies.status_code != 200:
logger.error('{0} Radarr server error - response {1}'.format(server, movies.status_code))
sys.exit(0)
else:
servers[server]['movies'] =
servers[server]['matchMovies'] = 0
servers[server]['searchid'] =
for movie in movies.json():
servers[server]['movies'].append(movie['tmdbId'])

for movie in radarrMovies.json():
for name, server in servers.items():
if movie['tmdbId'] in server['movies']:
if movie['hasFile'] == "true":
if movie['sizeOnDisk'] != 0:
if 'rootfolders' in server:
allowedFolders = server['rootfolders'].split(';')
for folder in allowedFolders:
if not folder in movie['path']:
continue
if 'local_path' in server:
path = str(movie['path']).replace(server['local_path'], server['cloud_path'])
logging.debug('Updating movie path from: {0} to {1}'.format(movie['path'], path))
else:
path = movie['path']
logging.debug('server: {0}'.format(name))
logging.debug('title: {0}'.format(movie['title']))
logging.debug('hasFile: {0}'.format(movie['hasFile']))
logging.debug('tmdbId: {0}'.format(movie['tmdbId']))
logging.debug('id: {0}'.format(movie['id']))
logging.debug('path: {0}'.format(path))

payload = {str(movie['id'])}

logging.debug('payload: {0}'.format(payload))
server['matchMovies'] += 1
if args.whatif:
logging.debug('WhatIf: Not actually removing movie from Radarr {0}.'.format(name))
else:
if server['matchMovies'] > 0:
logging.debug('Sleeping for: {0} seconds.'.format(ConfigSectionMap('General')['wait_between_delete']))
time.sleep(int(ConfigSectionMap('General')['wait_between_delete']))
r = session.delete('{0}/api/movie?apikey={1}'.format(server['url'], server['key']), data=json.dumps(payload))
logger.info('Removing {0} from Radarr {1} server'.format(movie['title'], name))


Example of the type of values in the file pulled by the api call



  {
"title": "Anaconda",
"sizeOnDisk": 1289110670,
"downloaded": true,
"hasFile": true,
"path": "/movies/Anaconda (1997)",
"profileId": 4,
"tmdbId": 9360,
"titleSlug": "anaconda-9360",
"id": 206
},
{
"title": "Analyze That",
"sizeOnDisk": 628338045,
"downloaded": true,
"hasFile": true,
"path": "/movies/Analyze That (2002)",
"profileId": 4,
"tmdbId": 9932,
"titleSlug": "analyze-that-9932",
"id": 207
},
{
"title": "Analyze This",
"sizeOnDisk": 756275693,
"downloaded": true,
"hasFile": true,
"path": "/movies/Analyze This (1999)",
"profileId": 4,
"tmdbId": 9535,
"titleSlug": "analyze-this-9535",
"id": 208
},









share|improve this question









New contributor




Geof Grouch is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



put on hold as off-topic by πάντα ῥεῖ, Jamal 3 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.





















    0












    $begingroup$


    I am trying to reverse engineer and modify to work in reverse the python script radarrsync.



    Its new purpose is to pull a list from two seperate radarrs via api, comparing for matches, to display the 'tmdbid', the 'hasFile' value (true/false), the 'id' and the 'path' values from the slave radarr of any matches and then to send a delete request to the slave radarr using the 'id' if just the 'tmdbid' match and use the modified path value to send a remove command to the actual file on top of the delete request if the 'hasFile' value == true.



    Currently if I comment out the 'hasFile' if line the script runs but errors "message": "MethodNotAllowed" and doesn't delete anything (although tries to delete everything in the list), and when running with the 'hasFile' if statement it exits early as its unable to evaluate it.



    Can anyone take a look and see what I have missed please



    import os
    import logging
    import json
    import sys
    import requests
    import configparser
    import argparse
    import shutil
    import time

    parser = argparse.ArgumentParser(description='RadarrClean. Compare two Radarr servers and clean matches from the slave.')
    parser.add_argument('--config', action="store", type=str, help='Location of config file.')
    parser.add_argument('--debug', help='Enable debug logging.', action="store_true")
    parser.add_argument('--whatif', help="Read-Only. What would happen if I ran this. No posts are sent. Should be used with --debug", action="store_true")
    args = parser.parse_args()

    def ConfigSectionMap(section):
    dict1 = {}
    options = Config.options(section)
    for option in options:
    try:
    dict1[option] = Config.get(section, option)
    if dict1[option] == -1:
    logger.debug("skip: %s" % option)
    except:
    print("exception on %s!" % option)
    dict1[option] = None
    return dict1

    Config = configparser.ConfigParser()
    settingsFilename = os.path.join(os.getcwd(), 'Config.txt')
    if args.config:
    settingsFilename = args.config
    elif not os.path.isfile(settingsFilename):
    print("Creating default config. Please edit and run again.")
    shutil.copyfile(os.path.join(os.getcwd(), 'Config.default'), settingsFilename)
    sys.exit(0)
    Config.read(settingsFilename)

    print(ConfigSectionMap('Radarr_PQ')['rootfolders'].split(';'))

    ########################################################################################################################
    logger = logging.getLogger()
    if ConfigSectionMap("General")['log_level'] == 'DEBUG':
    logger.setLevel(logging.DEBUG)
    elif ConfigSectionMap("General")['log_level'] == 'VERBOSE':
    logger.setLevel(logging.VERBOSE)
    else:
    logger.setLevel(logging.INFO)
    if args.debug:
    logger.setLevel(logging.DEBUG)

    logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s")

    fileHandler = logging.FileHandler(ConfigSectionMap('General')['log_path'],'w','utf-8')
    fileHandler.setFormatter(logFormatter)
    logger.addHandler(fileHandler)

    consoleHandler = logging.StreamHandler(sys.stdout)
    consoleHandler.setFormatter(logFormatter)
    logger.addHandler(consoleHandler)
    ########################################################################################################################

    session = requests.Session()
    session.trust_env = False

    radarr_url = ConfigSectionMap("RadarrMaster")['url']
    radarr_key = ConfigSectionMap("RadarrMaster")['key']
    radarrMovies = session.get('{0}/api/movie?apikey={1}'.format(radarr_url, radarr_key))
    if radarrMovies.status_code != 200:
    logger.error('Master Radarr server error - response {}'.format(radarrMovies.status_code))
    sys.exit(0)

    servers = {}
    for section in Config.sections():
    section = str(section)
    if "Radarr_" in section:
    server = (str.split(section,'Radarr_'))[1]
    servers[server] = ConfigSectionMap(section)
    movies = session.get('{0}/api/movie?apikey={1}'.format(servers[server]['url'], servers[server]['key']))
    if movies.status_code != 200:
    logger.error('{0} Radarr server error - response {1}'.format(server, movies.status_code))
    sys.exit(0)
    else:
    servers[server]['movies'] =
    servers[server]['matchMovies'] = 0
    servers[server]['searchid'] =
    for movie in movies.json():
    servers[server]['movies'].append(movie['tmdbId'])

    for movie in radarrMovies.json():
    for name, server in servers.items():
    if movie['tmdbId'] in server['movies']:
    if movie['hasFile'] == "true":
    if movie['sizeOnDisk'] != 0:
    if 'rootfolders' in server:
    allowedFolders = server['rootfolders'].split(';')
    for folder in allowedFolders:
    if not folder in movie['path']:
    continue
    if 'local_path' in server:
    path = str(movie['path']).replace(server['local_path'], server['cloud_path'])
    logging.debug('Updating movie path from: {0} to {1}'.format(movie['path'], path))
    else:
    path = movie['path']
    logging.debug('server: {0}'.format(name))
    logging.debug('title: {0}'.format(movie['title']))
    logging.debug('hasFile: {0}'.format(movie['hasFile']))
    logging.debug('tmdbId: {0}'.format(movie['tmdbId']))
    logging.debug('id: {0}'.format(movie['id']))
    logging.debug('path: {0}'.format(path))

    payload = {str(movie['id'])}

    logging.debug('payload: {0}'.format(payload))
    server['matchMovies'] += 1
    if args.whatif:
    logging.debug('WhatIf: Not actually removing movie from Radarr {0}.'.format(name))
    else:
    if server['matchMovies'] > 0:
    logging.debug('Sleeping for: {0} seconds.'.format(ConfigSectionMap('General')['wait_between_delete']))
    time.sleep(int(ConfigSectionMap('General')['wait_between_delete']))
    r = session.delete('{0}/api/movie?apikey={1}'.format(server['url'], server['key']), data=json.dumps(payload))
    logger.info('Removing {0} from Radarr {1} server'.format(movie['title'], name))


    Example of the type of values in the file pulled by the api call



      {
    "title": "Anaconda",
    "sizeOnDisk": 1289110670,
    "downloaded": true,
    "hasFile": true,
    "path": "/movies/Anaconda (1997)",
    "profileId": 4,
    "tmdbId": 9360,
    "titleSlug": "anaconda-9360",
    "id": 206
    },
    {
    "title": "Analyze That",
    "sizeOnDisk": 628338045,
    "downloaded": true,
    "hasFile": true,
    "path": "/movies/Analyze That (2002)",
    "profileId": 4,
    "tmdbId": 9932,
    "titleSlug": "analyze-that-9932",
    "id": 207
    },
    {
    "title": "Analyze This",
    "sizeOnDisk": 756275693,
    "downloaded": true,
    "hasFile": true,
    "path": "/movies/Analyze This (1999)",
    "profileId": 4,
    "tmdbId": 9535,
    "titleSlug": "analyze-this-9535",
    "id": 208
    },









    share|improve this question









    New contributor




    Geof Grouch is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$



    put on hold as off-topic by πάντα ῥεῖ, Jamal 3 hours ago


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Jamal

    If this question can be reworded to fit the rules in the help center, please edit the question.



















      0












      0








      0





      $begingroup$


      I am trying to reverse engineer and modify to work in reverse the python script radarrsync.



      Its new purpose is to pull a list from two seperate radarrs via api, comparing for matches, to display the 'tmdbid', the 'hasFile' value (true/false), the 'id' and the 'path' values from the slave radarr of any matches and then to send a delete request to the slave radarr using the 'id' if just the 'tmdbid' match and use the modified path value to send a remove command to the actual file on top of the delete request if the 'hasFile' value == true.



      Currently if I comment out the 'hasFile' if line the script runs but errors "message": "MethodNotAllowed" and doesn't delete anything (although tries to delete everything in the list), and when running with the 'hasFile' if statement it exits early as its unable to evaluate it.



      Can anyone take a look and see what I have missed please



      import os
      import logging
      import json
      import sys
      import requests
      import configparser
      import argparse
      import shutil
      import time

      parser = argparse.ArgumentParser(description='RadarrClean. Compare two Radarr servers and clean matches from the slave.')
      parser.add_argument('--config', action="store", type=str, help='Location of config file.')
      parser.add_argument('--debug', help='Enable debug logging.', action="store_true")
      parser.add_argument('--whatif', help="Read-Only. What would happen if I ran this. No posts are sent. Should be used with --debug", action="store_true")
      args = parser.parse_args()

      def ConfigSectionMap(section):
      dict1 = {}
      options = Config.options(section)
      for option in options:
      try:
      dict1[option] = Config.get(section, option)
      if dict1[option] == -1:
      logger.debug("skip: %s" % option)
      except:
      print("exception on %s!" % option)
      dict1[option] = None
      return dict1

      Config = configparser.ConfigParser()
      settingsFilename = os.path.join(os.getcwd(), 'Config.txt')
      if args.config:
      settingsFilename = args.config
      elif not os.path.isfile(settingsFilename):
      print("Creating default config. Please edit and run again.")
      shutil.copyfile(os.path.join(os.getcwd(), 'Config.default'), settingsFilename)
      sys.exit(0)
      Config.read(settingsFilename)

      print(ConfigSectionMap('Radarr_PQ')['rootfolders'].split(';'))

      ########################################################################################################################
      logger = logging.getLogger()
      if ConfigSectionMap("General")['log_level'] == 'DEBUG':
      logger.setLevel(logging.DEBUG)
      elif ConfigSectionMap("General")['log_level'] == 'VERBOSE':
      logger.setLevel(logging.VERBOSE)
      else:
      logger.setLevel(logging.INFO)
      if args.debug:
      logger.setLevel(logging.DEBUG)

      logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s")

      fileHandler = logging.FileHandler(ConfigSectionMap('General')['log_path'],'w','utf-8')
      fileHandler.setFormatter(logFormatter)
      logger.addHandler(fileHandler)

      consoleHandler = logging.StreamHandler(sys.stdout)
      consoleHandler.setFormatter(logFormatter)
      logger.addHandler(consoleHandler)
      ########################################################################################################################

      session = requests.Session()
      session.trust_env = False

      radarr_url = ConfigSectionMap("RadarrMaster")['url']
      radarr_key = ConfigSectionMap("RadarrMaster")['key']
      radarrMovies = session.get('{0}/api/movie?apikey={1}'.format(radarr_url, radarr_key))
      if radarrMovies.status_code != 200:
      logger.error('Master Radarr server error - response {}'.format(radarrMovies.status_code))
      sys.exit(0)

      servers = {}
      for section in Config.sections():
      section = str(section)
      if "Radarr_" in section:
      server = (str.split(section,'Radarr_'))[1]
      servers[server] = ConfigSectionMap(section)
      movies = session.get('{0}/api/movie?apikey={1}'.format(servers[server]['url'], servers[server]['key']))
      if movies.status_code != 200:
      logger.error('{0} Radarr server error - response {1}'.format(server, movies.status_code))
      sys.exit(0)
      else:
      servers[server]['movies'] =
      servers[server]['matchMovies'] = 0
      servers[server]['searchid'] =
      for movie in movies.json():
      servers[server]['movies'].append(movie['tmdbId'])

      for movie in radarrMovies.json():
      for name, server in servers.items():
      if movie['tmdbId'] in server['movies']:
      if movie['hasFile'] == "true":
      if movie['sizeOnDisk'] != 0:
      if 'rootfolders' in server:
      allowedFolders = server['rootfolders'].split(';')
      for folder in allowedFolders:
      if not folder in movie['path']:
      continue
      if 'local_path' in server:
      path = str(movie['path']).replace(server['local_path'], server['cloud_path'])
      logging.debug('Updating movie path from: {0} to {1}'.format(movie['path'], path))
      else:
      path = movie['path']
      logging.debug('server: {0}'.format(name))
      logging.debug('title: {0}'.format(movie['title']))
      logging.debug('hasFile: {0}'.format(movie['hasFile']))
      logging.debug('tmdbId: {0}'.format(movie['tmdbId']))
      logging.debug('id: {0}'.format(movie['id']))
      logging.debug('path: {0}'.format(path))

      payload = {str(movie['id'])}

      logging.debug('payload: {0}'.format(payload))
      server['matchMovies'] += 1
      if args.whatif:
      logging.debug('WhatIf: Not actually removing movie from Radarr {0}.'.format(name))
      else:
      if server['matchMovies'] > 0:
      logging.debug('Sleeping for: {0} seconds.'.format(ConfigSectionMap('General')['wait_between_delete']))
      time.sleep(int(ConfigSectionMap('General')['wait_between_delete']))
      r = session.delete('{0}/api/movie?apikey={1}'.format(server['url'], server['key']), data=json.dumps(payload))
      logger.info('Removing {0} from Radarr {1} server'.format(movie['title'], name))


      Example of the type of values in the file pulled by the api call



        {
      "title": "Anaconda",
      "sizeOnDisk": 1289110670,
      "downloaded": true,
      "hasFile": true,
      "path": "/movies/Anaconda (1997)",
      "profileId": 4,
      "tmdbId": 9360,
      "titleSlug": "anaconda-9360",
      "id": 206
      },
      {
      "title": "Analyze That",
      "sizeOnDisk": 628338045,
      "downloaded": true,
      "hasFile": true,
      "path": "/movies/Analyze That (2002)",
      "profileId": 4,
      "tmdbId": 9932,
      "titleSlug": "analyze-that-9932",
      "id": 207
      },
      {
      "title": "Analyze This",
      "sizeOnDisk": 756275693,
      "downloaded": true,
      "hasFile": true,
      "path": "/movies/Analyze This (1999)",
      "profileId": 4,
      "tmdbId": 9535,
      "titleSlug": "analyze-this-9535",
      "id": 208
      },









      share|improve this question









      New contributor




      Geof Grouch is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I am trying to reverse engineer and modify to work in reverse the python script radarrsync.



      Its new purpose is to pull a list from two seperate radarrs via api, comparing for matches, to display the 'tmdbid', the 'hasFile' value (true/false), the 'id' and the 'path' values from the slave radarr of any matches and then to send a delete request to the slave radarr using the 'id' if just the 'tmdbid' match and use the modified path value to send a remove command to the actual file on top of the delete request if the 'hasFile' value == true.



      Currently if I comment out the 'hasFile' if line the script runs but errors "message": "MethodNotAllowed" and doesn't delete anything (although tries to delete everything in the list), and when running with the 'hasFile' if statement it exits early as its unable to evaluate it.



      Can anyone take a look and see what I have missed please



      import os
      import logging
      import json
      import sys
      import requests
      import configparser
      import argparse
      import shutil
      import time

      parser = argparse.ArgumentParser(description='RadarrClean. Compare two Radarr servers and clean matches from the slave.')
      parser.add_argument('--config', action="store", type=str, help='Location of config file.')
      parser.add_argument('--debug', help='Enable debug logging.', action="store_true")
      parser.add_argument('--whatif', help="Read-Only. What would happen if I ran this. No posts are sent. Should be used with --debug", action="store_true")
      args = parser.parse_args()

      def ConfigSectionMap(section):
      dict1 = {}
      options = Config.options(section)
      for option in options:
      try:
      dict1[option] = Config.get(section, option)
      if dict1[option] == -1:
      logger.debug("skip: %s" % option)
      except:
      print("exception on %s!" % option)
      dict1[option] = None
      return dict1

      Config = configparser.ConfigParser()
      settingsFilename = os.path.join(os.getcwd(), 'Config.txt')
      if args.config:
      settingsFilename = args.config
      elif not os.path.isfile(settingsFilename):
      print("Creating default config. Please edit and run again.")
      shutil.copyfile(os.path.join(os.getcwd(), 'Config.default'), settingsFilename)
      sys.exit(0)
      Config.read(settingsFilename)

      print(ConfigSectionMap('Radarr_PQ')['rootfolders'].split(';'))

      ########################################################################################################################
      logger = logging.getLogger()
      if ConfigSectionMap("General")['log_level'] == 'DEBUG':
      logger.setLevel(logging.DEBUG)
      elif ConfigSectionMap("General")['log_level'] == 'VERBOSE':
      logger.setLevel(logging.VERBOSE)
      else:
      logger.setLevel(logging.INFO)
      if args.debug:
      logger.setLevel(logging.DEBUG)

      logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s")

      fileHandler = logging.FileHandler(ConfigSectionMap('General')['log_path'],'w','utf-8')
      fileHandler.setFormatter(logFormatter)
      logger.addHandler(fileHandler)

      consoleHandler = logging.StreamHandler(sys.stdout)
      consoleHandler.setFormatter(logFormatter)
      logger.addHandler(consoleHandler)
      ########################################################################################################################

      session = requests.Session()
      session.trust_env = False

      radarr_url = ConfigSectionMap("RadarrMaster")['url']
      radarr_key = ConfigSectionMap("RadarrMaster")['key']
      radarrMovies = session.get('{0}/api/movie?apikey={1}'.format(radarr_url, radarr_key))
      if radarrMovies.status_code != 200:
      logger.error('Master Radarr server error - response {}'.format(radarrMovies.status_code))
      sys.exit(0)

      servers = {}
      for section in Config.sections():
      section = str(section)
      if "Radarr_" in section:
      server = (str.split(section,'Radarr_'))[1]
      servers[server] = ConfigSectionMap(section)
      movies = session.get('{0}/api/movie?apikey={1}'.format(servers[server]['url'], servers[server]['key']))
      if movies.status_code != 200:
      logger.error('{0} Radarr server error - response {1}'.format(server, movies.status_code))
      sys.exit(0)
      else:
      servers[server]['movies'] =
      servers[server]['matchMovies'] = 0
      servers[server]['searchid'] =
      for movie in movies.json():
      servers[server]['movies'].append(movie['tmdbId'])

      for movie in radarrMovies.json():
      for name, server in servers.items():
      if movie['tmdbId'] in server['movies']:
      if movie['hasFile'] == "true":
      if movie['sizeOnDisk'] != 0:
      if 'rootfolders' in server:
      allowedFolders = server['rootfolders'].split(';')
      for folder in allowedFolders:
      if not folder in movie['path']:
      continue
      if 'local_path' in server:
      path = str(movie['path']).replace(server['local_path'], server['cloud_path'])
      logging.debug('Updating movie path from: {0} to {1}'.format(movie['path'], path))
      else:
      path = movie['path']
      logging.debug('server: {0}'.format(name))
      logging.debug('title: {0}'.format(movie['title']))
      logging.debug('hasFile: {0}'.format(movie['hasFile']))
      logging.debug('tmdbId: {0}'.format(movie['tmdbId']))
      logging.debug('id: {0}'.format(movie['id']))
      logging.debug('path: {0}'.format(path))

      payload = {str(movie['id'])}

      logging.debug('payload: {0}'.format(payload))
      server['matchMovies'] += 1
      if args.whatif:
      logging.debug('WhatIf: Not actually removing movie from Radarr {0}.'.format(name))
      else:
      if server['matchMovies'] > 0:
      logging.debug('Sleeping for: {0} seconds.'.format(ConfigSectionMap('General')['wait_between_delete']))
      time.sleep(int(ConfigSectionMap('General')['wait_between_delete']))
      r = session.delete('{0}/api/movie?apikey={1}'.format(server['url'], server['key']), data=json.dumps(payload))
      logger.info('Removing {0} from Radarr {1} server'.format(movie['title'], name))


      Example of the type of values in the file pulled by the api call



        {
      "title": "Anaconda",
      "sizeOnDisk": 1289110670,
      "downloaded": true,
      "hasFile": true,
      "path": "/movies/Anaconda (1997)",
      "profileId": 4,
      "tmdbId": 9360,
      "titleSlug": "anaconda-9360",
      "id": 206
      },
      {
      "title": "Analyze That",
      "sizeOnDisk": 628338045,
      "downloaded": true,
      "hasFile": true,
      "path": "/movies/Analyze That (2002)",
      "profileId": 4,
      "tmdbId": 9932,
      "titleSlug": "analyze-that-9932",
      "id": 207
      },
      {
      "title": "Analyze This",
      "sizeOnDisk": 756275693,
      "downloaded": true,
      "hasFile": true,
      "path": "/movies/Analyze This (1999)",
      "profileId": 4,
      "tmdbId": 9535,
      "titleSlug": "analyze-this-9535",
      "id": 208
      },






      python-3.x






      share|improve this question









      New contributor




      Geof Grouch is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Geof Grouch is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 6 hours ago







      Geof Grouch













      New contributor




      Geof Grouch is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 6 hours ago









      Geof GrouchGeof Grouch

      61




      61




      New contributor




      Geof Grouch is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Geof Grouch is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Geof Grouch is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      put on hold as off-topic by πάντα ῥεῖ, Jamal 3 hours ago


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Jamal

      If this question can be reworded to fit the rules in the help center, please edit the question.







      put on hold as off-topic by πάντα ῥεῖ, Jamal 3 hours ago


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Jamal

      If this question can be reworded to fit the rules in the help center, please edit the question.






















          0






          active

          oldest

          votes

















          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

          is 'sed' thread safe

          How to make a Squid Proxy server?