本文整理汇总了Python中model.DBSession.close方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.close方法的具体用法?Python DBSession.close怎么用?Python DBSession.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.DBSession
的用法示例。
在下文中一共展示了DBSession.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import close [as 别名]
def new(cls, username, password):
salt = random_str()
password_md5 = md5(password.encode('utf-8')).hexdigest()
password_final = md5((password_md5 + salt).encode('utf-8')).hexdigest()
level = USER_LEVEL.ADMIN if cls.count() == 0 else USER_LEVEL.NORMAL # 首个用户赋予admin权限
the_time = int(time.time())
session = DBSession()
ret = cls(username=username, password=password_final, salt=salt, level=level, key=random_str(32),
key_time = the_time, reg_time = the_time)
session.add(ret)
session.commit()
session.close()
return ret
示例2: crawling
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import close [as 别名]
def crawling(company_short_name):
param = {'first': 'false', 'pn': 0, 'kd': ''}
param = {'first': 'false', 'pn': page, 'sortField': 0, 'havemark': 0}
log = "[{}]\t抓取第 {} 页完毕, 当前页职位个数{}, 累计已抓{}, 该公司总计{}"
count = 0
for i in range(max_iter):
param['pn'] += 1
req = requests.post(job_url, data=param)
info = json.loads(req.content)
total_count = int(info['content']['positionResult']['totalCount'])
job_list = info['content']['positionResult']['result']
count += len(job_list)
print log.format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), param['pn'],
len(job_list), count, total_count)
session = DBSession()
for job in job_list:
c = Job(
company_id=company.get("companyId"),
company_full_name=company.get("companyFullName"),
company_short_name=company.get("companyShortName"),
city=company.get("city"),
position_num=company.get("positionNum"),
city_score=company.get("cityScore"),
finance_stage=company.get("financeStage"),
industry_field=company.get("industryField"),
country_score=company.get("countryScore"),
company_features=company.get("companyFeatures"),
process_rate=company.get("processRate"),
interview_remark_num=company.get("interviewRemarkNum"),
approve=company.get("approve"),
create_time=datetime.now()
)
session.add(c)
session.commit()
session.close()
time.sleep(3)
if len(job_list) == 0: break
return count