import pywikibot as pw
from pywikibot import pagegenerators as pg
import re
wikidata = pw.Site('wikidata', 'wikidata')
c = pw.Site('commons', 'commons')
print(c)
ruwiki = pw.Site('ru', 'wikipedia')
hywiki = pw.Site('hy', 'wikipedia')

cat = pw.Category(hywiki, "Category:Հայաստան") 
catgen = pg.CategorizedPageGenerator(cat, recurse=True)
for page in catgen:
    print(page)
    if not (page.title(with_ns=False) == page.title()):
        continue
    item = pw.ItemPage.fromPage(page, lazy_load=True)
    add = False
    if item.exists():
        try:
            item.getSitelink(ruwiki)
        except:
            add = True
    else:
        add = True
    if add and page.text.count('<ref') >=2:
        print(page)
commons:commons
[[hy:2010 թվականը Հայաստանում]]
[[hy:2010 թվականը Հայաստանում]]
[[hy:2012 թվականը Հայաստանում]]
[[hy:2012 թվականը Հայաստանում]]
[[hy:2013 թվականը Հայաստանում]]
[[hy:2013 թվականը Հայաստանում]]
[[hy:Մասնակից:Nooberella/Հայաստանի ղեկավարների ցանկ]]
[[hy:Արիմ]]
[[hy:Հայ-հարավկորեական հարաբերություններ]]
WARNING: API error mwoauth-invalid-authorization-invalid-user: The authorization headers in your request are for a user that does not exist here
---------------------------------------------------------------------------
NoUsername                                Traceback (most recent call last)
<ipython-input-13-44dd4d52e2c4> in <module>
     16     item = pw.ItemPage.fromPage(page, lazy_load=True)
     17     add = False
---> 18     if item.exists():
     19         try:
     20             item.getSitelink(ruwiki)

/srv/paws/pwb/pywikibot/page.py in exists(self)
   3884         if not hasattr(self, '_content'):
   3885             try:
-> 3886                 self.get(get_redirect=True)
   3887                 return True
   3888             except pywikibot.NoPage:

/srv/paws/pwb/pywikibot/page.py in get(self, force, get_redirect, *args, **kwargs)
   4481         @raise NotImplementedError: a value in args or kwargs
   4482         """
-> 4483         data = super(ItemPage, self).get(force, *args, **kwargs)
   4484 
   4485         if self.isRedirectPage() and not get_redirect:

/srv/paws/pwb/pywikibot/page.py in get(self, force, *args, **kwargs)
   3974                 self.claims[pid] = []
   3975                 for claim in self._content['claims'][pid]:
-> 3976                     c = Claim.fromJSON(self.repo, claim)
   3977                     c.on_item = self
   3978                     self.claims[pid].append(c)

/srv/paws/pwb/pywikibot/page.py in fromJSON(cls, site, data)
   4941             if claim.type in cls.types or claim.type == 'wikibase-property':
   4942                 claim.target = cls.TARGET_CONVERTER.get(
-> 4943                     claim.type, lambda value, site: value)(value, site)
   4944             else:
   4945                 pywikibot.warning(

/srv/paws/pwb/pywikibot/page.py in <lambda>(value, site)
   4849             PropertyPage(site, 'P' + str(value['numeric-id'])),
   4850         'commonsMedia': lambda value, site:
-> 4851             FilePage(pywikibot.Site('commons', 'commons'), value),  # T90492
   4852         'globe-coordinate': pywikibot.Coordinate.fromWikibase,
   4853         'geo-shape': pywikibot.WbGeoShape.fromWikibase,

/srv/paws/pwb/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1736                              cls, depth)
   1737                     del __kw[old_arg]
-> 1738             return obj(*__args, **__kw)
   1739 
   1740         if not __debug__:

/srv/paws/pwb/pywikibot/page.py in __init__(self, source, title)
   2450         """Initializer."""
   2451         self._file_revisions = {}  # dictionary to cache File history.
-> 2452         super(FilePage, self).__init__(source, title, 6)
   2453         if self.namespace() != 6:
   2454             raise ValueError("'%s' is not in the file namespace!" % title)

/srv/paws/pwb/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1736                              cls, depth)
   1737                     del __kw[old_arg]
-> 1738             return obj(*__args, **__kw)
   1739 
   1740         if not __debug__:

/srv/paws/pwb/pywikibot/page.py in __init__(self, source, title, ns)
   2299                 raise ValueError('Title must be specified and not empty '
   2300                                  'if source is a Site.')
-> 2301         super(Page, self).__init__(source, title, ns)
   2302 
   2303     @property

/srv/paws/pwb/pywikibot/page.py in __init__(self, source, title, ns)
    192 
    193         if isinstance(source, pywikibot.site.BaseSite):
--> 194             self._link = Link(title, source=source, default_namespace=ns)
    195             self._revisions = {}
    196         elif isinstance(source, Page):

/srv/paws/pwb/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1736                              cls, depth)
   1737                     del __kw[old_arg]
-> 1738             return obj(*__args, **__kw)
   1739 
   1740         if not __debug__:

/srv/paws/pwb/pywikibot/page.py in __init__(self, text, source, default_namespace)
   5563         # See bug T104864, default_namespace might have been deleted.
   5564         try:
-> 5565             self._defaultns = self._source.namespaces[default_namespace]
   5566         except KeyError:
   5567             self._defaultns = default_namespace

/srv/paws/pwb/pywikibot/site.py in namespaces(self)
   1018         """Return dict of valid namespaces on this wiki."""
   1019         if not hasattr(self, '_namespaces'):
-> 1020             self._namespaces = NamespacesDict(self._build_namespaces())
   1021         return self._namespaces
   1022 

/srv/paws/pwb/pywikibot/site.py in _build_namespaces(self)
   2638         _namespaces = {}
   2639 
-> 2640         for nsdata in self.siteinfo.get('namespaces', cache=False).values():
   2641             ns = nsdata.pop('id')
   2642             custom_name = None

/srv/paws/pwb/pywikibot/site.py in get(self, key, get_default, cache, expiry)
   1668                 elif not Siteinfo._is_expired(cached[1], expiry):
   1669                     return copy.deepcopy(cached[0])
-> 1670         preloaded = self._get_general(key, expiry)
   1671         if not preloaded:
   1672             preloaded = self._get_siteinfo(key, expiry)[key]

/srv/paws/pwb/pywikibot/site.py in _get_general(self, key, expiry)
   1614                     .format("', '".join(props)), _logger)
   1615             props += ['general']
-> 1616             default_info = self._get_siteinfo(props, expiry)
   1617             for prop in props:
   1618                 self._cache[prop] = default_info[prop]

/srv/paws/pwb/pywikibot/site.py in _get_siteinfo(self, prop, expiry)
   1537         request._warning_handler = warn_handler
   1538         try:
-> 1539             data = request.submit()
   1540         except api.APIError as e:
   1541             if e.code == 'siunknown_siprop':

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2232         cached_available = self._load_cache()
   2233         if not cached_available:
-> 2234             self._data = super(CachedRequest, self).submit()
   2235             self._write_cache(self._data)
   2236         else:

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2059                     continue
   2060                 raise NoUsername('Failed OAuth authentication for %s: %s'
-> 2061                                  % (self.site, info))
   2062             if code == 'cirrussearch-too-busy-error':  # T170647
   2063                 self.wait()

NoUsername: Failed OAuth authentication for commons:commons: The authorization headers in your request are for a user that does not exist here
import pywikibot as pw
from pywikibot import pagegenerators as pg
import re

hywiki = pw.Site('hy', 'wikipedia')
cat = pw.Category(hywiki, "Կատեգորիա:Վիքիպեդիա:CEE Spring 2019 համագործակցության հոդվածներ (մասնակից՝ )")
catgen = pg.CategorizedPageGenerator(cat, recurse=False)
for talkPage in catgen:
    page = pw.Page(hywiki, talkPage.title().replace('Քննարկում:', ''))
    if page.oldest_revision['timestamp'].year == 2019:
        talkPage.text = re.sub(r'\{\{ *CEE Spring 2019 *\|', '{{CEE Spring 2019 | մասնակից = ' + page.oldest_revision['user'] + '|', talkPage.text)
        talkPage.save(summary='+' + page.oldest_revision['user'])
Sleeping for 7.6 seconds, 2019-08-14 20:21:30
Page [[hy:Քննարկում:Ագրարային բանկի շենք]] saved
Sleeping for 9.2 seconds, 2019-08-14 20:21:38
Page [[hy:Քննարկում:Ադամ Բոդոր]] saved
Sleeping for 9.2 seconds, 2019-08-14 20:21:48
Page [[hy:Քննարկում:Ադամ Մատուշչիկ]] saved
Sleeping for 9.2 seconds, 2019-08-14 20:21:58
Page [[hy:Քննարկում:Ադամ Միցկևիչի հուշարձան (Լվով)]] saved
Sleeping for 9.3 seconds, 2019-08-14 20:22:08
Page [[hy:Քննարկում:Ադամ և Խեվա]] saved
Sleeping for 9.2 seconds, 2019-08-14 20:22:18
Page [[hy:Քննարկում:Ադել Ալ-Հադադ]] saved
Sleeping for 9.2 seconds, 2019-08-14 20:22:28
Page [[hy:Քննարկում:Ադիգամ Իսկուժին]] saved
Sleeping for 9.1 seconds, 2019-08-14 20:22:38
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-1-1bfb9f3c3262> in <module>
     10     if page.oldest_revision['timestamp'].year == 2019:
     11         talkPage.text = re.sub(r'\{\{ *CEE Spring 2019 *\|', '{{CEE Spring 2019 | մասնակից = ' + page.oldest_revision['user'] + '|', talkPage.text)
---> 12         talkPage.save(summary='+' + page.oldest_revision['user'])

/srv/paws/pwb/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1736                              cls, depth)
   1737                     del __kw[old_arg]
-> 1738             return obj(*__args, **__kw)
   1739 
   1740         if not __debug__:

/srv/paws/pwb/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1736                              cls, depth)
   1737                     del __kw[old_arg]
-> 1738             return obj(*__args, **__kw)
   1739 
   1740         if not __debug__:

/srv/paws/pwb/pywikibot/page.py in save(self, summary, watch, minor, botflag, force, asynchronous, callback, apply_cosmetic_changes, quiet, **kwargs)
   1280         self._save(summary=summary, watch=watch, minor=minor, botflag=botflag,
   1281                    asynchronous=asynchronous, callback=callback,
-> 1282                    cc=apply_cosmetic_changes, quiet=quiet, **kwargs)
   1283 
   1284     @allow_asynchronous

/srv/paws/pwb/pywikibot/page.py in wrapper(self, *args, **kwargs)
    126             pywikibot.async_request(handle, func, self, *args, **kwargs)
    127         else:
--> 128             handle(func, self, *args, **kwargs)
    129 
    130     manage_wrapping(wrapper, func)

/srv/paws/pwb/pywikibot/page.py in handle(func, self, *args, **kwargs)
    105         err = None
    106         try:
--> 107             func(self, *args, **kwargs)
    108         # TODO: other "expected" error types to catch?
    109         except pywikibot.Error as edit_err:

/srv/paws/pwb/pywikibot/page.py in _save(self, summary, watch, minor, botflag, cc, quiet, **kwargs)
   1291 
   1292         done = self.site.editpage(self, summary=summary, minor=minor,
-> 1293                                   watch=watch, bot=botflag, **kwargs)
   1294         if not done:
   1295             if not quiet:

/srv/paws/pwb/pywikibot/site.py in callee(self, *args, **kwargs)
   1318             else:
   1319                 raise Exception('Not implemented')
-> 1320             return fn(self, *args, **kwargs)
   1321 
   1322         if not __debug__:

/srv/paws/pwb/pywikibot/site.py in editpage(self, page, summary, minor, notminor, bot, recreate, createonly, nocreate, watch, **kwargs)
   5265             while True:
   5266                 try:
-> 5267                     result = req.submit()
   5268                     pywikibot.debug('editpage response: %s' % result,
   5269                                     _logger)

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   1975 
   1976             if self.throttle:
-> 1977                 self.site.throttle(write=self.write)
   1978             else:
   1979                 pywikibot.log(

/srv/paws/pwb/pywikibot/throttle.py in __call__(self, requestsize, write)
    276             self.next_multiplicity = math.log(1 + requestsize) / math.log(2.0)
    277 
--> 278             self.wait(wait)
    279 
    280             if write:

/srv/paws/pwb/pywikibot/throttle.py in wait(self, seconds)
    254             pywikibot.log(message)
    255 
--> 256         time.sleep(seconds)
    257 
    258     def __call__(self, requestsize=1, write=False):

KeyboardInterrupt: