• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python textlib.TimeStripper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pywikibot.textlib.TimeStripper的典型用法代码示例。如果您正苦于以下问题:Python TimeStripper类的具体用法?Python TimeStripper怎么用?Python TimeStripper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_timestripper_match_only

    def test_timestripper_match_only(self):
        """Test that latest date is used instead of other dates."""
        ts = TimeStripper(self.get_site())

        later_date = '10:57 06 June 2015 (UTC)'
        txt_match = '<!-- --> ' + self.user_and_date + ' <!-- -->' + later_date
        res = datetime.datetime(2015, 6, 6, 10, 57, tzinfo=self.tzone)
        self.assertEqual(ts.timestripper(txt_match), res)

        earlier_date = '02:57 06 June 2015 (UTC)'
        txt_match = '<!-- ' + self.user_and_date + ' --> ' + earlier_date
        res = datetime.datetime(2015, 6, 6, 6, 57, tzinfo=self.tzone)
        self.assertEqual(ts.timestripper(txt_match), res)
开发者ID:edgarskos,项目名称:pywikibot_scripts,代码行数:13,代码来源:timestripper_tests.py


示例2: test_timestripper_match

    def test_timestripper_match(self):
        """Test that dates in comments  are correctly recognised."""
        ts = TimeStripper(self.get_site())

        txt_match = '<!-- [[User:Do___ArchiveUntil]] ' + self.date + ' -->'
        res = datetime.datetime(2015, 6, 6, 6, 57, tzinfo=self.tzone)
        self.assertEqual(ts.timestripper(txt_match), res)

        txt_match = '<!-- --> <!-- ' + self.user_and_date + ' <!-- -->'
        res = datetime.datetime(2015, 6, 6, 6, 57, tzinfo=self.tzone)
        self.assertEqual(ts.timestripper(txt_match), res)

        txt_match = '<!-- ' + self.user_and_date + ' -->'
        res = datetime.datetime(2015, 6, 6, 6, 57, tzinfo=self.tzone)
        self.assertEqual(ts.timestripper(txt_match), res)
开发者ID:edgarskos,项目名称:pywikibot_scripts,代码行数:15,代码来源:timestripper_tests.py


示例3: test_timestripper_match

    def test_timestripper_match(self, key):
        """Test that correct date is matched."""
        self.ts = TimeStripper(self.get_site(key))

        tzone = tzoneFixedOffset(self.ts.site.siteinfo['timeoffset'],
                                 self.ts.site.siteinfo['timezone'])

        txtMatch = self.sites[key]['match']

        res = datetime.datetime(2010, 2, 7, 19, 48, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txtMatch), res)

        if 'match2' not in self.sites[key]:
            return

        txtMatch = self.sites[key]['match2']

        res = datetime.datetime(2008, 9, 12, 16, 41, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txtMatch), res)

        if 'match3' not in self.sites[key]:
            return

        txtMatch = self.sites[key]['match3']

        res = datetime.datetime(2014, 8, 14, 21, 18, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txtMatch), res)
开发者ID:anrao91,项目名称:pywikibot-core,代码行数:30,代码来源:timestripper_tests.py


示例4: TestTimeStripper

class TestTimeStripper(PywikibotTestCase):
    """Test cases for Link objects"""

    def setUp(self):
        site = pywikibot.Site('fr', 'wikipedia')
        self.ts = TimeStripper(site)
        super(TestTimeStripper, self).setUp()

    def test_findmarker(self):
        """Test that string which is not part of text is found"""

        txt = u'this is a string with a maker is @@@@already present'
        self.assertEqual(self.ts.findmarker(txt, base=u'@@', delta='@@'),
                         '@@@@@@')

    def test_last_match_and_replace(self):
        """Test that pattern matches the righmost item"""

        txtWithMatch = u'this string has one 1998, 1999 and 3000 in it'
        txtWithNoMatch = u'this string has no match'
        pat = self.ts.yearR

        self.assertEqual(self.ts.last_match_and_replace(txtWithMatch, pat),
                         (u'this string has one @@, @@ and 3000 in it',
                          {'year': u'1999'})
                         )
        self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat),
                         (txtWithNoMatch,
                          None)
                         )

    def test_timestripper(self):
        """Test that correct date is matched"""

        txtMatch = u'3 février 2010 à 19:48 (CET) 7 février 2010 à 19:48 (CET)'
        txtNoMatch = u'3 March 2010 19:48 (CET) 7 March 2010 19:48 (CET)'

        tzone = tzoneFixedOffset(self.ts.site.siteinfo['timeoffset'],
                                 self.ts.site.siteinfo['timezone'])

        res = datetime.datetime(2010, 2, 7, 19, 48, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txtMatch), res)
        self.assertEqual(self.ts.timestripper(txtNoMatch), None)
开发者ID:legoktm,项目名称:pywikibot-core,代码行数:44,代码来源:timestripper_tests.py


示例5: DiscussionThread

class DiscussionThread(object):
    """An object representing a discussion thread on a page, that is something of the form:

    == Title of thread ==

    Thread content here. ~~~~
    :Reply, etc. ~~~~
    """

    def __init__(self, title, now):
        self.title = title
        self.now = now
        self.content = ""
        self.ts = TimeStripper(site=site)
        self.timestamp = None

    def __repr__(self):
        return '%s("%s",%d bytes)' \
               % (self.__class__.__name__, self.title, len(self.content))

    def feed_line(self, line):
        if not self.content and not line:
            return

        self.content += line + '\n'

        timestamp = self.ts.timestripper(line)

        if not self.timestamp:  # first time
            self.timestamp = timestamp

        if timestamp:
            self.timestamp = max(self.timestamp, timestamp)

    def size(self):
        return len(self.title.encode('utf-8')) + len(self.content.encode('utf-8')) + 12

    def to_text(self):
        return "== " + self.title + ' ==\n\n' + self.content

    def should_be_archived(self, archiver):
        algo = archiver.get('algo')
        re_t = re.search(r'^old\((.*)\)$', algo)
        if re_t:
            if not self.timestamp:
                return ''
            #TODO: handle this:
                #return 'unsigned'
            maxage = str2time(re_t.group(1))
            if self.now - self.timestamp > maxage:
                return message('archivebot-older-than') + ' ' + re_t.group(1)
        return ''
开发者ID:blueprintmrk,项目名称:pywikibot-core,代码行数:52,代码来源:archivebot.py


示例6: TestTimeStripperWithDigitsAsMonths

class TestTimeStripperWithDigitsAsMonths(TestCase):

    """Test cases for TimeStripper methods."""

    family = 'wikipedia'
    code = 'cs'

    cached = True

    def setUp(self):
        """Setup a timestripper for the configured site."""
        super(TestTimeStripperWithDigitsAsMonths, self).setUp()
        self.ts = TimeStripper(self.get_site())

    def test_last_match_and_replace(self):
        """Test that pattern matches and removes items correctly."""
        txtWithOneMatch = u'this string has XX. YY. 12. in it'
        txtWithTwoMatch = u'this string has XX. 1. 12. in it'
        txtWithThreeMatch = u'this string has 1. 1. 12. in it'
        txtWithNoMatch = u'this string has no match'
        pat = self.ts.pmonthR

        self.assertEqual(self.ts.last_match_and_replace(txtWithOneMatch, pat),
                         (u'this string has XX. YY. 12. in it',
                          {'month': u'12.'})
                         )
        self.assertEqual(self.ts.last_match_and_replace(txtWithTwoMatch, pat),
                         (u'this string has XX. 1. 12. in it',
                          {'month': u'12.'})
                         )
        self.assertEqual(self.ts.last_match_and_replace(txtWithThreeMatch, pat),
                         (u'this string has @@ 1. 12. in it',
                          {'month': u'12.'})
                         )
        self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat),
                         (txtWithNoMatch,
                          None)
                         )
开发者ID:edgarskos,项目名称:pywikibot_scripts,代码行数:38,代码来源:timestripper_tests.py


示例7: test_timestripper_nomatch

    def test_timestripper_nomatch(self, key):
        """Test that correct date is not matched."""
        self.ts = TimeStripper(self.get_site(key))

        if 'nomatch' in self.sites[key]:
            txtNoMatch = self.sites[key]['nomatch']
        else:
            txtNoMatch = u'3 March 2010 19:48 (UTC) 7 March 2010 19:48 (UTC)'

        self.assertEqual(self.ts.timestripper(txtNoMatch), None)

        if 'nomatch1' not in self.sites[key]:
            return

        txtNoMatch = self.sites[key]['nomatch1']
        self.assertEqual(self.ts.timestripper(txtNoMatch), None)
开发者ID:anrao91,项目名称:pywikibot-core,代码行数:16,代码来源:timestripper_tests.py


示例8: setUp

 def setUp(self):
     super(TestTimeStripperWithDigitsAsMonths, self).setUp()
     self.ts = TimeStripper(self.get_site())
开发者ID:anrao91,项目名称:pywikibot-core,代码行数:3,代码来源:timestripper_tests.py


示例9: TestTimeStripperWithNoDigitsAsMonths

class TestTimeStripperWithNoDigitsAsMonths(TestCase):

    """Test cases for TimeStripper methods."""

    family = 'wikipedia'
    code = 'fr'

    cached = True

    def setUp(self):
        super(TestTimeStripperWithNoDigitsAsMonths, self).setUp()
        self.ts = TimeStripper(self.get_site())

    def test_findmarker(self):
        """Test that string which is not part of text is found."""
        txt = u'this is a string with a maker is @@@@already present'
        self.assertEqual(self.ts.findmarker(txt, base=u'@@', delta='@@'),
                         '@@@@@@')

    def test_last_match_and_replace(self):
        """Test that pattern matches and removes items correctly."""
        txtWithOneMatch = u'this string has 3000, 1999 and 3000 in it'
        txtWithTwoMatch = u'this string has 1998, 1999 and 3000 in it'
        txtWithNoMatch = u'this string has no match'
        pat = self.ts.pyearR

        self.assertEqual(self.ts.last_match_and_replace(txtWithOneMatch, pat),
                         (u'this string has 3000, @@ and 3000 in it',
                          {'year': u'1999'})
                         )
        self.assertEqual(self.ts.last_match_and_replace(txtWithTwoMatch, pat),
                         (u'this string has @@, @@ and 3000 in it',
                          {'year': u'1999'})
                         )
        self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat),
                         (txtWithNoMatch,
                          None)
                         )

        txtWithOneMatch = u'this string has XXX, YYY and février in it'
        txtWithTwoMatch = u'this string has XXX, mars and février in it'
        txtWithThreeMatch = u'this string has avr, mars and février in it'
        txtWithNoMatch = u'this string has no match'
        pat = self.ts.pmonthR

        self.assertEqual(self.ts.last_match_and_replace(txtWithOneMatch, pat),
                         (u'this string has XXX, YYY and @@ in it',
                          {'month': u'février'})
                         )
        self.assertEqual(self.ts.last_match_and_replace(txtWithTwoMatch, pat),
                         (u'this string has XXX, @@ and @@ in it',
                          {'month': u'février'})
                         )
        self.assertEqual(self.ts.last_match_and_replace(txtWithThreeMatch, pat),
                         (u'this string has @@, @@ and @@ in it',
                          {'month': u'février'})
                         )
        self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat),
                         (txtWithNoMatch,
                          None)
                         )

    def test_hour(self):
        """Test that correct hour is matched."""
        txtHourInRange = u'7 février 2010 à 23:00 (CET)'
        txtHourOutOfRange = u'7 février 2010 à 24:00 (CET)'

        self.assertNotEqual(self.ts.timestripper(txtHourInRange), None)
        self.assertEqual(self.ts.timestripper(txtHourOutOfRange), None)
开发者ID:anrao91,项目名称:pywikibot-core,代码行数:69,代码来源:timestripper_tests.py


示例10: TestTimeStripperLanguage

class TestTimeStripperLanguage(TestCase):

    """Test cases for English language"""

    sites = {
        'cswiki': {
            'family': 'wikipedia',
            'code': 'cs',
            'match': u'3. 2. 2010, 19:48 (UTC) 7. 2. 2010 19:48 (UTC)',
        },
        'enwiki': {
            'family': 'wikipedia',
            'code': 'en',
            'match': u'3 February 2010 19:48 (UTC) 7 February 2010 19:48 (UTC)',
            'nomatch': u'3. 2. 2010, 19:48 (UTC) 7. 2. 2010 19:48 (UTC)',
        },
        'frwiki': {
            'family': 'wikipedia',
            'code': 'fr',
            'match': u'3 février 2010 à 19:48 (CET) 7 février 2010 à 19:48 (CET)',
            'nomatch': u'3 March 2010 19:48 (CET) 7 March 2010 19:48 (CET)',
        },
        'nowiki': {
            'family': 'wikipedia',
            'code': 'no',
            'match': u'3. feb 2010 kl. 19:48 (CET) 7. feb 2010 kl. 19:48 (UTC)',
        },
        'ptwiki': {
            'family': 'wikipedia',
            'code': 'pt',
            'match': u'19h48min de 3 de fevereiro de 2010‎ (UTC) 19h48min de 7 de fevereiro de 2010‎ (UTC)',
        },
        'viwiki': {
            'family': 'wikipedia',
            'code': 'vi',
            'match': u'19:48, ngày 15 tháng 9 năm 2008 (UTC) 19:48, ngày 7 tháng 2 năm 2010 (UTC)',
            'match2': u'16:41, ngày 15 tháng 9 năm 2008 (UTC) 16:41, ngày 12 tháng 9 năm 2008 (UTC)',
            'match3':  u'21:18, ngày 13 tháng 8 năm 2014 (UTC) 21:18, ngày 14 tháng 8 năm 2014 (UTC)',
            'nomatch1': u'21:18, ngày 13 March 8 năm 2014 (UTC) 21:18, ngày 14 March 8 năm 2014 (UTC)',
        },
    }

    cached = True

    def test_timestripper_match(self, key):
        """Test that correct date is matched."""
        self.ts = TimeStripper(self.get_site(key))

        tzone = tzoneFixedOffset(self.ts.site.siteinfo['timeoffset'],
                                 self.ts.site.siteinfo['timezone'])

        txtMatch = self.sites[key]['match']

        res = datetime.datetime(2010, 2, 7, 19, 48, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txtMatch), res)

        if 'match2' not in self.sites[key]:
            return

        txtMatch = self.sites[key]['match2']

        res = datetime.datetime(2008, 9, 12, 16, 41, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txtMatch), res)

        if 'match3' not in self.sites[key]:
            return

        txtMatch = self.sites[key]['match3']

        res = datetime.datetime(2014, 8, 14, 21, 18, tzinfo=tzone)

        self.assertEqual(self.ts.timestripper(txtMatch), res)

    def test_timestripper_nomatch(self, key):
        """Test that correct date is not matched."""
        self.ts = TimeStripper(self.get_site(key))

        if 'nomatch' in self.sites[key]:
            txtNoMatch = self.sites[key]['nomatch']
        else:
            txtNoMatch = u'3 March 2010 19:48 (UTC) 7 March 2010 19:48 (UTC)'

        self.assertEqual(self.ts.timestripper(txtNoMatch), None)

        if 'nomatch1' not in self.sites[key]:
            return

        txtNoMatch = self.sites[key]['nomatch1']
        self.assertEqual(self.ts.timestripper(txtNoMatch), None)
开发者ID:anrao91,项目名称:pywikibot-core,代码行数:91,代码来源:timestripper_tests.py


示例11: setUp

 def setUp(self):
     site = pywikibot.Site('fr', 'wikipedia')
     self.ts = TimeStripper(site)
开发者ID:zd123,项目名称:pywikibot-core,代码行数:3,代码来源:timestripper_tests.py


示例12: __init__

 def __init__(self, title, now):
     self.title = title
     self.now = now
     self.content = ""
     self.ts = TimeStripper(site=site)
     self.timestamp = None
开发者ID:blueprintmrk,项目名称:pywikibot-core,代码行数:6,代码来源:archivebot.py


示例13: setUp

 def setUp(self):
     """Set up test cases."""
     super(TestTimeStripperWithNoDigitsAsMonths, self).setUp()
     self.ts = TimeStripper(self.get_site())
开发者ID:Exal117,项目名称:pywikibot-core,代码行数:4,代码来源:timestripper_tests.py


示例14: setUp

 def setUp(self):
     """Setup a timestripper for the configured site."""
     super(TestTimeStripperWithDigitsAsMonths, self).setUp()
     self.ts = TimeStripper(self.get_site())
开发者ID:edgarskos,项目名称:pywikibot_scripts,代码行数:4,代码来源:timestripper_tests.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tools.filter_unique函数代码示例发布时间:2022-05-26
下一篇:
Python textlib.replace_links函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap