Skip to content

Commit

Permalink
- Removed username, password no longer needed when using API key
Browse files Browse the repository at this point in the history
- Replaced json.loads by json.load for string reading ( correct one)
- removed unnecessary code 
- Fixed the indexes for return values
- Added a todo comment for tagging
  • Loading branch information
Mirabis committed Apr 10, 2014
1 parent 9198ba7 commit f643a1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
2 changes: 0 additions & 2 deletions autoProcess.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ api_key=
[NzbDrone]
host=localhost
port=8082
username=
password=
web_root=
ssl=0
api_key=
Expand Down
31 changes: 10 additions & 21 deletions nzbDroneFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ def scan(directory,status=0):
host = config.get("NzbDrone", "host")
port = config.get("NzbDrone", "port")
apikey = config.get("NzbDrone", "api_key")
username = config.get("NzbDrone", "username")
password = config.get("NzbDrone", "password")
try:
ssl = int(config.get("NzbDrone", "ssl"))
except (ConfigParser.NoOptionError, ValueError):
Expand All @@ -60,12 +58,6 @@ def scan(directory,status=0):
c.setopt(pycurl.HTTPHEADER, ['{0} : {1}'.format('X-Api-Key', apikey)])
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, postData)
#Optional username/password if needed
#if username and password:
# c.setopt(pycurl.USERPWD, '{0}:{1}'.format(username, password)
#else:
# randomtxt = "without this i had syntax error"
#perform the request
try:
c.perform()
except pycurl.error, error:
Expand All @@ -74,26 +66,23 @@ def scan(directory,status=0):
sys.exit(2)

# Handle the response
print contents.getvalue() + "\n==============================\n" #result of API call
contentasjson = contents.getvalue()
print contentasjson + "\n==============================\n" #result of API call
responseCode = c.getinfo(pycurl.HTTP_CODE);
print 'Response code: ' + str(responseCode);
isSuccesResponse = responseCode < 400;
pyobj = json.loads(contents.getvalue())
print 'Status: ' + str(pyobj['Response']['Status'])
print 'Code: ' + str(pyobj['Response']['Code'])

pyobj = json.load(contentasjson)
# Print information to read on Sabnzbd if went succesfull
if (isSuccesResponse):
print 'Name: ' + str(pyobj['Response']['name'])
print 'StartedOn: ' + str(pyobj['Response']['startedOn'])
print 'StateChangeTime: ' + str(pyobj['Response']['stateChangeTime'])
print 'SendUpdatesToClient: ' + str(pyobj['Response']['sendUpdatesToClient'])
print 'State: ' + str(pyobj['Response']['state'])
print 'SeriesID: ' + str(pyobj['Response']['id'])
#exit succesfull
print 'Name: ' + str(pyobj['name'])
print 'StartedOn: ' + str(pyobj['startedOn'])
print 'StateChangeTime: ' + str(pyobj['stateChangeTime'])
print 'SendUpdatesToClient: ' + str(pyobj['sendUpdatesToClient'])
print 'State: ' + str(pyobj['state'])
print 'SeriesID: ' + str(pyobj['id'])
# TODO: Tagging of file
sys.exit(0)
else:
print 'Errors: ' + str(pyobj['Response']['Errors']) # Not sure what the correct error response is, did not test it
sys.exit(2)


Expand Down

0 comments on commit f643a1d

Please sign in to comment.