本文整理匯總了Python中whatpotato.environment.Env.setting方法的典型用法代碼示例。如果您正苦於以下問題:Python Env.setting方法的具體用法?Python Env.setting怎麽用?Python Env.setting使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類whatpotato.environment.Env
的用法示例。
在下文中一共展示了Env.setting方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: createBaseUrl
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def createBaseUrl(self):
host = Env.setting('host')
if host == '0.0.0.0' or host == '':
host = 'localhost'
port = Env.setting('port')
ssl = Env.setting('ssl_cert') and Env.setting('ssl_key')
return '%s:%d%s' % (cleanHost(host, ssl = ssl).rstrip('/'), int(port), Env.get('web_base'))
示例2: get_current_user
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def get_current_user(self):
username = Env.setting('username')
password = Env.setting('password')
if username and password:
return self.get_secure_cookie('user')
else: # Login when no username or password are set
return True
示例3: calculate
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def calculate(self, nzb, movie):
""" Calculate the score of a NZB, used for sorting later """
# Merge global and category
preferred_words = splitString(Env.setting('preferred_words', section = 'searcher').lower())
try: preferred_words = removeDuplicate(preferred_words + splitString(movie['category']['preferred'].lower()))
except: pass
score = nameScore(toUnicode(nzb['name']), movie['info']['year'], preferred_words)
for movie_title in movie['info']['titles']:
score += nameRatioScore(toUnicode(nzb['name']), toUnicode(movie_title))
score += namePositionScore(toUnicode(nzb['name']), toUnicode(movie_title))
score += sizeScore(nzb['size'])
# Torrents only
if nzb.get('seeders'):
try:
score += nzb.get('seeders') * 100 / 15
score += nzb.get('leechers') * 100 / 30
except:
pass
# Provider score
score += providerScore(nzb['provider'])
# Duplicates in name
score += duplicateScore(nzb['name'], getTitle(movie))
# Merge global and category
ignored_words = splitString(Env.setting('ignored_words', section = 'searcher').lower())
try: ignored_words = removeDuplicate(ignored_words + splitString(movie['category']['ignored'].lower()))
except: pass
# Partial ignored words
score += partialIgnoredScore(nzb['name'], getTitle(movie), ignored_words)
# Ignore single downloads from multipart
score += halfMultipartScore(nzb['name'])
# Extra provider specific check
extra_score = nzb.get('extra_score')
if extra_score:
score += extra_score(nzb)
# Scene / Nuke scoring
score += sceneScore(nzb['name'])
return score
示例4: post
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def post(self, *args, **kwargs):
api_key = None
username = Env.setting('username')
password = Env.setting('password')
if (self.get_argument('username') == username or not username) and (md5(self.get_argument('password')) == password or not password):
api_key = Env.setting('api_key')
if api_key:
remember_me = tryInt(self.get_argument('remember_me', default = 0))
self.set_secure_cookie('user', api_key, expires_days = 30 if remember_me > 0 else None)
self.redirect(Env.get('web_base'))
示例5: getRequestHeaders
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def getRequestHeaders(self):
return {
'X-CP-Version': fireEvent('app.version', single = True),
'X-CP-API': self.api_version,
'X-CP-Time': time.time(),
'X-CP-Identifier': '+%s' % Env.setting('api_key', 'core')[:10], # Use first 10 as identifier, so we don't need to use IP address in api stats
}
示例6: get
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def get(self, *args, **kwargs):
api_key = None
try:
username = Env.setting('username')
password = Env.setting('password')
if (self.get_argument('u') == md5(username) or not username) and (self.get_argument('p') == password or not password):
api_key = Env.setting('api_key')
self.write({
'success': api_key is not None,
'api_key': api_key
})
except:
log.error('Failed doing key request: %s', (traceback.format_exc()))
self.write({'success': False, 'error': 'Failed returning results'})
示例7: providerScore
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def providerScore(provider):
try:
score = tryInt(Env.setting('extra_score', section = provider.lower(), default = 0))
except:
score = 0
return score
示例8: fillResult
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def fillResult(self, result):
defaults = {
'id': 0,
'protocol': self.provider.protocol,
'type': self.provider.type,
'provider': self.provider.getName(),
'download': self.provider.loginDownload if self.provider.urls.get('login') else self.provider.download,
'seed_ratio': Env.setting('seed_ratio', section = self.provider.getName().lower(), default = ''),
'seed_time': Env.setting('seed_time', section = self.provider.getName().lower(), default = ''),
'url': '',
'name': '',
'age': 0,
'size': 0,
'description': '',
'score': 0
}
return mergeDicts(defaults, result)
示例9: launchBrowser
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def launchBrowser(self):
if Env.setting('launch_browser'):
log.info('Launching browser')
url = self.createBaseUrl()
try:
webbrowser.open(url, 2, 1)
except:
try:
webbrowser.open(url, 1, 1)
except:
log.error('Could not launch a browser.')
示例10: tryDownloadResult
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def tryDownloadResult(self, results, media, quality_custom):
wait_for = False
let_through = False
filtered_results = []
minimum_seeders = tryInt(Env.setting('minimum_seeders', section = 'torrent', default = 1))
# Filter out ignored and other releases we don't want
for rel in results:
if rel['status'] in ['ignored', 'failed']:
log.info('Ignored: %s', rel['name'])
continue
if rel['score'] < quality_custom.get('minimum_score'):
log.info('Ignored, score "%s" to low, need at least "%s": %s', (rel['score'], quality_custom.get('minimum_score'), rel['name']))
continue
if rel['size'] <= 50:
log.info('Ignored, size "%sMB" to low: %s', (rel['size'], rel['name']))
continue
if 'seeders' in rel and rel.get('seeders') < minimum_seeders:
log.info('Ignored, not enough seeders, has %s needs %s: %s', (rel.get('seeders'), minimum_seeders, rel['name']))
continue
# If a single release comes through the "wait for", let through all
rel['wait_for'] = False
if quality_custom.get('index') != 0 and quality_custom.get('wait_for', 0) > 0 and rel.get('age') <= quality_custom.get('wait_for', 0):
rel['wait_for'] = True
else:
let_through = True
filtered_results.append(rel)
# Loop through filtered results
for rel in filtered_results:
# Only wait if not a single release is old enough
if rel.get('wait_for') and not let_through:
log.info('Ignored, waiting %s days: %s', (quality_custom.get('wait_for') - rel.get('age'), rel['name']))
wait_for = True
continue
downloaded = fireEvent('release.download', data = rel, media = media, single = True)
if downloaded is True:
return True
elif downloaded != 'try_next':
break
return wait_for
示例11: cpTag
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def cpTag(self, media, unique_tag = False):
tag = ''
if Env.setting('enabled', 'renamer') or unique_tag:
identifier = getIdentifier(media) or ''
unique_tag = ', ' + randomString() if unique_tag else ''
tag = '.cp('
tag += identifier
tag += ', ' if unique_tag and identifier else ''
tag += randomString() if unique_tag else ''
tag += ')'
return tag if len(tag) > 7 else ''
示例12: buildUrl
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def buildUrl(self, media, quality):
query = tryUrlencode(
{
"q": getIdentifier(media),
"m": "n",
"max": 400,
"adv_age": Env.setting("retention", "nzb"),
"adv_sort": "date",
"adv_col": "on",
"adv_nfo": "on",
"minsize": quality.get("size_min"),
"maxsize": quality.get("size_max"),
}
)
return query
示例13: __init__
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def __init__(self):
desktop = Env.get('desktop')
desktop.setSettings({
'base_url': fireEvent('app.base_url', single = True),
'api_url': fireEvent('app.api_url', single = True),
'api': Env.setting('api'),
})
# Events from desktop
desktop.addEvents({
'onClose': self.onClose,
})
# Events to desktop
addEvent('app.after_shutdown', desktop.afterShutdown)
addEvent('app.load', desktop.onAppLoad, priority = 110)
示例14: get
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def get(self, random, route):
bookmarklet_host = Env.setting('bookmarklet_host')
loc = bookmarklet_host if bookmarklet_host else "{0}://{1}".format(self.request.protocol, self.request.headers.get('X-Forwarded-Host') or self.request.headers.get('host'))
params = {
'includes': fireEvent('userscript.get_includes', merge = True),
'excludes': fireEvent('userscript.get_excludes', merge = True),
'version': klass.getVersion(),
'api': '%suserscript/' % Env.get('api_base'),
'host': loc,
}
script = klass.renderTemplate(__file__, 'template.js_tmpl', **params)
klass.createFile(os.path.join(Env.get('cache_dir'), 'whatpotato.user.js'), script)
self.redirect(Env.get('api_base') + 'file.cache/whatpotato.user.js')
示例15: manifest
# 需要導入模塊: from whatpotato.environment import Env [as 別名]
# 或者: from whatpotato.environment.Env import setting [as 別名]
def manifest(handler):
web_base = Env.get('web_base')
static_base = Env.get('static_path')
lines = [
'CACHE MANIFEST',
'# %s theme' % ('dark' if Env.setting('dark_theme') else 'light'),
'',
'CACHE:',
''
]
if not Env.get('dev'):
# CSS
for url in fireEvent('clientscript.get_styles', single = True):
lines.append(web_base + url)
# Scripts
for url in fireEvent('clientscript.get_scripts', single = True):
lines.append(web_base + url)
# Favicon
lines.append(static_base + 'images/favicon.ico')
# Fonts
font_folder = sp(os.path.join(Env.get('app_dir'), 'whatpotato', 'static', 'fonts'))
for subfolder, dirs, files in os.walk(font_folder, topdown = False):
for file in files:
if '.woff' in file:
lines.append(static_base + 'fonts/' + file + ('?%s' % os.path.getmtime(os.path.join(font_folder, file))))
else:
lines.append('# Not caching anything in dev mode')
# End lines
lines.extend(['',
'NETWORK: ',
'*'])
handler.set_header('Content-Type', 'text/cache-manifest')
return '\n'.join(lines)