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


Python DumpTruck.insert方法代码示例

本文整理汇总了Python中dumptruck.DumpTruck.insert方法的典型用法代码示例。如果您正苦于以下问题:Python DumpTruck.insert方法的具体用法?Python DumpTruck.insert怎么用?Python DumpTruck.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dumptruck.DumpTruck的用法示例。


在下文中一共展示了DumpTruck.insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save_and_check

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
  def save_and_check(self, dataIn, tableIn, dataOut, tableOut = None, twice = True):
    if tableOut == None:
      tableOut = quote(tableIn)

    # Insert
    h = DumpTruck(dbname = '/tmp/test.db')
    h.insert(dataIn, tableIn)
    h.close()

    # Observe with pysqlite
    connection=sqlite3.connect('/tmp/test.db')
    cursor=connection.cursor()
    cursor.execute(u'SELECT * FROM %s' % tableOut)
    observed1 = cursor.fetchall()
    connection.close()

    if twice:
      # Observe with DumpTruck
      h = DumpTruck(dbname = '/tmp/test.db')
      observed2 = h.execute(u'SELECT * FROM %s' % tableOut)
      h.close()
 
      #Check
      expected1 = dataOut
      expected2 = [dataIn] if type(dataIn) in (dict, OrderedDict) else dataIn
 
      self.assertListEqual(observed1, expected1)
      self.assertListEqual(observed2, expected2)
开发者ID:sungoak,项目名称:dumptruck,代码行数:30,代码来源:tests.py

示例2: test_empty_row_second_insert

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
 def test_empty_row_second_insert(self):
     "An empty row acts like any other row."
     dt = DumpTruck(dbname="/tmp/test.db")
     dt.create_table({"foo": "uhtnh", "bar": "aoue"}, "nine")
     dt.insert({}, "nine")
     c = dt.execute("select count(*) as c from nine")[0]["c"]
     dt.close()
     self.assertEqual(c, 1)
开发者ID:4bic,项目名称:entity_log,代码行数:10,代码来源:tests.py

示例3: test_second_insert

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
 def test_second_insert(self):
   "Inserting a second row that is all null adds an empty row."
   dt = DumpTruck(dbname = '/tmp/test.db')
   dt.create_table({'foo': 'uhtnh', 'bar': 'aoue'}, 'three')
   dt.insert({'foo': None, 'bar': None}, 'three')
   c = dt.execute('select count(*) as c from three')[0]['c']
   dt.close()
   self.assertEqual(c, 1)
开发者ID:sungoak,项目名称:dumptruck,代码行数:10,代码来源:tests.py

示例4: test_empty_row_second_insert

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
 def test_empty_row_second_insert(self):
   "An empty row acts like any other row."
   dt = DumpTruck(dbname = '/tmp/test.db')
   dt.create_table({'foo': 'uhtnh', 'bar': 'aoue'}, 'nine')
   dt.insert({}, 'nine')
   c = dt.execute('select count(*) as c from nine')[0]['c']
   dt.close()
   self.assertEqual(c, 1)
开发者ID:sungoak,项目名称:dumptruck,代码行数:10,代码来源:tests.py

示例5: test_no_rows_second_insert

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
 def test_no_rows_second_insert(self):
   "Nothing happens if no rows are inserted to a table that is there."
   dt = DumpTruck(dbname = '/tmp/test.db')
   dt.create_table({'foo': 'uhtnh', 'bar': 'aoue'}, 'ninety')
   dt.insert([], 'ninety')
   c = dt.execute('select count(*) as c from ninety')[0]['c']
   dt.close()
   self.assertEqual(c, 0)
开发者ID:sungoak,项目名称:dumptruck,代码行数:10,代码来源:tests.py

示例6: test_second_insert

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
 def test_second_insert(self):
     "Inserting a second row that is all null adds an empty row."
     dt = DumpTruck(dbname="/tmp/test.db")
     dt.create_table({"foo": "uhtnh", "bar": "aoue"}, "three")
     dt.insert({"foo": None, "bar": None}, "three")
     c = dt.execute("select count(*) as c from three")[0]["c"]
     dt.close()
     self.assertEqual(c, 1)
开发者ID:4bic,项目名称:entity_log,代码行数:10,代码来源:tests.py

示例7: test_no_rows_second_insert

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
 def test_no_rows_second_insert(self):
     "Nothing happens if no rows are inserted to a table that is there."
     dt = DumpTruck(dbname="/tmp/test.db")
     dt.create_table({"foo": "uhtnh", "bar": "aoue"}, "ninety")
     dt.insert([], "ninety")
     c = dt.execute("select count(*) as c from ninety")[0]["c"]
     dt.close()
     self.assertEqual(c, 0)
开发者ID:4bic,项目名称:entity_log,代码行数:10,代码来源:tests.py

示例8: users

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
def users():
    dt = DumpTruck(dbname = '/tmp/socrata.db')
    dt.create_table({'id': 'abcd-efgh'}, 'user')
    dt.create_index(['id'], 'user', unique = True)

    _users = {}
    for portal in os.listdir('data'):
        for viewid in os.listdir(os.path.join('data', portal, 'views')):
            handle = open(os.path.join('data', portal, 'views', viewid), 'r')
            try:
                view = json.load(handle)
            except:
                # *cringe*
                continue
            handle.close()

            if view['owner']['id'] in _users:
                _users[view['owner']['id']]['views'].add(view['id'])
                try:
                    _users[view['owner']['id']]['publicationDates'].add((view['id'], view['publicationDate']))
                except:
                    return view
            else:
                _users[view['owner']['id']] = view['owner']
                _users[view['owner']['id']]['views'] = {view['id']}
                _users[view['owner']['id']]['tables'] = set()
                _users[view['owner']['id']]['publicationDates'] = set()

            if view['tableAuthor']['id'] in _users:
                _users[view['tableAuthor']['id']]['tables'].add(view['tableId'])
            else:
                _users[view['tableAuthor']['id']] = view['tableAuthor']
                _users[view['tableAuthor']['id']]['views'] = set()
                _users[view['tableAuthor']['id']]['tables'] = {view['tableId']}
                _users[view['tableAuthor']['id']]['publicationDates'] = set()

    for uid in _users.keys():
        for key in ['views', 'rights', 'tables']:
            if key in _users[uid]:
                _users[uid]['n_' + key] = len(_users[uid][key])
                del _users[uid][key]

    dt.insert(_users.values(), 'user')
    for uid, user in _users.items():
        for viewid, publicationDate in user['publicationDates']:
            dt.insert({'userid': user['id'], 'viewid': viewid, 'publicationDate': publicationDate}, 'publications', commit = False)
    dt.commit()
    return _users
开发者ID:casunlight,项目名称:socrata-analysis,代码行数:50,代码来源:run.py

示例9: AuctionsPipeline

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
class AuctionsPipeline(object):
    def open_spider(self, spider):
        self.dt = DumpTruck(dbname=settings['DB_PATH'],auto_commit=True)

        id_data = self.dt.execute('SELECT id FROM auctions')
        self.ids = [x['id'] for x in id_data]

    def process_item(self, item, spider):
        if 'auctions' not in getattr(spider,'pipelines',[]):
            return item

        item['id'] = int(item['id'][0])
        item['auctioneer'] = ' '.join(item['auctioneer'])
        item['contact_number'] = ' '.join(item['contact_number'])
        item['date'] = '%s %s' % (' '.join(item['date']), ' '.join(item['time']))
        item['location'] = ' '.join(item['location'])
        item['link'] = ' '.join(item['link'])
        item['listing'] = ' '.join(item['listing'])

        #format phonenumber
        parsed_number = phonenumbers.parse(item['contact_number'],'US')
        item['contact_number'] = phonenumbers.format_number(parsed_number, phonenumbers.PhoneNumber())

        # format listing / remove any html cludge
        soup_listing = BeautifulSoup(item['listing'])
        item['listing'] = soup_listing.get_text()

        # format date and time to standard format
        dt = parse(item['date'])
        item['date'] = dt.datetime.strftime('%Y-%m-%d %H:%M:%S')

        if item['id'] in self.ids:
            raise DropItem('Dupe auction stored, ignoring listing: %s' % item)
        else:
            self.dt.insert({
                'id': item['id'],
                'auctioneer': item['auctioneer'],
                'contact_number': item['contact_number'],
                'date': item['date'],
                'location': item['location'],
                'link': item['link'],
                'listing': item['listing'],
            }, 'auctions')

            return item
开发者ID:stevecoward,项目名称:auction-scraper,代码行数:47,代码来源:pipelines.py

示例10: test_convert_lxml

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
 def test_convert_lxml(self):
     dt = DumpTruck(dbname="/tmp/test.db", adapt_and_convert=True)
     elementstringresult = lxml.html.fromstring("<html>Hi</html>").xpath("//*/text()")[0]
     dt.insert({"bar": elementstringresult}, "foo")
     self.assertEqual(type(dt.dump("foo")[0]["bar"]), unicode)
开发者ID:4bic,项目名称:entity_log,代码行数:7,代码来源:tests.py

示例11: test_retrieve

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
 def test_retrieve(self):
   dt = DumpTruck(dbname = DB_FILE)
   dt.insert([{'a': 'b'}], 'c')
   self.assertEqual(dt.execute('select * from c', structure = zip)[0], ('a', 'b'))
开发者ID:drj11,项目名称:dumptruck,代码行数:6,代码来源:tests.py

示例12: test_save

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
 def test_save(self):
     h = DumpTruck(dbname="/tmp/test.db")
     data = [{"firstname": "Robert", "lastname": "LeTourneau"}]
     h.insert(data, "foo")
     self.assertEqual(data, h.dump("foo"))
     h.close()
开发者ID:4bic,项目名称:entity_log,代码行数:8,代码来源:tests.py

示例13: test_many

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
 def test_many(self):
   dt = DumpTruck(dbname = '/tmp/test.db')
   rowid = dt.insert([{u'foo': 8}, {u'bar': 5}])
   self.assertEqual(rowid, [1, 2])
开发者ID:sungoak,项目名称:dumptruck,代码行数:6,代码来源:tests.py

示例14: test_if_not_exists

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
 def test_if_not_exists(self):
     dt = DumpTruck(dbname="/tmp/test.db")
     dt.insert({"foo": "bar"}, "baz")
     dt.insert({"foo": "bar"}, "baz")
开发者ID:4bic,项目名称:entity_log,代码行数:6,代码来源:tests.py

示例15: test_save_integers

# 需要导入模块: from dumptruck import DumpTruck [as 别名]
# 或者: from dumptruck.DumpTruck import insert [as 别名]
 def test_save_integers(self):
     dt = DumpTruck()
     with self.assertRaises(ValueError):
         dt.insert({"foo": {1: "A", 2: "B", 3: "C"}})
开发者ID:4bic,项目名称:entity_log,代码行数:6,代码来源:tests.py


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