Example #1
0
 def test_xml(self):
     ws = WikiStats()
     data = ws.get_dict('wikisource', 'xml')
     self.assertIsInstance(data, dict)
     self.assertIn('en', data)
     self.assertIn('id', data)
     self.assertGreater(int(data['fr']['total']), 1600000)
Example #2
0
    def test_sort_numeric(self):
        """Test sorted results."""
        keys = ('good', 'prefix', 'total')

        ws = WikiStats()
        data = ws.sorted('wikipedia', 'total')
        top = data[0]
        bottom = data[-1]

        for key in keys:
            with self.subTest(key=key):
                self.assertIn(key, top)
                self.assertIn(key, bottom)

        self.assertTrue(all(isinstance(key, str)
                            for key in top.keys()
                            if key is not None))
        self.assertIsInstance(top['good'], str)
        self.assertIsInstance(top['total'], str)
        self.assertIsInstance(bottom['good'], str)
        self.assertIsInstance(bottom['total'], str)

        self.assertGreater(int(top['total']), int(bottom['good']))
        self.assertGreater(int(top['good']), int(bottom['good']))
        self.assertGreater(int(top['total']), int(bottom['total']))
 def test_xml(self):
     ws = WikiStats()
     data = ws.get_dict('wikisource', 'xml')
     self.assertIsInstance(data, dict)
     self.assertIn('en', data)
     self.assertIn('id', data)
     self.assertGreater(int(data['fr']['total']), 1600000)
Example #4
0
 def test_csv(self):
     if not csv:
         raise unittest.SkipTest('unicodecsv not installed.')
     ws = WikiStats()
     data = ws.get_dict('wikipedia', 'csv')
     self.assertIsInstance(data, dict)
     self.assertIn('en', data)
     self.assertIn('ht', data)
     self.assertGreater(int(data['en']['total']), 4000000)
     data = ws.get_dict
Example #5
0
 def test_sort(self):
     ws = WikiStats()
     data = ws.sorted('wikipedia', 'total')
     top = data[0]
     self.assertIn('prefix', top)
     self.assertIn('total', top)
     self.assertEqual(top['prefix'], 'en')
     self.assertIsInstance(top['total'], basestring)
     self.assertEqual(ws.languages_by_size('wikipedia')[0], 'en')
     self.assertEqual(ws.languages_by_size('wikisource')[0], 'fr')
 def test_sort(self):
     ws = WikiStats()
     data = ws.sorted('wikipedia', 'total')
     top = data[0]
     self.assertIn('prefix', top)
     self.assertIn('total', top)
     self.assertEqual(top['prefix'], 'en')
     self.assertIsInstance(top['total'], basestring)
     self.assertEqual(ws.languages_by_size('wikipedia')[0], 'en')
     self.assertEqual(ws.languages_by_size('wikisource')[0], 'fr')
 def test_csv(self):
     if not csv:
         raise unittest.SkipTest('unicodecsv not installed.')
     ws = WikiStats()
     data = ws.get_dict('wikipedia', 'csv')
     self.assertIsInstance(data, dict)
     self.assertIn('en', data)
     self.assertIn('ht', data)
     self.assertGreater(int(data['en']['total']), 4000000)
     data = ws.get_dict
 def test_sort(self):
     """Test sorted results."""
     ws = WikiStats()
     data = ws.sorted('wikipedia', 'total')
     top = data[0]
     self.assertIn('prefix', top)
     self.assertIn('total', top)
     self.assertEqual(top['prefix'], 'en')
     self.assertIsInstance(top['total'], UnicodeType)
     self.assertEqual(ws.languages_by_size('wikipedia')[0], 'en')
     self.assertEqual(ws.languages_by_size('wikisource')[0], 'fr')
 def test_sort(self):
     """Test sorted results."""
     ws = WikiStats()
     data = ws.sorted('wikipedia', 'total')
     top = data[0]
     self.assertIn('prefix', top)
     self.assertIn('total', top)
     self.assertEqual(top['prefix'], 'en')
     self.assertIsInstance(top['total'], UnicodeType)
     self.assertEqual(ws.languages_by_size('wikipedia')[0], 'en')
     self.assertEqual(ws.languages_by_size('wikisource')[0], 'fr')
Example #10
0
 def test_sort_alphabetic(self):
     """Test alphabetic sorted results."""
     ws = WikiStats()
     for reverse in (True, False):
         last = ' ~'[reverse]  # first and last printable ASCII
         data = ws.sorted('wikisource', 'prefix', reverse=reverse)
         with self.subTest(reverse=reverse):
             for entry in data:
                 code = entry['prefix']
                 if reverse:
                     self.assertGreater(last, code)
                 else:
                     self.assertLess(last, code)
                 last = code
Example #11
0
 def test_sorting_order(self):
     """Test sorting order of languages_by_size."""
     family = 'wikipedia'
     ws = WikiStats()
     data = ws.get_dict(family)
     last = sys.maxsize
     last_code = ''
     for code in ws.languages_by_size(family):
         curr = int(data[code]['good'])
         self.assertGreaterEqual(
             last, curr, '{} ({}) is greater than {} ({}).'.format(
                 code, curr, last_code, last))
         last = curr
         last_code = code
Example #12
0
 def test_wikisource(self):
     """Test WikiStats wikisource data content."""
     ws = WikiStats()
     data = ws.get_dict('wikisource')
     self.assertIsInstance(data, dict)
     self.assertIn('en', data)
     self.assertIn('id', data)
     self.assertGreater(int(data['fr']['total']), int(data['fr']['good']))
     data = data['fr']
     self.assertTrue(all(isinstance(key, str)
                         for key in data.keys() if key is not None))
     self.assertIsInstance(data['total'], str)
     self.assertIn('prefix', data)
     self.assertIn('total', data)
 def test_xml(self):
     """Test XML."""
     ws = WikiStats()
     data = ws.get_dict('wikisource', 'xml')
     self.assertIsInstance(data, dict)
     self.assertIn('en', data)
     self.assertIn('id', data)
     self.assertGreater(int(data['fr']['total']), int(data['fr']['good']))
     data = data['fr']
     self.assertTrue(all(isinstance(key, UnicodeType)
                         for key in data.keys()
                         if key is not None))
     self.assertIsInstance(data['total'], UnicodeType)
     self.assertIn('prefix', data)
     self.assertIn('total', data)
 def test_sorting_order(self):
     """Test sorting order of languages_by_size."""
     FAMILY = 'wikipedia'
     ws = WikiStats()
     data = ws.get_dict(FAMILY)
     last = sys.maxsize
     last_code = ''
     for code in ws.languages_by_size(FAMILY):
         curr = int(data[code]['good'])
         self.assertGreaterEqual(
             last, curr,
             '{0} ({1}) is greater than {2} ({3}).'
             ''.format(code, curr, last_code, last))
         last = curr
         last_code = code
Example #15
0
def main():

    ws = WikiStats()

    stats = ws.sorted('wikipedia', 'good')

    # rimuove mo.wikipedia.org redirect a ro.wikipedia.org

    stats = [stat for stat in stats if stat['prefix'] != 'mo']

    now = datetime.datetime.now()

    text = u'<!-- یہاں نئی زبان شامل کرنے سے قبل تبادلہ خیال صفحہ پر گفتگو کر لیں۔ -->\n<onlyinclude>{{#switch:{{{1}}}\n'

    text += '| data = %d %s %d\n' % (now.day, date.formats['MonthName']['ur'](
        now.month), now.year)

    total = {
        'good': 0,
        'images': 0,
        'total': 0,
        'users': 0,
        'activeusers': 0,
        'admins': 0,
        'edits': 0
    }

    for stat in stats:

        text += formatStat(stat)

        for key in total:

            total[key] += int(stat[key])

    total['prefix'] = 'total'

    text += formatStat(total)

    text += u'| 0 }}</onlyinclude>\n<noinclude>\n{{دستاویز}}\n</noinclude>\n'

    pywikibot.handleArgs()

    site = pywikibot.Site()

    page = pywikibot.Page(site, 'Template:NUMBEROF/data')

    page.put(text, 'خودکار: تجدید شماریات')
Example #16
0
 def test_xml(self):
     """Test XML."""
     ws = WikiStats()
     data = ws.get_dict('wikisource', 'xml')
     self.assertIsInstance(data, dict)
     self.assertIn('en', data)
     self.assertIn('id', data)
     self.assertGreater(int(data['fr']['total']), int(data['fr']['good']))
     data = data['fr']
     self.assertTrue(
         all(
             isinstance(key, UnicodeType) for key in data.keys()
             if key is not None))
     self.assertIsInstance(data['total'], UnicodeType)
     self.assertIn('prefix', data)
     self.assertIn('total', data)
Example #17
0
 def test_csv(self):
     """Test CSV."""
     ws = WikiStats()
     data = ws.get_dict('wikipedia', 'csv')
     self.assertIsInstance(data, dict)
     self.assertIn('en', data)
     self.assertIn('ht', data)
     self.assertGreater(int(data['en']['total']), int(data['en']['good']))
     data = data['en']
     self.assertTrue(
         all(
             isinstance(key, str) for key in data.keys()
             if key is not None))
     self.assertIsInstance(data['total'], str)
     self.assertIn('prefix', data)
     self.assertIn('total', data)
 def test_csv(self):
     """Test CSV."""
     if not csv:
         raise unittest.SkipTest('unicodecsv not installed.')
     ws = WikiStats()
     data = ws.get_dict('wikipedia', 'csv')
     self.assertIsInstance(data, dict)
     self.assertIn('en', data)
     self.assertIn('ht', data)
     self.assertGreater(int(data['en']['total']), int(data['en']['good']))
     data = data['en']
     self.assertTrue(all(isinstance(key, UnicodeType)
                         for key in data.keys()
                         if key is not None))
     self.assertIsInstance(data['total'], UnicodeType)
     self.assertIn('prefix', data)
     self.assertIn('total', data)
Example #19
0
 def test_csv(self):
     """Test CSV."""
     if not csv:
         raise unittest.SkipTest('unicodecsv not installed.')
     ws = WikiStats()
     data = ws.get_dict('wikipedia', 'csv')
     self.assertIsInstance(data, dict)
     self.assertIn('en', data)
     self.assertIn('ht', data)
     self.assertGreater(int(data['en']['total']), int(data['en']['good']))
     data = data['en']
     self.assertTrue(
         all(
             isinstance(key, UnicodeType) for key in data.keys()
             if key is not None))
     self.assertIsInstance(data['total'], UnicodeType)
     self.assertIn('prefix', data)
     self.assertIn('total', data)
 def test_sort(self):
     """Test sorted results."""
     ws = WikiStats()
     data = ws.sorted('wikipedia', 'total')
     top = data[0]
     bottom = data[-1]
     self.assertIn('good', top)
     self.assertIn('prefix', top)
     self.assertIn('total', top)
     self.assertIn('good', bottom)
     self.assertIn('prefix', bottom)
     self.assertIn('total', bottom)
     self.assertIsInstance(top['good'], UnicodeType)
     self.assertTrue(all(isinstance(key, UnicodeType)
                         for key in top.keys()
                         if key is not None))
     self.assertIsInstance(top['total'], UnicodeType)
     self.assertIsInstance(bottom['good'], UnicodeType)
     self.assertIsInstance(bottom['total'], UnicodeType)
     self.assertGreater(int(top['total']), int(bottom['good']))
     self.assertGreater(int(top['good']), int(bottom['good']))
     self.assertGreater(int(top['total']), int(bottom['total']))
Example #21
0
 def test_sort(self):
     """Test sorted results."""
     ws = WikiStats()
     data = ws.sorted('wikipedia', 'total')
     top = data[0]
     bottom = data[-1]
     self.assertIn('good', top)
     self.assertIn('prefix', top)
     self.assertIn('total', top)
     self.assertIn('good', bottom)
     self.assertIn('prefix', bottom)
     self.assertIn('total', bottom)
     self.assertIsInstance(top['good'], UnicodeType)
     self.assertTrue(
         all(
             isinstance(key, UnicodeType) for key in top.keys()
             if key is not None))
     self.assertIsInstance(top['total'], UnicodeType)
     self.assertIsInstance(bottom['good'], UnicodeType)
     self.assertIsInstance(bottom['total'], UnicodeType)
     self.assertGreater(int(top['total']), int(bottom['good']))
     self.assertGreater(int(top['good']), int(bottom['good']))
     self.assertGreater(int(top['total']), int(bottom['total']))