本文整理匯總了Python中db.DB.hit_group_content_id方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.hit_group_content_id方法的具體用法?Python DB.hit_group_content_id怎麽用?Python DB.hit_group_content_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類db.DB
的用法示例。
在下文中一共展示了DB.hit_group_content_id方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: process_group
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import hit_group_content_id [as 別名]
def process_group(hg, crawl_id, requesters, processed_groups, dbpool):
"""Gevent worker that should process single hitgroup.
This should write some data into database and do not return any important
data.
"""
hg['keywords'] = ', '.join(hg['keywords'])
# for those hit goups that does not contain hash group, create one and
# setup apropiate flag
hg['qualifications'] = ', '.join(hg['qualifications'])
conn = dbpool.getconn(thread.get_ident())
db = DB(conn)
try:
hit_group_content_id = db.hit_group_content_id(hg['group_id'])
if hit_group_content_id is None:
# check if there's profile for current requester and if does
# exists with non-public status, then setup non public status for
# current hitsgroup content
profile = requesters.get(hg['requester_id'], None)
if profile and profile.is_public is False:
hg['is_public'] = False
else:
hg['is_public'] = True
# fresh hitgroup - create group content entry, but first add some data
# required by hitgroup content table
hg['occurrence_date'] = datetime.datetime.now()
hg['first_crawl_id'] = crawl_id
if not hg['group_id_hashed']:
# if group_id is hashed, we cannot fetch details because we
# don't know what the real hash is
hg.update(hits_group_info(hg['group_id']))
else:
hg['html'] = ''
hit_group_content_id = db.insert_hit_group_content(hg)
log.debug('new hit group content: %s;;%s',
hit_group_content_id, hg['group_id'])
hg['hit_group_content_id'] = hit_group_content_id
hg['crawl_id'] = crawl_id
hg['now'] = datetime.datetime.now()
db.insert_hit_group_status(hg)
conn.commit()
except Exception:
processed_groups.remove(hg['group_id'])
log.exception('process_group fail - rollback')
conn.rollback()
finally:
db.curr.close()
dbpool.putconn(conn, thread.get_ident())
msg = ('This really should not happen, Hitgroupstatus was processed but'
' is not on the list, race condition?')
assert hg['group_id'] in processed_groups, msg
return True
示例2: process_group
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import hit_group_content_id [as 別名]
def process_group(hg, crawl_id, requesters, processed_groups):
"""Gevent worker that should process single hitgroup.
This should write some data into database and do not return any important
data.
"""
hg['keywords'] = ', '.join(hg['keywords'])
# for those hit goups that does not contain hash group, create one and
# setup apropiate flag
hg['group_id_hashed'] = not bool(hg.get('group_id', None))
hg['qualifications'] = ', '.join(hg['qualifications'])
if hg['group_id_hashed']:
composition = ';'.join(map(str, (
hg['title'], hg['requester_id'], hg['time_alloted'],
hg['reward'], hg['description'], hg['keywords'],
hg['qualifications']))) + ';'
hg['group_id'] = hashlib.md5(composition).hexdigest()
log.debug('group_id not found, creating hash: %s %s',
hg['group_id'], composition)
if hg['group_id'] in processed_groups:
# this higroup was already processed
log.info('duplicated group: %s;;%s', crawl_id, hg['group_id'])
return False
conn = dbpool.getconn(thread.get_ident())
db = DB(conn)
try:
hit_group_content_id = db.hit_group_content_id(hg['group_id'])
if hit_group_content_id is None:
# check if there's profile for current requester and if does
# exists with non-public status, then setup non public status for
# current hitsgroup content
profile = requesters.get(hg['requester_id'], None)
if profile and profile.is_public is False:
hg['is_public'] = False
else:
hg['is_public'] = True
# fresh hitgroup - create group content entry, but first add some data
# required by hitgroup content table
hg['occurrence_date'] = datetime.datetime.now()
hg['first_crawl_id'] = crawl_id
if not hg['group_id_hashed']:
# if group_id is hashed, we cannot fetch details because we
# don't know what the real hash is
hg.update(hits_group_info(hg['group_id']))
else:
hg['html'] = ''
hit_group_content_id = db.insert_hit_group_content(hg)
log.debug('new hit group content: %s;;%s',
hit_group_content_id, hg['group_id'])
hg['hit_group_content_id'] = hit_group_content_id
hg['crawl_id'] = crawl_id
db.insert_hit_group_status(hg)
conn.commit()
except Exception:
log.exception('process_group fail - rollback')
conn.rollback()
finally:
db.curr.close()
dbpool.putconn(conn, thread.get_ident())
processed_groups.add(hg['group_id'])
return True