本文整理汇总了Python中settings.settings方法的典型用法代码示例。如果您正苦于以下问题:Python settings.settings方法的具体用法?Python settings.settings怎么用?Python settings.settings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类settings
的用法示例。
在下文中一共展示了settings.settings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_window
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def init_window(self):
self.centralWidget = QtWidgets.QWidget(self)
self.setCentralWidget(self.centralWidget)
self.setWindowTitle('Snake AI')
self.setGeometry(self.top, self.left, self.width, self.height)
# Create the Neural Network window
self.nn_viz_window = NeuralNetworkViz(self.centralWidget, self.snake)
self.nn_viz_window.setGeometry(QtCore.QRect(0, 0, 600, self._snake_widget_height + self.border[1] + self.border[3] + 200))
self.nn_viz_window.setObjectName('nn_viz_window')
# Create SnakeWidget window
self.snake_widget_window = SnakeWidget(self.centralWidget, self.board_size, self.snake)
self.snake_widget_window.setGeometry(QtCore.QRect(600 + self.border[0], self.border[1], self.snake_widget_width, self.snake_widget_height))
self.snake_widget_window.setObjectName('snake_widget_window')
# Genetic Algorithm Stats window
self.ga_window = GeneticAlgoWidget(self.centralWidget, self.settings)
self.ga_window.setGeometry(QtCore.QRect(600, self.border[1] + self.border[3] + self.snake_widget_height, self._snake_widget_width + self.border[0] + self.border[2] + 100, 200-10))
self.ga_window.setObjectName('ga_window')
示例2: getRandomImage
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def getRandomImage(filteredImagesCache=None, randomImageFilter=''):
if not savedImagesCache:
generateSavedImagesCache(settings.settings['Output_dir'])
if filteredImagesCache:
randomImage = random.choice(filteredImagesCache)
else:
randomImage = random.choice(savedImagesCache)
print('\tgetRandomImage(): Chose random image {} (filter {})'.format(randomImage, randomImageFilter))
serverPath = utilities.outputPathToServerPath(randomImage)
return randomImage, serverPath
#
# Tornado handlers
#
# See https://github.com/tornadoweb/tornado/blob/stable/demos/blog/blog.py
# https://www.tornadoweb.org/en/stable/guide/security.html
示例3: open
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def open(self):
global userSessionData
currentUser = login_get_current_user(self)
if not currentUser:
# Failed authorization
return None
self.connections.add(self)
if currentUser not in userSessionData:
newSessionData = SessionData()
userSessionData[currentUser] = newSessionData
self.sessionData = userSessionData[currentUser]
self.sessionData.acquire()
# Set up the directory cache with the top-level output
self.changeCurrentDirectory(settings.settings['Output_dir'])
self.sessionData.release()
示例4: shouldUseYoutubeDl
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def shouldUseYoutubeDl(url):
for siteMask in youtubeDlSitesSupported:
if siteMask in url:
isBlacklisted = False
for blacklistSite in youtubeDlBlacklistSites:
if blacklistSite in url:
isBlacklisted = True
break
# Use the gfycat api for these, if available
# Ever since the creation of RedGifs, use YoutubeDL for all gfycat links...
# if settings.settings['Gfycat_Client_id'] and 'gfycat.com' in url:
# isBlacklisted = True
if isBlacklisted:
# We probably have another downloader
return False
# YoutubeDL should support this site
return True
return False
# Returns (success or failure, output file or failure message)
示例5: create_redis_pool
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def create_redis_pool():
redis_configs = settings[const.REDIS_CONFIG_ITEM][const.DEFAULT_RD_KEY]
pool = redis.ConnectionPool(host=redis_configs['host'], port=redis_configs['port'],
password=redis_configs['password'], db=redis_configs[const.RD_DB_KEY],
decode_responses=True)
return pool
示例6: __init__
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def __init__(self):
tornado.web.Application.__init__(self, url_patterns, **settings)
示例7: _mutation
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def _mutation(self, child1_weights: np.ndarray, child2_weights: np.ndarray,
child1_bias: np.ndarray, child2_bias: np.ndarray) -> None:
scale = .2
rand_mutation = random.random()
mutation_bucket = np.digitize(rand_mutation, self._mutation_bins)
mutation_rate = self._mutation_rate
if self.settings['mutation_rate_type'].lower() == 'decaying':
mutation_rate = mutation_rate / sqrt(self.current_generation + 1)
# Gaussian
if mutation_bucket == 0:
# Mutate weights
gaussian_mutation(child1_weights, mutation_rate, scale=scale)
gaussian_mutation(child2_weights, mutation_rate, scale=scale)
# Mutate bias
gaussian_mutation(child1_bias, mutation_rate, scale=scale)
gaussian_mutation(child2_bias, mutation_rate, scale=scale)
# Uniform random
elif mutation_bucket == 1:
# Mutate weights
random_uniform_mutation(child1_weights, mutation_rate, -1, 1)
random_uniform_mutation(child2_weights, mutation_rate, -1, 1)
# Mutate bias
random_uniform_mutation(child1_bias, mutation_rate, -1, 1)
random_uniform_mutation(child2_bias, mutation_rate, -1, 1)
else:
raise Exception('Unable to determine valid mutation based off probabilities.')
示例8: AddAllFromReddit
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def AddAllFromReddit(database, settings):
if not settings.hasRedditSettings():
logger.log('Reddit settings are not provided!')
return
submissions = []
logger.log('Adding last 1000 liked/saved submissions from Reddit. This will take a long time.')
redditSubmissions, redditComments, earlyOutPoints = redditScraper.getRedditUserLikedSavedSubmissions(
settings.settings['Username'], settings.settings['Password'],
settings.settings['Client_id'], settings.settings['Client_secret'],
request_limit = None, # No limit = request as many as possible (1000)
saveLiked = settings.settings['Reddit_Save_Liked'],
saveSaved = settings.settings['Reddit_Save_Saved'],
earlyOutPointSaved = None,
earlyOutPointLiked = None,
unlikeLiked = False,
unsaveSaved = False)
logger.log('Retrieved submissions, adding to database...')
for submission in redditSubmissions:
database.addSubmission(submission)
for comment in redditComments:
database.addComment(comment)
logger.log('Done! Saved {} submissions and {} comments'.format(len(redditSubmissions), len(redditComments)))
示例9: initialize
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def initialize():
settings.getSettings()
if not settings.settings['Database']:
logger.log('Please provide a location for the Database')
return
# Do this early so we can use it anywhere
LikedSavedDatabase.initializeFromSettings(settings.settings)
示例10: saveRequestedSubmissions
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def saveRequestedSubmissions(pipeConnection, submissionIds):
if pipeConnection:
logger.setPipe(pipeConnection)
initialize()
logger.log('Attempting to save {} requested submissions. This will take several minutes...'
.format(len(submissionIds)))
dbSubmissions = LikedSavedDatabase.db.getSubmissionsByIds(submissionIds)
submissions = []
# Convert from database submissions to Submission
for dbSubmission in dbSubmissions:
convertedSubmission = submission.Submission()
convertedSubmission.initFromDict(dbSubmission)
submissions.append(convertedSubmission)
if len(submissions) != len(submissionIds):
logger.log('Could not find {} submissions in database!'.format(len(submissionIds) - len(submissions)))
unsupportedSubmissions = imageSaver.saveAllImages(settings.settings['Output_dir'], submissions,
imgur_auth = imgurDownloader.getImgurAuth(),
only_download_albums = settings.settings['Only_download_albums'],
skip_n_percent_submissions = settings.settings['Skip_n_percent_submissions'],
soft_retrieve_imgs = settings.settings['Should_soft_retrieve'],
only_important_messages = settings.settings['Only_important_messages'])
logger.log('Download finished. Please refresh the page to see updated entries')
if pipeConnection:
logger.log(scriptFinishedSentinel)
pipeConnection.close()
示例11: saveRequestedUrls
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def saveRequestedUrls(pipeConnection, urls):
if pipeConnection:
logger.setPipe(pipeConnection)
initialize()
logger.log('Attempting to save {} requested urls. This may take several minutes...'
.format(len(urls)))
submissions = []
# Create Submission for each URL
for url in urls:
convertedSubmission = submission.Submission()
convertedSubmission.source = "UserRequested"
convertedSubmission.title = "UserRequested"
convertedSubmission.author = "(Requested by user)"
convertedSubmission.subreddit = "Requested_Downloads"
convertedSubmission.subredditTitle = "Requested Downloads"
convertedSubmission.body = "(Requested by user)"
convertedSubmission.bodyUrl= url
convertedSubmission.postUrl= url
submissions.append(convertedSubmission)
if len(submissions) != len(urls):
logger.log('Could not parse {} URLs!'.format(len(urls) - len(submissions)))
unsupportedSubmissions = imageSaver.saveAllImages(settings.settings['Output_dir'], submissions,
imgur_auth = imgurDownloader.getImgurAuth(),
only_download_albums = settings.settings['Only_download_albums'],
skip_n_percent_submissions = settings.settings['Skip_n_percent_submissions'],
soft_retrieve_imgs = settings.settings['Should_soft_retrieve'],
only_important_messages = settings.settings['Only_important_messages'])
logger.log('Download finished. Output to \'Requested Downloads\' directory')
if pipeConnection:
logger.log(scriptFinishedSentinel)
pipeConnection.close()
示例12: getImgurAuth
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def getImgurAuth():
imgurAuth = None
if settings.hasImgurSettings():
return ImgurAuth(settings.settings['Imgur_client_id'],
settings.settings['Imgur_client_secret'])
else:
logger.log('No Imgur Client ID and/or Imgur Client Secret was provided, or album download is not'
' enabled. This is required to download imgur albums. They will be ignored. Check'
' settings.txt for how to fill in these values.')
return None
示例13: settingsToHtmlForm
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def settingsToHtmlForm():
settingsInputs = []
for sectionSettingsPair in settings.settingsStructure:
settingsInputs.append('<h2>{}</h2>'.format(sectionSettingsPair[0]))
for sectionOption in sectionSettingsPair[1]:
option = None
optionComment = ''
if type(sectionOption) == tuple:
option = sectionOption[0]
optionComment = '<p class="optionComment">{}</p>'.format(sectionOption[1])
else:
option = sectionOption
if type(settings.settings[option]) == bool:
settingsInputs.append('''<input type="checkbox" id="{option}" name="{option}" value="{optionValue}" {checkedState} />
<label for="{option}">{optionName}</label>{comment}
<br />'''
.format(option=option, optionName=option.replace('_', ' '),
comment=optionComment,
checkedState=('checked' if settings.settings[option] else ''),
optionValue=('1' if settings.settings[option] else '0')))
elif type(settings.settings[option]) == int:
settingsInputs.append('''<label for="{option}">{optionName}</label>
<input type="number" id="{option}" name="{option}" value="{optionValue}" />{comment}
<br />'''
.format(option=option, optionName=option.replace('_', ' '), comment=optionComment,
optionValue=settings.settings[option]))
elif type(settings.settings[option]) == str:
settingsInputs.append('''<label for="{option}">{optionName}</label>
<input type="{type}" id="{option}" name="{option}" value="{optionValue}" />{comment}
<br />'''
.format(option=option, optionName=option.replace('_', ' '),
comment=optionComment, optionValue=settings.settings[option],
type=('password' if 'secret' in option.lower() or 'password' in option.lower() else 'text')))
return ''.join(settingsInputs)
示例14: doSettings
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def doSettings(self, afterSubmit):
htmlSettingsForm = settingsToHtmlForm()
settingsFilename = settings.getSettingsFilename()
self.render("templates/Settings.html",
status_html=('<p><b>Settings updated</b></p>' if afterSubmit else ''),
settings_filename=settingsFilename,
settings_form_html=htmlSettingsForm,
xsrf_form_html=self.xsrf_form_html())
示例15: make_app
# 需要导入模块: import settings [as 别名]
# 或者: from settings import settings [as 别名]
def make_app():
# Each time the server starts up, invalidate all cookies
randomGenerator = random.SystemRandom()
cookieSecret = str(randomGenerator.getrandbits(128))
return tornado.web.Application([
# Home page
(r'/', HomeHandler),
# Login
(r'/login', LoginHandler),
(r'/logout', LogoutHandler),
(r'/setPassword', SetPasswordHandler),
# Configure the script
(r'/settings', SettingsHandler),
# Handles messages for run script
(r'/runScriptWebSocket', RunScriptWebSocket),
# Handles messages for randomImageBrowser
(r'/randomImageBrowserWebSocket', RandomImageBrowserWebSocket),
(r'/unsupportedSubmissions', UnsupportedSubmissionsHandler),
#
# Static files
#
(r'/webInterface/(.*)', AuthedStaticHandler, {'path' : 'webInterface'}),
# Don't change this "output" here without changing the other places as well
(r'/output/(.*)', AuthedStaticHandler, {'path' : settings.settings['Output_dir']}),
# Files served regardless of whether the user is authenticated. Only login page resources
# should be in this folder, because anyone can see them
(r'/webInterfaceNoAuth/(.*)', tornado.web.StaticFileHandler, {'path' : 'webInterfaceNoAuth'}),
],
xsrf_cookies=True,
cookie_secret=cookieSecret,
login_url="/login")