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


Python Delorean.epoch方法代码示例

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


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

示例1: process_item

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import epoch [as 别名]
    def process_item(self, item, spider):
        if 'search_results' not in getattr(spider,'pipelines',[]):
            return item

        dt = Delorean()

        item['id'] = item['id'][0]
        item['auction_id'] = item['auction_id'][0]
        item['site'] = item['site'][0]
        item['link'] = item['link'][0]
        item['name'] = item['name'][0]
        item['price'] = ','.join([x.replace(',','').replace('$','') for x in item['price']]) if 'price' in item else 0
        item['modified'] = int(dt.epoch())

        existing_record = Session().query(AuctionItem)\
            .filter(AuctionItem.id == item['id'])\
            .filter(AuctionItem.auction_id == item['auction_id']).all()

        item = AuctionItem(**item)

        if existing_record is not None:
            item.update()
        else:
            item.create()
            
        return item
开发者ID:stevecoward,项目名称:auction-scraper,代码行数:28,代码来源:pipelines.py

示例2: epoch

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import epoch [as 别名]
def epoch(date):
    dt = Delorean(datetime=date, timezone='US/Eastern')
    return int(dt.epoch())
开发者ID:stevecoward,项目名称:auction-scraper,代码行数:5,代码来源:main.py

示例3: DeloreanTests

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import epoch [as 别名]

#.........这里部分代码省略.........
    def test_move_year_function(self):
        dt_next = datetime(2014, 1, 3, 4, 31, 14, 148546, tzinfo=utc)
        dt_last = datetime(2012, 1, 3, 4, 31, 14, 148546, tzinfo=utc)

        d_obj_next = move_datetime_year(self.do.datetime, 'next', 1)
        d_obj_last = move_datetime_year(self.do.datetime, 'last', 1)

        self.assertEqual(dt_next, d_obj_next)
        self.assertEqual(dt_last, d_obj_last)

    def test_range_count(self):
        """
        tests the range method with count used
        """
        count = list(stops(DAILY, count=5))
        self.assertEqual(len(count), 5)

    def test_range_with_start(self):
        dates1 = []
        for do in stops(DAILY, count=5, start=datetime.utcnow()):
            do.truncate('minute')
            dates1.append(do)
        do = Delorean().truncate('minute')
        dates2 = []
        for x in range(5):
            dates2.append(do.next_day(x))
        self.assertEqual(dates1, dates2)

    def test_range_with_start_and_stop(self):
        dates1 = []
        tomorrow = datetime.utcnow() + timedelta(days=1)
        for do in stops(DAILY, start=datetime.utcnow(), until=tomorrow):
            do.truncate('minute')
            dates1.append(do)
        do = Delorean().truncate('minute')
        dates2 = []
        for x in range(2):
            dates2.append(do.next_day(x))
        self.assertEqual(dates1, dates2)

    def test_range_with_interval(self):
        dates1 = []
        for do in stops(DAILY, interval=2, count=3, start=datetime.utcnow()):
            do.truncate('minute')
            dates1.append(do)
        do = Delorean().truncate('minute')
        dates2 = []
        for x in range(6):
            if (x % 2) == 0:
                dates2.append(do.next_day(x))
        self.assertEqual(dates1, dates2)

    def test_delorean_failure(self):
        dt = datetime.utcnow()
        dt = utc.localize(dt)
        self.assertRaises(DeloreanInvalidDatetime, Delorean, datetime=dt)

    def test_delorean_with_datetime(self):
        dt = datetime.utcnow()
        d = Delorean(datetime=dt, timezone=UTC)
        dt = utc.localize(dt)
        self.assertEqual(dt, d._dt)
        self.assertEqual(UTC, d._tz)

    def test_delorean_with_timezone(self):
        dt = datetime.utcnow()
        d = Delorean(datetime=dt, timezone=UTC)
        d = d.shift("US/Eastern")
        dt = utc.localize(dt)
        dt = est.normalize(dt)
        self.assertEqual(dt, d._dt)
        self.assertEqual(est, timezone(d._tz))

    def test_delorean_with_only_timezone(self):
        dt = datetime.utcnow()
        dt = utc.localize(dt)
        dt = est.normalize(dt)
        dt = dt.replace(second=0, microsecond=0)
        d = Delorean(timezone="US/Eastern")
        d.truncate('minute')
        self.assertEqual(est, timezone(d._tz))
        self.assertEqual(dt, d._dt)

    def testparse_with_timezone(self):
        d1 = parse("2011/01/01 00:00:00 -0700")
        d2 = datetime(2011, 1, 1, 7, 0)
        d2 = utc.localize(d2)
        self.assertEqual(d2, d1.datetime)
        self.assertEqual(utc, timezone(d1._tz))

    def test_shift_failure(self):
        self.assertRaises(DeloreanInvalidTimezone, self.do.shift, "US/Westerrn")

    def test_epoch(self):
        unix_time = self.do.epoch()
        self.assertEqual(unix_time, 1357187474.148546)

    def test_epoch_creation(self):
        do = epoch(1357187474.148546)
        self.assertEqual(self.do, do)
开发者ID:shussain,项目名称:delorean,代码行数:104,代码来源:test_data.py

示例4: index

# 需要导入模块: from delorean import Delorean [as 别名]
# 或者: from delorean.Delorean import epoch [as 别名]
def index():
    dt = Delorean()
    auctions = Session().query(Auction).order_by(Auction.date.desc()).all()
    return render_template('admin/index.html', auctions=auctions, now=int(dt.epoch()))
开发者ID:stevecoward,项目名称:auction-scraper,代码行数:6,代码来源:admin.py


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