本文整理汇总了Python中sickbeard.helpers.getURL函数的典型用法代码示例。如果您正苦于以下问题:Python getURL函数的具体用法?Python getURL怎么用?Python getURL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getURL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getDBcompare
def getDBcompare(self):
"""
Compare the current DB version with the new branch version.
:return: 'upgrade', 'equal', or 'downgrade'
"""
try:
self.updater.need_update()
cur_hash = str(self.updater.get_newest_commit_hash())
assert len(cur_hash) == 40, 'Commit hash wrong length: {length} hash: {hash}'.format(
length=len(cur_hash), hash=cur_hash)
check_url = 'http://cdn.rawgit.com/{org}/{repo}/{commit}/sickbeard/databases/main_db.py'.format(
org=sickbeard.GIT_ORG, repo=sickbeard.GIT_REPO, commit=cur_hash)
response = helpers.getURL(check_url, session=self.session)
if response.status_code == 404:
check_url.replace('main_db.py', 'mainDB.py')
response = helpers.getURL(check_url, session=self.session)
match = re.search(r'MAX_DB_VERSION\s=\s(?P<version>\d{2,3})', response.text)
new_branch_db_version = int(match.group('version'))
main_db_con = db.DBConnection()
cur_branch_db_version = main_db_con.checkDBVersion()
if new_branch_db_version > cur_branch_db_version:
return 'upgrade'
elif new_branch_db_version == cur_branch_db_version:
return 'equal'
else:
return 'downgrade'
except Exception as e:
return repr(e)
示例2: get_url
def get_url(self, url, post_data=None, params=None, timeout=30, json=False, need_bytes=False): # pylint: disable=too-many-arguments
"""
need_bytes=True when trying access to torrent info (For calling torrent client). Previously we must parse
the URL to get torrent file
"""
if need_bytes:
data = helpers.getURL(url, headers=self.headers, timeout=timeout, session=self.session, returns='json')
url = re.search(r'http://tumejorserie.com/descargar/.+\.torrent', data, re.DOTALL).group()
return helpers.getURL(url, post_data=post_data, params=params, headers=self.headers, timeout=timeout,
session=self.session, json=json, need_bytes=need_bytes)
示例3: sendNZB
def sendNZB(nzb): # pylint:disable=too-many-return-statements, too-many-branches, too-many-statements
'''
Sends an NZB to SABnzbd via the API.
:param nzb: The NZBSearchResult object to send to SAB
'''
category = sickbeard.SAB_CATEGORY
if nzb.show.is_anime:
category = sickbeard.SAB_CATEGORY_ANIME
# if it aired more than 7 days ago, override with the backlog category IDs
for curEp in nzb.episodes:
if datetime.date.today() - curEp.airdate > datetime.timedelta(days=7):
category = sickbeard.SAB_CATEGORY_ANIME_BACKLOG if nzb.show.is_anime else sickbeard.SAB_CATEGORY_BACKLOG
# set up a dict with the URL params in it
params = {'output': 'json'}
if sickbeard.SAB_USERNAME is not None:
params['ma_username'] = sickbeard.SAB_USERNAME
if sickbeard.SAB_PASSWORD is not None:
params['ma_password'] = sickbeard.SAB_PASSWORD
if sickbeard.SAB_APIKEY is not None:
params['apikey'] = sickbeard.SAB_APIKEY
if category is not None:
params['cat'] = category
if nzb.priority:
params['priority'] = 2 if sickbeard.SAB_FORCED else 1
if nzb.resultType == 'nzb':
params['mode'] = 'addurl'
params['name'] = nzb.url
elif nzb.resultType == 'nzbdata':
params['mode'] = 'addfile'
multiPartParams = {'nzbfile': (nzb.name + '.nzb', nzb.extraInfo[0])}
logger.log('Sending NZB to SABnzbd')
url = urljoin(sickbeard.SAB_HOST, 'api')
if nzb.resultType == 'nzb':
jdata = helpers.getURL(url, params=params, session=session, returns='json', headers={'User-Agent': USER_AGENT})
elif nzb.resultType == 'nzbdata':
jdata = helpers.getURL(url, file=multiPartParams, session=session, returns='json', headers={'User-Agent': USER_AGENT})
if not jdata:
logger.log('Error connecting to sab, no data returned')
return False
logger.log('Result text from SAB: {0}'.format(jdata), logger.DEBUG)
result, _ = _checkSabResponse(jdata)
return result
示例4: sendNZB
def sendNZB(nzb): # pylint:disable=too-many-return-statements, too-many-branches, too-many-statements
"""
Sends an NZB to SABnzbd via the API.
:param nzb: The NZBSearchResult object to send to SAB
"""
category = sickbeard.SAB_CATEGORY
if nzb.show.is_anime:
category = sickbeard.SAB_CATEGORY_ANIME
# if it aired more than 7 days ago, override with the backlog category IDs
for curEp in nzb.episodes:
if datetime.date.today() - curEp.airdate > datetime.timedelta(days=7):
category = sickbeard.SAB_CATEGORY_ANIME_BACKLOG if nzb.show.is_anime else sickbeard.SAB_CATEGORY_BACKLOG
# set up a dict with the URL params in it
params = {"output": "json"}
if sickbeard.SAB_USERNAME:
params["ma_username"] = sickbeard.SAB_USERNAME
if sickbeard.SAB_PASSWORD:
params["ma_password"] = sickbeard.SAB_PASSWORD
if sickbeard.SAB_APIKEY:
params["apikey"] = sickbeard.SAB_APIKEY
if category:
params["cat"] = category
if nzb.priority:
params["priority"] = 2 if sickbeard.SAB_FORCED else 1
logger.log("Sending NZB to SABnzbd")
url = urljoin(sickbeard.SAB_HOST, "api")
if nzb.resultType == "nzb":
params["mode"] = "addurl"
params["name"] = nzb.url
jdata = helpers.getURL(url, params=params, session=session, returns="json", verify=False)
elif nzb.resultType == "nzbdata":
params["mode"] = "addfile"
multiPartParams = {"nzbfile": (nzb.name + ".nzb", nzb.extraInfo[0])}
jdata = helpers.getURL(url, params=params, file=multiPartParams, session=session, returns="json", verify=False)
if not jdata:
logger.log("Error connecting to sab, no data returned")
return False
logger.log("Result text from SAB: {0}".format(jdata), logger.DEBUG)
result, error_ = _checkSabResponse(jdata)
return result
示例5: _do_login
def _do_login(self):
logged_in = lambda: 'gft_uid' in self.session.cookies and 'gft_pass' in self.session.cookies
if logged_in():
return True
if self._check_auth():
helpers.getURL(self.urls['login_get'], session=self.session)
login_params = {'username': self.username, 'password': self.password}
response = helpers.getURL(self.urls['login_post'], post_data=login_params, session=self.session)
if response and logged_in():
return True
logger.log(u'Failed to authenticate with %s, abort provider.' % self.name, logger.ERROR)
return False
示例6: _getTVRageInfo
def _getTVRageInfo(self, season=None, episode=None, full=False):
url = "http://services.tvrage.com/tools/quickinfo.php?"
# if we need full info OR if we don't have a tvrage id, use show name
if full == True or self.show.tvrid == 0:
if self.show.tvrname != "" and self.show.tvrname != None:
showName = self.show.tvrname
else:
showName = self.show.name
urlData = {'show': showName.encode('utf-8')}
# if we don't need full info and we have a tvrage id, use it
else:
urlData = {'sid': self.show.tvrid}
if season != None and episode != None:
urlData['ep'] = str(season)+'x'+str(episode)
# build the URL
url += urllib.urlencode(urlData)
logger.log(u"Loading TVRage info from URL: " + url, logger.DEBUG)
try:
result = helpers.getURL(url).decode('utf-8')
except (urllib2.HTTPError, IOError), e:
logger.log(u"Unable to load TVRage info: " + e.message.decode(sickbeard.SYS_ENCODING))
raise exceptions.TVRageException("urlopen call to " + url + " failed")
示例7: _sabURLOpenSimple
def _sabURLOpenSimple(url):
try:
result = helpers.getURL(url, throw_exc=True)
f = StringIO.StringIO(result)
except (EOFError, IOError), e:
logger.log(u"Unable to connect to SAB: " + ex(e), logger.ERROR)
return False, "Unable to connect"
示例8: _xem_exceptions_fetcher
def _xem_exceptions_fetcher():
if shouldRefresh('xem'):
for indexer in sickbeard.indexerApi().indexers:
logger.log(u'Checking for XEM scene exception updates for {0}'.format
(sickbeard.indexerApi(indexer).name))
url = 'http://thexem.de/map/allNames?origin={0}&seasonNumbers=1'.format(sickbeard.indexerApi(indexer).config['xem_origin'])
parsedJSON = helpers.getURL(url, session=xem_session, timeout=90, returns='json')
if not parsedJSON:
logger.log(u'Check scene exceptions update failed for {0}, Unable to get URL: {1}'.format
(sickbeard.indexerApi(indexer).name, url), logger.DEBUG)
continue
if parsedJSON['result'] == 'failure':
continue
if not parsedJSON['data']:
logger.log(u'No data returned from XEM when checking scene exceptions. Update failed for {0}'.format
(sickbeard.indexerApi(indexer).name), logger.DEBUG)
continue
for indexerid, names in iteritems(parsedJSON['data']):
try:
xem_exception_dict[int(indexerid)] = names
except Exception as error:
logger.log(u'XEM: Rejected entry: indexerid:{0}; names:{1}'.format(indexerid, names), logger.WARNING)
logger.log(u'XEM: Rejected entry error message:{0}'.format(error), logger.DEBUG)
setLastRefresh('xem')
return xem_exception_dict
示例9: getDBcompare
def getDBcompare(self):
try:
self.updater.need_update()
cur_hash = str(self.updater.get_newest_commit_hash())
assert len(cur_hash) == 40, "Commit hash wrong length: %s hash: %s" % (len(cur_hash), cur_hash)
check_url = "http://cdn.rawgit.com/%s/%s/%s/sickbeard/databases/mainDB.py" % (
sickbeard.GIT_ORG,
sickbeard.GIT_REPO,
cur_hash,
)
response = helpers.getURL(check_url, session=self.session)
assert response, "Empty response from %s" % check_url
match = re.search(r"MAX_DB_VERSION\s=\s(?P<version>\d{2,3})", response)
branchDestDBversion = int(match.group("version"))
main_db_con = db.DBConnection()
branchCurrDBversion = main_db_con.checkDBVersion()
if branchDestDBversion > branchCurrDBversion:
return "upgrade"
elif branchDestDBversion == branchCurrDBversion:
return "equal"
else:
return "downgrade"
except Exception as e:
return repr(e)
示例10: getURL
def getURL(self, url, post_data=None, params=None, timeout=30, json=False):
"""
By default this is just a simple urlopen call but this method should be overridden
for providers with special URL requirements (like cookies)
"""
# check for auth
if not self._doLogin():
return
if self.proxy.isEnabled():
self.headers.update({"Referer": self.proxy.getProxyURL()})
self.proxyGlypeProxySSLwarning = (
self.proxy.getProxyURL() + "includes/process.php?action=sslagree&submit=Continue anyway..."
)
else:
if "Referer" in self.headers:
self.headers.pop("Referer")
self.proxyGlypeProxySSLwarning = None
return helpers.getURL(
self.proxy._buildURL(url),
post_data=post_data,
params=params,
headers=self.headers,
timeout=timeout,
session=self.session,
json=json,
proxyGlypeProxySSLwarning=self.proxyGlypeProxySSLwarning,
)
示例11: _xem_exceptions_fetcher
def _xem_exceptions_fetcher():
global xem_exception_dict
xem_list = 'xem_us'
for show in sickbeard.showList:
if show.is_anime and not show.paused:
xem_list = 'xem'
break
if shouldRefresh(xem_list):
for indexer in [i for i in sickbeard.indexerApi().indexers if 'xem_origin' in sickbeard.indexerApi(i).config]:
logger.log(u'Checking for XEM scene exception updates for %s' % sickbeard.indexerApi(indexer).name)
url = 'http://thexem.de/map/allNames?origin=%s%s&seasonNumbers=1'\
% (sickbeard.indexerApi(indexer).config['xem_origin'], ('&language=us', '')['xem' == xem_list])
parsed_json = helpers.getURL(url, json=True, timeout=90)
if not parsed_json:
logger.log(u'Check scene exceptions update failed for %s, Unable to get URL: %s'
% (sickbeard.indexerApi(indexer).name, url), logger.ERROR)
continue
if 'failure' == parsed_json['result']:
continue
for indexerid, names in parsed_json['data'].items():
try:
xem_exception_dict[int(indexerid)] = names
except:
continue
setLastRefresh(xem_list)
return xem_exception_dict
示例12: check_for_new_news
def check_for_new_news(self, force=False):
"""
Checks GitHub for the latest news.
returns: str, a copy of the news
force: if true the VERSION_NOTIFY setting will be ignored and a check will be forced
"""
if not self.updater or not sickbeard.VERSION_NOTIFY and not sickbeard.AUTO_UPDATE and not force:
logger.log(u"check_for_new_news: Version checking is disabled, not checking for latest news")
return ''
# Grab a copy of the news
logger.log(u'check_for_new_news: Checking GitHub for latest news.', logger.DEBUG)
try:
news = helpers.getURL(sickbeard.NEWS_URL, session=requests.Session())
except Exception:
logger.log(u'check_for_new_news: Could not load news from repo.', logger.WARNING)
last_read = time.mktime(time.strptime(sickbeard.NEWS_LAST_READ, '%Y-%m-%d'))
dates= re.finditer(r'^####(\d{4}-\d{2}-\d{2})####$', news, re.M)
sickbeard.NEWS_UNREAD = 0
gotLatest = False
for match in dates:
if not gotLatest:
gotLatest = True
sickbeard.NEWS_LATEST = match.group(1)
if time.mktime(time.strptime(match.group(1), '%Y-%m-%d')) > last_read:
sickbeard.NEWS_UNREAD += 1
return news
示例13: testAuthentication
def testAuthentication(host=None, username=None, password=None, apikey=None):
"""
Sends a simple API request to SAB to determine if the given connection information is connect
:param host: The host where SAB is running (incl port)
:param username: The username to use for the HTTP request
:param password: The password to use for the HTTP request
:param apikey: The API key to provide to SAB
:return: A tuple containing the success boolean and a message
"""
# build up the URL parameters
params = {"mode": "queue", "output": "json", "ma_username": username, "ma_password": password, "apikey": apikey}
url = urljoin(host, "api")
data = helpers.getURL(url, params=params, session=session, returns="json", verify=False)
if not data:
return False, data
# check the result and determine if it's good or not
result, sabText = _checkSabResponse(data)
if not result:
return False, sabText
return True, "Success"
示例14: get_url_x
def get_url_x(self, url, token=None, **kwargs):
if not token:
token = self.token
if not url.startswith('http'):
url = 'http://' + url
for x in range(0, 3):
if 0 < x:
sleep(0.5)
try:
headers = {'X-Plex-Device-Name': 'SickGear',
'X-Plex-Platform': platform.system(), 'X-Plex-Device': platform.system(),
'X-Plex-Platform-Version': platform.release(),
'X-Plex-Provides': 'controller', 'X-Plex-Product': 'Python',
'X-Plex-Client-Identifier': self.client_id,
'X-Plex-Version': str(self.config_version),
'X-Plex-Token': token,
'Accept': 'application/xml'
}
if self.username:
headers.update({'X-Plex-Username': self.username})
page = getURL(url, headers=headers, **kwargs)
if page:
parsed = etree.fromstring(page)
if None is not parsed and len(parsed):
return parsed
return None
except Exception as e:
self.log('Error requesting page: %s' % e)
continue
return None
示例15: get_feed
def get_feed(self, url, request_headers=None):
if not self._check_auth_cookie():
return
session = None
if self.provider and hasattr(self.provider, 'session'):
session = self.provider.session
response = helpers.getURL(url, headers=request_headers, session=session)
if not response:
return
try:
feed = feedparser.parse(response)
if feed and 'entries' in feed:
return feed
if feed and 'error' in feed.feed:
err_code = feed.feed['error']['code']
err_desc = feed.feed['error']['description']
logger.log(u'RSS ERROR:[%s] CODE:[%s]' % (err_desc, err_code), logger.DEBUG)
else:
logger.log(u'RSS error loading url: ' + url, logger.DEBUG)
except Exception as e:
logger.log(u'RSS error: ' + ex(e), logger.DEBUG)