Use urlopener
This commit is contained in:
@@ -6,7 +6,6 @@ from couchpotato.environment import Env
|
||||
import re
|
||||
import telnetlib
|
||||
import urllib
|
||||
import urllib2
|
||||
|
||||
try:
|
||||
import xml.etree.cElementTree as etree
|
||||
@@ -81,12 +80,10 @@ class NMJ(Notification):
|
||||
database = self.conf('database')
|
||||
|
||||
if self.mount:
|
||||
try:
|
||||
req = urllib2.Request(mount)
|
||||
log.debug('Try to mount network drive via url: %s' % (mount))
|
||||
handle = urllib2.urlopen(req)
|
||||
except IOError, e:
|
||||
log.error('Warning: Couldn\'t contact popcorn hour on host %s: %s' % (host, e))
|
||||
log.debug('Try to mount network drive via url: %s' % (mount))
|
||||
data = self.urlopen(mount)
|
||||
if not data:
|
||||
log.error('Warning: Couldn\'t contact popcorn hour on host %s' % host)
|
||||
return False
|
||||
|
||||
params = {
|
||||
@@ -99,13 +96,9 @@ class NMJ(Notification):
|
||||
UPDATE_URL = 'http://%(host)s:8008/metadata_database?%(params)s'
|
||||
updateUrl = UPDATE_URL % {'host': host, 'params': params}
|
||||
|
||||
try:
|
||||
req = urllib2.Request(updateUrl)
|
||||
log.debug('Sending NMJ scan update command via url: %s' % (updateUrl))
|
||||
handle = urllib2.urlopen(req)
|
||||
response = handle.read()
|
||||
except IOError, e:
|
||||
log.error('Warning: Couldn\'t contact Popcorn Hour on host %s: %s' % (host, e))
|
||||
response = self.urlopen(updateUrl)
|
||||
if not response:
|
||||
log.error('Warning: Couldn\'t contact Popcorn Hour on host %s' % host)
|
||||
return False
|
||||
|
||||
try:
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.notifications.base import Notification
|
||||
from couchpotato.environment import Env
|
||||
from flask.helpers import json
|
||||
import base64
|
||||
import urllib
|
||||
import urllib2
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -23,15 +19,15 @@ class Notifo(Notification):
|
||||
if self.isDisabled(): return
|
||||
|
||||
try:
|
||||
data = urllib.urlencode({
|
||||
params = {
|
||||
'msg': toUnicode(message),
|
||||
})
|
||||
}
|
||||
|
||||
req = urllib2.Request(self.url)
|
||||
authHeader = "Basic %s" % base64.encodestring('%s:%s' % (self.conf('username'), self.conf('api_key')))[:-1]
|
||||
req.add_header("Authorization", authHeader)
|
||||
headers = {
|
||||
'Authorization': "Basic %s" % base64.encodestring('%s:%s' % (self.conf('username'), self.conf('api_key')))[:-1]
|
||||
}
|
||||
|
||||
handle = urllib2.urlopen(req, data)
|
||||
handle = self.urlopen(self.url, params = params, headers = headers)
|
||||
result = json.load(handle)
|
||||
|
||||
if result['status'] != 'success' or result['response_message'] != 'OK':
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.notifications.base import Notification
|
||||
from xml.dom import minidom
|
||||
import urllib
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -23,12 +20,12 @@ class Plex(Notification):
|
||||
refresh_url = '%s/%%s/refresh' % base_url
|
||||
|
||||
try:
|
||||
xml_sections = minidom.parse(urllib.urlopen(base_url))
|
||||
xml_sections = minidom.parse(self.urlopen(base_url))
|
||||
sections = xml_sections.getElementsByTagName('Directory')
|
||||
for s in sections:
|
||||
if s.getAttribute('type') in source_type:
|
||||
url = refresh_url % s.getAttribute('key')
|
||||
x = urllib.urlopen(url)
|
||||
x = self.urlopen(url)
|
||||
except:
|
||||
log.error('Plex library update failed for %s.' % host)
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.notifications.base import Notification
|
||||
import base64
|
||||
import urllib
|
||||
import urllib2
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -22,15 +21,14 @@ class XBMC(Notification):
|
||||
|
||||
url = 'http://%s/xbmcCmds/xbmcHttp/?%s' % (host, urllib.urlencode(command))
|
||||
|
||||
try:
|
||||
req = urllib2.Request(url)
|
||||
if self.password:
|
||||
authHeader = "Basic %s" % base64.encodestring('%s:%s' % (self.conf('username'), self.conf('password')))[:-1]
|
||||
req.add_header("Authorization", authHeader)
|
||||
headers = {}
|
||||
if self.password:
|
||||
headers = {
|
||||
'Authorization': "Basic %s" % base64.encodestring('%s:%s' % (self.conf('username'), self.conf('password')))[:-1]
|
||||
}
|
||||
|
||||
urllib2.urlopen(req, timeout = 10).read()
|
||||
except Exception, e:
|
||||
log.error("Couldn't sent command to XBMC. %s" % e)
|
||||
if not self.urlopen(url, headers = headers):
|
||||
log.error("Couldn't sent command to XBMC")
|
||||
return False
|
||||
|
||||
log.info('XBMC notification to %s successful.' % host)
|
||||
|
||||
Reference in New Issue
Block a user