本文整理汇总了Python中Utils.Logger类的典型用法代码示例。如果您正苦于以下问题:Python Logger类的具体用法?Python Logger怎么用?Python Logger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Logger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parse_douban
def _parse_douban(page):
soup = BeautifulSoup(page)
ret = []
try:
table = soup.findAll('table', {'class':'olt'})[0]
'''
nexturl = soup.findAll('div', {'class':'paginator'})[0]\
.findAll('span', {'class':'next'})[0]
try:
nexturl = nexturl.findAll('link')[0]['href']
except:
nexturl = ''
'''
for row in PageParser._clean(table)[1:]: #skip table header
try:
url, _, _, reply_time = PageParser._clean(row)
except:
continue
url = PageParser._clean(url)[0]['href'].strip()
reply_time = PageParser._clean(reply_time)[0].strip()
if ':' in reply_time:
year = time.strftime('%Y-',time.localtime(time.time()))
reply_time = time.strptime(year+reply_time, '%Y-%m-%d %H:%M')
else:
reply_time = time.strptime(reply_time, '%Y-%m-%d')
reply_time = int(time.mktime(reply_time))
hashurl = hashlib.md5(url).hexdigest()
ret.append(Link(
hashurl=hashurl,
url=url,
reply_time=reply_time
))
except IndexError:
Logger.error('index error!')
return ret #, nexturl
示例2: diff_task
def diff_task(linkdb, output, pagelist):
page_filenames = []
#trick :)
if os.path.exists(pagelist):
Logger.info('Use pagelist indead of page files!')
with open(pagelist, 'r') as f:
for line in f:
line = line.strip()
if not line:
break
filename = line
page_filenames.append(filename)
else:
Logger.info('CANNOT find pagelist file: %s' % pagelist)
tasks = {}
sources = []
with open(linkdb, 'r') as f:
for line in f:
line = line.strip()
if line:
try:
hashurl, url, reply_time, source = line.split('\t')[:4]
except: continue
filename = '%s' % (hashurl)
tasks.update({
filename:{
'url':url,
'source':source
}
})
sources.append(source)
if not pagelist:
for source in set(sources):
source = os.path.join(output, source)
if os.path.exists(source):
filenames = os.listdir(source)
for filename in filenames:
tasks.pop(filename)
else:
os.mkdir(source)
else:
for source in set(sources):
source = os.path.join(output, source)
if not os.path.exists(source):
os.mkdir(source)
for filename in page_filenames:
try:
tasks.pop(filename)
except:
print 'Skip', filename
return tasks
示例3: open
def open(self, url, delay=0.1):
response = None
try:
response = self.br.open(url, timeout=20.0)
except urllib2.HTTPError, e:
while e.code != 404:
interval = Interval.val()
time.sleep(interval)
Logger.info('sleep %ds error %d %s' % (interval, e.code, url))
try:
response = self.br.open(url, timeout=20.0)
Logger.info('skip 403 ' + url)
break
except urllib2.HTTPError, e:
if e.code != 404:
continue
except:
示例4: parse
def parse(self, **args):
page = args['page']
source = args['source']
hashurl = args['hashurl']
ret = PageParser.parse(page, source)
if ret.has_key('error'):
Logger.info(hashurl+' '+ret['error'])
return
record = '\t'.join([
hashurl,
ret['title2'] if ret['title2']\
else ret['title'],
json.dumps(ret['author']),
json.dumps(ret['images']),
json.dumps(ret['links']),
ret['text'],
ret['pub_time'],
]).encode('utf-8')
self._db.insert(record)
示例5: parse
def parse(self, **args):
hashurl = args['hashurl']
title = args['title']
text = args['text']
ret = TextParser.parse(title+' '+text)
if ret.has_key('error'):
Logger.info(hashurl+' '+ret['error'])
return
record = '\t'.join([
hashurl,
title,
text,
ret['jushi'],
ret['shouji'],
ret['zujin'],
ret['dizhi'],
ret['ditie'],
])
self._db.insert(record)
示例6: crawl
def crawl(self, **args):
source = args['source']
ext = args['ext']
reply_time = args['reply_time']
br = Browser()
page = br.open(self.baseurl)
new_reply_time = reply_time
while True:
links = PageParser.parse(page, source)
for i, link in enumerate(links):
if reply_time < link.reply_time:
if i is 0:
new_reply_time = link.reply_time
self.db.insert('\t'.join([str(link), source, json.dumps(ext)]))
else:
return new_reply_time
try:
page = br.follow_link(text='后页>')
except:
Logger.info('finished!')
break
return new_reply_time
示例7: run_linkspider
def run_linkspider(db, meta):
source = 'douban'
baseurls = [
'http://www.douban.com/group/beijingzufang/discussion',
'http://www.douban.com/group/fangzi/discussion',
'http://www.douban.com/group/262626/discussion',
'http://www.douban.com/group/276176/discussion',
'http://www.douban.com/group/26926/discussion',
'http://www.douban.com/group/sweethome/discussion',
'http://www.douban.com/group/242806/discussion',
'http://www.douban.com/group/257523/discussion',
'http://www.douban.com/group/279962/discussion',
'http://www.douban.com/group/334449/discussion',
]
for baseurl in baseurls:
Logger.info('start '+baseurl)
groupid = baseurl\
.replace('http://www.douban.com/group/', '')\
.replace('/discussion', '')
reply_time = 0
if meta.has(source, groupid)\
and meta.get(source, groupid).has_key('reply_time'):
reply_time = meta.get(source, groupid)['reply_time']
linkspider = LinkSpider(
baseurl=baseurl,
db=db,
)
reply_time = linkspider.crawl(
source=source,
reply_time=reply_time,
ext={
'groupid':groupid
}
)
meta.set(source, groupid, {
'reply_time':reply_time
})
meta.write()
示例8: TestAnnotation
import time
import math
import sys
import pdb
from Utils import Logger
from Utils import GeomUtils
from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnimateAnnotation
from Observers import ObserverBase
logger = Logger.getLogger('TestObserver', Logger.DEBUG)
#-------------------------------------
class TestAnnotation(AnimateAnnotation):
def __init__(self):
Annotation.__init__(self)
self.dt = 0
self.pattern = [1,1,1,1,1,0,0,0,0,0,2,0,0,0,0,0]
self.idx = 0
def step(self,dt):
"Test animator, tracks the time since this was last called"
self.idx = (self.idx + 1) % len(self.pattern)
self.dt += dt
示例9: TkSketchGUI
#from SketchFramework.strokeout import imageBufferToStrokes, imageToStrokes
#from SketchFramework.NetworkReceiver import ServerThread
from Utils.StrokeStorage import StrokeStorage
from Utils.GeomUtils import getStrokesIntersection
from Utils import Logger
from Observers.ObserverBase import Animator
# Constants
WIDTH = 1000
HEIGHT = 800
MID_W = WIDTH/2
MID_H = HEIGHT/2
logger = Logger.getLogger("TkSketchGUI", Logger.DEBUG)
class TkSketchGUI(_SketchGUI):
Singleton = None
def __init__(self):
"Set up members for this GUI"
global HEIGHT, WIDTH
self.sketchFrame = None
TkSketchGUI.Singleton = self
self.run()
def run(self):
root = Tk()
root.title("Sketchy/Scratch")
self.sketchFrame = TkSketchFrame(master = root)
示例10: LineAnnotation
>>> c.onStrokeAdded(Stroke(circlepoints))
"""
#-------------------------------------
import math
from Utils import Logger
from Utils import GeomUtils
from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnnotatableObject
logger = Logger.getLogger('LineObserver', Logger.WARN )
#-------------------------------------
class LineAnnotation(Annotation):
def __init__(self, linearity, angle, start_point, end_point ):
Annotation.__init__(self)
self.linearity = linearity
self.angle = angle
self.start_point = start_point
self.end_point = end_point
#-------------------------------------
class LineMarker( BoardObserver ):
"Watches for lines, and annotates them with the linearity and angle"
示例11: Logger
# XrdTest is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with XrdTest. If not, see <http://www.gnu.org/licenses/>.
#
# -------------------------------------------------------------------------------
#
# File: Daemon
# Desc: TODO
# -------------------------------------------------------------------------------
from Utils import Logger
LOGGER = Logger(__name__).setup()
try:
import os
import signal
import sys
import logging
except ImportError, e:
LOGGER.error(str(e))
sys.exit(1)
class DaemonException(Exception):
"""
General Exception raised by Daemon.
"""
示例12: ArrowHeadAnnotation
#-------------------------------------
import math
import pdb
from Utils import Logger
from Utils import GeomUtils
from Utils import Template
from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnnotatableObject
from xml.etree import ElementTree as ET
from Observers.Semantics_Class1 import Class1Annotation
logger = Logger.getLogger('ArrowObserver', Logger.WARN)
arrowHeadMatcher = Template.TemplateDict(filename = "Utils/arrowheads.templ")
class ArrowHeadAnnotation( Class1Annotation ):
def __init__(self, end1, cusp, end2):
Class1Annotation.__init__(self)
self.addKeyPoint("end1", end1)
self.addKeyPoint("cusp", cusp)
self.addKeyPoint("end2", end2)
def classifyArrowhead(board, stroke):
"""Following the class 1 semantics, this classifies arrowheads"""
if _isArrowHead(stroke, arrowHeadMatcher):
# * (tip-point)
# o o
示例13: CamArea
from Utils.ImageUtils import findCalibrationChessboard
from multiprocessing.queues import Queue
from sketchvision import ImageStrokeConverter as ISC
import cv
import gobject
import gtk
import multiprocessing
import pdb
import pygtk
import threading
pygtk.require('2.0')
log = Logger.getLogger("CamArea", Logger.DEBUG)
MAXCAPSIZE = (2592, 1944)
HD1080 = (1920, 1080)
HD720 = (1280, 720)
DEFAULT_CORNERS = [
(777.6, 239.76000000000002),
(2080, 533),
(2235.6, 1506.6000000000001),
(625.32, 1441.8000000000002),
]
if __name__ == "__main__":
DEBUG = True
else:
DEBUG = False
class CamArea (ImageArea):
示例14: BoardException
from SketchFramework.SketchGUI import DummyGUI
from SketchFramework.Stroke import Stroke
from Utils import GeomUtils
from Utils import Logger
from xml.etree import ElementTree as ET
import datetime
import pdb
import sys
import threading
from Utils.GeomUtils import pointDistance
logger = Logger.getLogger('Board', Logger.WARN )
#--------------------------------------------
class BoardException (Exception):
"""A custom exception class to handle errors within the framework"""
def __init__(self, message):
"""input: message for the error"""
self.message = message
def __str__(self):
return repr(self.message)
#--------------------------------------------
class BoardObserver(object):
"The Board Observer Class from which all other Board Observers should be derived"
def __init__(self, board):
self._parentBoard = board
self.AnnoFuncs={}
self._targetAnnotations = None #Set by the Board with a call to "RegisterBoardObserver"
示例15: DebugObserver
>>> d.trackAnnotation(myAnnotation)
FIXME: need some way to actually trigger the proper events to
actually test that the visualizer is called correctly
"""
import time
import pdb
from Utils import Logger
from Utils import GeomUtils
from SketchFramework.Point import Point
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnnotatableObject
logger = Logger.getLogger('DiGraphObserver', Logger.WARN )
#-------------------------------------
class DebugObserver( BoardObserver ):
"Watches for all annotations, and draws them"
def __init__(self, board):
BoardObserver.__init__(self, board)
self.getBoard().AddBoardObserver( self, [] )
self.watchSet = set([]) # set of annotation types to track
self.seenBefore = {} # set of particular annotation that we have already drawn
def trackAnnotation(self,annoType):
logger.debug("debugObserver adding %s", annoType.__name__ );
# add this annotation type to the list to track
self.watchSet.add(annoType)