当前位置: 首页>>代码示例>>Python>>正文


Python models.db_connect函数代码示例

本文整理汇总了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)
开发者ID:Gmulti,项目名称:Foot-Engine,代码行数:7,代码来源:pipelines.py

示例2: __init__

 def __init__(self):
     log.start(settings.LOG_FILE)
     try:
         engine = db_connect()
         self.Session = sessionmaker(bind=engine)
     except Exception as e:
         pass
开发者ID:zachhilbert,项目名称:freelist,代码行数:7,代码来源:pipelines.py

示例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}
开发者ID:fashionwu,项目名称:weixiao,代码行数:26,代码来源:behavior.py

示例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...'
开发者ID:fashionwu,项目名称:weixiao,代码行数:25,代码来源:main.py

示例5: __init__

 def __init__(self):
     """
     Initialize database connection and create tables.
     """
     engine = db_connect()
     create_tables(engine)
     self.Session = sessionmaker(bind=engine)
开发者ID:mcwitt,项目名称:apt-hunter,代码行数:7,代码来源:pipelines.py

示例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
开发者ID:ewong718,项目名称:tmiicentral,代码行数:30,代码来源:billing_sql.py

示例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
开发者ID:4bic-attic,项目名称:scrape,代码行数:30,代码来源:pipelines.py

示例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)
开发者ID:vaibhavmule,项目名称:learning-python,代码行数:7,代码来源:pipelines.py

示例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()
开发者ID:piatra,项目名称:ssl-project,代码行数:27,代码来源:get_demographics.py

示例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
开发者ID:fashionwu,项目名称:weixiao,代码行数:7,代码来源:behavior.py

示例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)
开发者ID:zelaznik,项目名称:scratchpad,代码行数:8,代码来源:pipelines.py

示例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)
开发者ID:snoozan,项目名称:Article-Aggregator,代码行数:8,代码来源:pipelines.py

示例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)
开发者ID:johnconnelly75,项目名称:newsCurator,代码行数:8,代码来源:pipelines.py

示例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)
开发者ID:kacak9229,项目名称:scrappy,代码行数:8,代码来源:pipelines.py

示例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)
开发者ID:AncillaryStats,项目名称:AS-Scrapers,代码行数:8,代码来源:pipelines.py


注:本文中的models.db_connect函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。