本文整理汇总了Python中config.LOGGER类的典型用法代码示例。如果您正苦于以下问题:Python LOGGER类的具体用法?Python LOGGER怎么用?Python LOGGER使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LOGGER类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_itunes_track_data
def get_itunes_track_data(self, track_path, itunes_keys):
# TODO: iTunes uses HTML encoding for some things (ampersands) and URL encoding for the rest
with open('/Users/carmstrong/Music/iTunes/iTunes Music Library.xml', 'rb') as itunes_xml:
tree = etree.parse(itunes_xml)
itunes_track_path = 'file://' + urllib.quote(track_path.encode('utf-8'), safe="/(),'")
location_node = tree.xpath('//string[text()="{}"]'.format(itunes_track_path))
if not location_node:
LOGGER.info('{} not found in iTunes XML file.'.format(itunes_track_path))
return
results = {}
for itunes_key in itunes_keys:
try:
itunes_value = location_node[0].xpath("../key[text()='{}']".format(itunes_key))[0].getnext().text
try:
itunes_value = int(itunes_value)
except (ValueError, TypeError):
continue
results.update({itunes_key: itunes_value})
except IndexError:
continue
return results
示例2: feature_decomposition
def feature_decomposition(transformer, train_features, test_features):
LOGGER.info("Beginning Dimensionality reduction using truncated SVD (%d features)" % transformer.n_components)
train_dfeatures = transformer.fit_transform(train_features)
#LOGGER.debug(["%6f " % transformer.explained_variance_ratio_[i] for i in range(5)])
LOGGER.debug("%0.4f%% of total variance in %d features\n" % (
100 * transformer.explained_variance_ratio_.sum(), transformer.n_components))
return train_dfeatures, transformer.transform(test_features)
示例3: main
def main():
# get zip codes
zip_codes = [row.zip_code for row in session.query(ZipCode).all()]
# # add leading 0's to zip codes due to excel's stupidness
# zip_codes_df['zip_code'] = zip_codes_df['zip_code'].astype(str)
# zip_codes_df['zip_code'] = zip_codes_df['zip_code'].apply(lambda x: '0' * (5 - len(x)) + x)
current_month = datetime.date.today().month
current_rows = session.query(Indeed).filter(extract('month', Indeed.date_created) == current_month).all()
current_rows = [row.as_dict() for row in current_rows]
existing_zip_codes = [row['zip_code'] for row in current_rows]
remaining_zip_codes = [zip_code for zip_code in zip_codes if zip_code not in existing_zip_codes]
LOGGER.info('Found {} rows for current month: {}. Extracting {} remaining zip codes'.format(len(current_rows),
current_month,
len(
remaining_zip_codes)))
for i, zip_code in enumerate(remaining_zip_codes):
job_count = get_num_job_postings(zip_code)
row = Indeed(zip_code=zip_code, job_count=job_count, date_created=datetime.date.today())
session.merge(row)
session.commit()
LOGGER.info("Extracting zip code {} ({} of {})".format(zip_code, i, len(remaining_zip_codes)))
session.close()
示例4: run
def run(self):
while True:
try:
if not self.data_queue.empty():
data = self.data_queue.get()
if hasattr(data, 'target_statuses'):
for status in data.target_statuses:
exist = self.db['target_statuses'].find({'_id': status['_id']}).count()
if not exist:
self.db['target_statuses'].insert(status)
if hasattr(data, 'statuses'):
posts = []
for status in data.statuses:
exist = self.db.statuses.find({'_id': status['_id']}).count()
if not exist:
posts.append(status)
if len(posts):
self.db.statuses.insert(posts)
if hasattr(data, 'users'):
for user in data.users:
exist = self.db.users.find_one({'_id': user['_id']})
if not exist:
self.users.insert(user)
if hasattr(data, 'user'):
self.db.users.save(data.user)
else:
if self.stoped:
break
else:
time.sleep(0.5)
except Exception, e:
LOGGER.error(e)
continue
示例5: getUser
def getUser(email):
user = User.query.filter_by(email=email).first()
form = EditUserForm(g.user.email)
if user is None:
flash('Utilisateur %s introuvable' % email)
users = User.query.order_by('last_connection desc').all()
return render_template('getUsers.html', users=users, app_name=app_name)
else:
if form.validate_on_submit():
try:
g.user.firstname = form.firstname.data
g.user.email = form.email.data
g.user.timezone = form.timezone.data
if form.new_password.data != '':
g.user.set_password(form.new_password.data)
db.session.add(g.user)
db.session.commit()
flash(u'tes modifs\' sont bien enregistrées')
except:
db.session.rollback()
flash(u'ERREUR : impossible d\'enregistrer tes modifs !')
LOGGER.p_log(u'impossible d\'enregistrer les modifs', exception=exc_info())
else:
for errors in form.errors.values():
for error in errors:
flash(error)
print error
form.firstname.data = g.user.firstname
form.email.data = g.user.email
form.timezone.data = g.user.timezone
return render_template('getUser.html', app_name=app_name, user=user, form=form)
示例6: run
def run(self):
flag = True
try:
self.socket.connect((HOST ,PORT))
except error:
print 'connection failed'
return
print 'connected to server %s:%s' % (HOST, PORT)
while flag:
try:
if not self.controler.stoped:
if self.task == 'random':
uid, pages = self.request(action='getuid')
self.travel(uid=uid, pages=pages)
time.sleep(1)
elif self.task == 'target':
uid = self.request(action='gettargetuid')
self.target_travel(time.time()-24*60*60, uid=uid)
time.sleep(1)
else:
pass
else:
time.sleep(1)
except Exception, e:
LOGGER.error('Unhandled Error:%s' % e)
示例7: handle
def handle(fd, address):
global data_queue
global uid_queue
global target_uid_queue
db = getDB()
LOGGER.info('connection accepted from %s:%s' % address)
while True:
data = fd.readline()
if not data:
break
data = data[:-2]
r = json.loads(data, object_hook=_obj_hook)
if hasattr(r, 'action'):
action = r.action
else:
break
if action == 'postdata':
try:
data_queue.put(r.data)
fd.write(json.dumps({'status': 'ok'})+'\r\n')
except:
fd.write(json.dumps({'error': 'bad request data'})+'\r\n')
fd.flush()
elif action == 'getuid':
if not uid_queue.empty():
uid = uid_queue.get()
pages = 0
user = db.users.find_one({'_id': uid})
try:
pages = user['pages']
except:
pages = 0
fd.write(json.dumps({'uid': uid, 'pages': pages})+'\r\n')
else:
fd.write(json.dumps({'error': 'uid queue empty'})+'\r\n')
fd.flush()
elif action == 'getuserinfo':
try:
name = r.data
user = db.users.find_one({'name': name})
try:
u = {'_id': user['_id'], 'gender': user['gender'], 'location': user['location']}
fd.write(json.dumps({'user': u})+'\r\n')
except:
fd.write(json.dumps({'error': 'not found'})+'\r\n')
except:
fd.write(json.dumps({'error': 'bad request data'})+'\r\n')
fd.flush()
elif action == 'gettargetuid':
uid = target_uid_queue.get()
if uid:
fd.write(json.dumps({'uid': uid})+'\r\n')
else:
fd.write(json.dumps({'error': 'target uid queue empty'})+'\r\n')
fd.flush()
else:
break
LOGGER.info('end connection %s:%s' % address)
示例8: save
def save(self):
self.sync()
if self.easyID3.is_modified:
LOGGER.info('Saving file changes...')
self.easyID3.save()
if session.is_modified(self.model):
LOGGER.info('Committing model changes...')
session.merge(self.model)
session.commit()
示例9: mailHandler
def mailHandler(event):
""" notify this error
"""
try:
return event.error['context'].restrictedTraverse(
'@@logbook_mail')(event)
except Exception, e:
LOGGER.error(
"An error occured while notifying recipients: %s" % str(e))
示例10: rescale_features
def rescale_features(train, test):
LOGGER.info("Rescaling feature matrices")
if issparse(train):
LOGGER.info("Converting feature matrices from sparse to dense")
train = csr_matrix(train).todense()
test = csr_matrix(test).todense()
scaler = StandardScaler(with_mean=False)
train_features_rs = scaler.fit_transform(train)
return train_features_rs, scaler.transform(test)
示例11: webhookHandler
def webhookHandler(event):
""" Travese to webhook handler and let it deal with the error.
"""
try:
return event.error['context'].restrictedTraverse(
'@@logbook_webhook')(event)
except Exception, e:
LOGGER.error(
"An error occured while notifying with webhooks: %s" % str(e))
示例12: gettargetuid
def gettargetuid(self):
self.socket.sendall(json.dumps({'action': 'gettargetuid'})+'\r\n')
res = self.socket.recv(1024)
r = json.loads(res, object_hook=_obj_hook)
if hasattr(r, 'error'):
LOGGER.error(r.error)
return None
else:
return r.uid
示例13: prepare_features
def prepare_features(train_movies, test_movies):
LOGGER.debug("Training samples: %d" % len(train_movies))
# Extract
vectorizer = CountVectorizer(decode_error=u'replace')
(train_features, train_labels, test_features, test_labels) = feature_extraction_sklearn(
vectorizer, train_movies, test_movies
)
LOGGER.debug("Original feature vectors size: %d" % csr_matrix(train_features[-1]).toarray().size)
return train_features, train_labels, test_features, test_labels
示例14: classify
def classify(classifier, train_features, train_labels, test_features,
test_labels, desc="Linear classifer"):
LOGGER.info("Beginning %s" % desc)
classifier.fit(train_features, train_labels)
results = classifier.predict(test_features)
correct = get_correct_num(results, test_labels)
LOGGER.info("%s predicted %d/%d correctly (%0.3f%% accuracy)\n" % (
desc, correct, len(test_labels), correct / len(test_labels) * 100))
return results
示例15: acquire_track_model
def acquire_track_model(self):
# determine if fingerprint present, if not generate
if not self.fingerprint:
self.query_fingerprint()
# use fingerprint to query model
self.model = session.query(SavedTrack).get(self.fingerprint)
# if 0 results, create model
if not self.model:
LOGGER.info('Track not found in database; creating...')
self.model = SavedTrack()