本文整理汇总了Python中models.db_connect函数的典型用法代码示例。如果您正苦于以下问题:Python db_connect函数的具体用法?Python db_connect怎么用?Python db_connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
"""
Initializes database connection and sessionmaker.
Creates website table.
"""
engine = db_connect()
self.Session = sessionmaker(bind=engine)
示例2: __init__
def __init__(self):
log.start(settings.LOG_FILE)
try:
engine = db_connect()
self.Session = sessionmaker(bind=engine)
except Exception as e:
pass
示例3: getallbehaviorsbygid
def getallbehaviorsbygid(query):
engine = db_connect()
Session = sessionmaker(bind=engine)
session = Session()
behaviors = []
myquery = session.query(Behaviors).filter(Behaviors.tid==query['gid']).filter(Behaviors.uid>0).filter(Behaviors.bcode!=0).filter(Behaviors.bcode!=1).filter(Behaviors.bcode!=2).filter(Behaviors.bcode!=3).filter(Behaviors.bcode!=5).filter(Behaviors.bcode!=11).filter(Behaviors.bcode!=12).filter(Behaviors.tcode!=0).filter(Behaviors.tcode!=3).filter(Behaviors.tcode!=4)
total = myquery.count()
for instance in myquery.order_by(desc(Behaviors.t)).offset(query['offset']).limit(query['limit']):
behavior = {}
behavior['uid'] = instance.uid
behavior['t'] = instance.t
behavior['bcode'] = instance.bcode
behavior['tcode'] = instance.tcode
behavior['tid'] = instance.tid
behaviors.append(behavior)
#endfor
session.close()
hasMore = 1
number = int(query['offset']) + int(query['limit'])
if (number>=total):
hasMore = 0
print 'get behaviors by gid - ', query['offset'], query['limit'], number, total, hasMore
return { 'numFound':total, 'hasMore':hasMore, 'behaviors':behaviors}
示例4: createWeixiaoSimTask
def createWeixiaoSimTask(self, potentialItem, items):
print 'begin createWeixiaoSimTask...'
# create json string
json_task = json.dumps({'item':potentialItem, 'existing':items}, separators=(',',':'))
print json_task
# and put it to lelesimtask table of lelespider, FIXME
#WeixiaoTaskService.addSimTask(json_task)
engine = db_connect()
Session = sessionmaker(bind=engine)
session = Session()
new_task = {}
new_task['jsontask'] = json_task
new_task['date'] = potentialItem['date']
new_task['time'] = potentialItem['time']
new_task['same'] = False
new_task['status'] = '0'
simtask = SimTask(**new_task)
session.add(simtask)
session.commit()
session.close()
print 'end createWeixiaoSimTask...'
示例5: __init__
def __init__(self):
"""
Initialize database connection and create tables.
"""
engine = db_connect()
create_tables(engine)
self.Session = sessionmaker(bind=engine)
示例6: importCalpendoIntoRMC
def importCalpendoIntoRMC(monthYear):
result = run_query("call billingCalpendoByMonth('{monthYear}%')".format(monthYear=monthYear), "calpendo")
s = db_connect("rmc")
for row in result:
row = list(row)
for idx, val in enumerate(row):
try:
row[idx] = pymysql.escape_string(unicode(val))
except UnicodeDecodeError:
row[idx] = pymysql.escape_string(val.decode('iso-8859-1'))
entry = Ris(accession_no=row[0], gco=row[1], project=row[2], MRN=row[3], PatientsName=row[4],
BirthDate=row[5], target_organ=row[6], target_abbr=row[7],
ScanDate=row[8], referring_md=row[9], Duration=row[10], ScanDTTM=row[11],
CompletedDTTM=row[12], Resource=row[13])
s.add(entry)
try:
s.commit()
except IntegrityError:
print "Warning: Duplicate row detected in ris table."
s.rollback()
else:
examEntry = Examcodes(target_abbr=row[7], target_organ=row[6])
s.add(examEntry)
try:
s.commit()
except IntegrityError:
print "Warning: Examcode already exists."
s.rollback()
return result
示例7: __init__
def __init__(self):
"""
Initializes database connection and sessionmaker.
Creates deals table.
"""
engine = db_connect()
create_deals_table(engine)
self.Session = sessionmaker( bind = engine )
def process_item(self, item, spider):
"""Save deals in the database.
This method is called for every item pipeline component.
"""
session = self.Session()
deal = Deals(**item)
try:
session.add(deal)
session.commit()
except:
session.rollback()
raise
finally:
session.close()
return item
示例8: __init__
def __init__(self):
"""Initialize database connecton and sessionmaker
Create deals table"""
engine = db_connect()
create_deals_table(engine)
self.Session = sessionmaker(bind=engine)
示例9: main
def main():
"""Index alexa demographics
"""
engine = db_connect()
Session = sessionmaker(bind=engine)
session = Session()
settings = get_project_settings()
settings.set('ITEM_PIPELINES',
{'demographic_scraper.demographic_scraper.pipelines.WebsiteDemographicPipeline': 300})
settings.set('EXTENSIONS',
{'scrapy.telnet.TelnetConsole': None,})
process = CrawlerProcess(settings)
for website in session.query(WebsitesContent).all():
demographic = list(session.query(Websites).filter_by(link=website.link))
if len(demographic) is 0:
url = website.link
print website.link
AlexaSpider.name = url
process.crawl(AlexaSpider, url=url, db_session=session)
process.start()
process.stop()
session.close()
示例10: __init__
def __init__(self, obj):
threading.Thread.__init__(self)
self.engine = db_connect()
create_all_tables(self.engine)
self.Session = sessionmaker(bind=self.engine)
self.session = self.Session()
self.obj = obj
示例11: __init__
def __init__(self):
''' Initializes db connection and session maker.
Creates deals table.
'''
engine = db_connect()
create_deals_table(engine)
self.Session = sessionmaker(bind=engine)
示例12: __init__
def __init__(self):
"""
initializes the database session
creates search term tables
"""
engine = db_connect()
create_url_table(engine)
self.Session = sessionmaker(bind=engine)
示例13: __init__
def __init__(self):
"""
Initializes database connection and sessionmaker.
Creates tables.
"""
self.engine = db_connect()
create_tables(self.engine)
self.Session = sessionmaker(bind=self.engine)
示例14: __init__
def __init__(self):
"""
Initializez database connection and sessionmaker
Create jobs table.
"""
engine = db_connect()
create_jobs_table(engine)
self.Session = sessionmaker(bind=engine)
示例15: __init__
def __init__(self):
"""
Initializes database connection and sessionmaker.
Creates nfl_te_games_2015 table if it doesn't exist.
"""
engine = db_connect()
create_tables(engine)
self.Session = sessionmaker(bind=engine)