print("Hello stroopwafels")
Hello stroopwafels
import pywikibot #tell python that we will be using pywikibot
site=pywikibot.Site('wikidata','wikidata') #Identify the site we will use
repo=site.data_repository()                #Identify the repository
wd = pywikibot.ItemPage(repo, 'Q56095936') #Identify the wanted object in WikiData
wd.get()                                   #Get the information for the object
print('%s' % wd.labels)
print('%s' % wd.descriptions['nl'])        # Gives the description in Dutch
                                           # Raises an exception if not existing
{'nl': 'Wiki Techstorm', 'en': 'Wiki Techstorm', 'fr': 'Wiki Techstorm', 'de': 'Wiki Techstorm'}
Wikimedia Hackaton
import pywikibot #tell python that we will be using pywikibot
site=pywikibot.Site('wikidata','wikidata') #Identify the site we will use
repo=site.data_repository()                #Identify the repository
wd = pywikibot.ItemPage(repo, 'Q56095936') #Identify the wanted object in WikiData
wd.get()                                   #Get the information for the object
print('%s' % wd.labels)
print('%s' % wd.descriptions['nl'])        # Gives the description in Dutch
                                           # Raises an exception if not existing
print('%s' % wd.sitelinks)
{'nl': 'Wiki Techstorm', 'en': 'Wiki Techstorm', 'fr': 'Wiki Techstorm', 'de': 'Wiki Techstorm'}
Wikimedia Hackaton
{'mediawikiwiki': 'Wiki Techstorm'}
import pywikibot                            # Tell python that we will be using pywikibot
site=pywikibot.Site('nl', 'wikipedia')       # Identify the site we will use
pagename = 'User talk:%s' % site.username() # Testing, so use your bots own talk page
page = pywikibot.Page(site, pagename)       # Retrieve the current page
text = page.text                            # Retrieve the current text, which we'll change
text += '\n== Happy hacking ==\n'           # Add text. \n tells to add a newline to the text, so the content will be on different lines 
                                            # NB: in Wikicode, doesn't mean it will be so in the shown content.
text += 'Let\'s do some Python exercise. ~~~~\n'
page.text = text                            # update the text in the page object in memory
page.save ('I\'m trying to use Python and Pywikibot')  #save everything to the page
Sleeping for 9.0 seconds, 2018-10-26 09:33:06
Page [[nl:Overleg gebruiker:IlonkaDP]] saved
import pywikibot
from pywikibot import pagegenerators as pg
def list_template_usage(site_obj, tmpl_name):
    name = "{}:{}".format(site_obj.namespace(10), tmpl_name)
    tmpl_page = pywikibot.Page(site_obj, name)
    ref_gen = pg.ReferringPageGenerator(tmpl_page, onlyTemplateInclusion=True)
    filter_gen = pg.NamespaceFilterPageGenerator(ref_gen, namespaces=[0])
    generator = site_obj.preloadpages(filter_gen, pageprops=True)
    return generator
site = pywikibot.Site("nl", 'wikipedia')
tmpl_gen = list_template_usage(site, "Infobox meteorietinslag")
for page in tmpl_gen:
    print(page.title())
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-9-187deca1ef93> in <module>()
     10 site = pywikibot.Site("nl", 'wikipedia')
     11 tmpl_gen = list_template_usage(site, "Infobox meteorietinslag")
---> 12 for page in tmpl_gen:
     13     print(page.title())

/srv/paws/pwb/pywikibot/site.py in preloadpages(self, pagelist, groupsize, templates, langlinks, pageprops)
   3370         rvprop = ['ids', 'flags', 'timestamp', 'user', 'comment', 'content']
   3371 
-> 3372         for sublist in itergroup(pagelist, groupsize):
   3373             # Do not use p.pageid property as it will force page loading.
   3374             pageids = [str(p._pageid) for p in sublist

/srv/paws/pwb/pywikibot/tools/__init__.py in itergroup(iterable, size)
    918     """
    919     group = []
--> 920     for item in iterable:
    921         group.append(item)
    922         if len(group) == size:

/srv/paws/pwb/pywikibot/pagegenerators.py in NamespaceFilterPageGenerator(generator, namespaces, site)
   1697         site = pywikibot.Site()
   1698     try:
-> 1699         namespaces = site.namespaces.resolve(namespaces)
   1700     except KeyError as e:
   1701         pywikibot.log('Failed resolving namespaces:')

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

/srv/paws/pwb/pywikibot/site.py in _build_namespaces(self)
   2643         # For versions lower than 1.14, APISite needs to override
   2644         # the defaults defined in Namespace.
-> 2645         is_mw114 = self.mw_version >= '1.14'
   2646 
   2647         for nsdata in self.siteinfo.get('namespaces', cache=False).values():

/srv/paws/pwb/pywikibot/site.py in mw_version(self)
   2777         mw_ver, cache_time = getattr(self, '_mw_version_time', (None, None))
   2778         if mw_ver is None or time.time() - cache_time > 60 * 60 * 24:
-> 2779             mw_ver = MediaWikiVersion(self.version())
   2780             setattr(self, '_mw_version_time', (mw_ver, time.time()))
   2781         return mw_ver

/srv/paws/pwb/pywikibot/site.py in version(self)
   2760             try:
   2761                 version = self.siteinfo.get('generator',
-> 2762                                             expiry=1).split(' ')[1]
   2763             except pywikibot.data.api.APIError:
   2764                 # May occur if you are not logged in (no API read permissions).

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

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

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

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2426         cached_available = self._load_cache()
   2427         if not cached_available:
-> 2428             self._data = super(CachedRequest, self).submit()
   2429             self._write_cache(self._data)
   2430         else:

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

NoUsername: Failed OAuth authentication for wikipedia:test: The authorization headers in your request are for a user that does not exist here
import pywikibot                            # Tell python that we will be using pywikibot
site=pywikibot.Site('nl', 'wiki.marc-one-retailing.com')       # Identify the site we will use
pagename = 'User talk:%s' % site.username() # Testing, so use your bots own talk page
page = pywikibot.Page(site, pagename)       # Retrieve the current page
text = page.text                            # Retrieve the current text, which we'll change
text += '\n== Happy hacking ==\n'           # Add text. \n tells to add a newline to the text, so the content will be on different lines 
                                            # NB: in Wikicode, doesn't mean it will be so in the shown content.
text += 'Let\'s do some Python exercise. User:IduPree\n'
page.text = text                            # update the text in the page object in memory
page.save ('I\'m trying to use Python and Pywikibot')  #save everything to the page
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-12-950c2b9c012f> in <module>()
      1 import pywikibot                            # Tell python that we will be using pywikibot
----> 2 site=pywikibot.Site('nl', 'wiki.marc-one-retailing.com')       # Identify the site we will use
      3 pagename = 'User talk:%s' % site.username() # Testing, so use your bots own talk page
      4 page = pywikibot.Page(site, pagename)       # Retrieve the current page
      5 text = page.text                            # Retrieve the current text, which we'll change

/srv/paws/pwb/pywikibot/__init__.py in Site(code, fam, user, sysop, interface, url)
   1238 
   1239         if not isinstance(fam, Family):
-> 1240             fam = Family.load(fam)
   1241 
   1242     interface = interface or fam.interface(code)

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

/srv/paws/pwb/pywikibot/family.py in load(fam)
    974 
    975         assert all(x in NAME_CHARACTERS for x in fam), \
--> 976             'Name of family %s must be ASCII characters and digits' % fam
    977 
    978         if fam in Family._families:

AssertionError: Name of family wiki.marc-one-retailing.com must be ASCII characters and digits
import pywikibot
from pywikibot import pagegenerators as pg
def list_template_usage(site_obj, tmpl_name):
    name = "{}:{}".format(site_obj.namespace(10), tmpl_name)
    tmpl_page = pywikibot.Page(site_obj, name)
    ref_gen = pg.ReferringPageGenerator(tmpl_page, onlyTemplateInclusion=True)
    filter_gen = pg.NamespaceFilterPageGenerator(ref_gen, namespaces=[0])
    generator = site_obj.preloadpages(filter_gen, pageprops=True)
    return generator
site = pywikibot.Site("nl", 'wikipedia')
tmpl_gen = list_template_usage(site, "Infobox meteorietinslag")
for page in tmpl_gen:
    print(page.title()), len(list(page.backlinks())))
  File "<ipython-input-13-8ec116a57cfd>", line 13
    print(page.title()), len(list(page.backlinks())))
                                                    ^
SyntaxError: invalid syntax
import pywikibot
from pywikibot import pagegenerators as pg
def list_template_usage(site_obj, tmpl_name):
    name = "{}:{}".format(site_obj.namespace(10), tmpl_name)
    tmpl_page = pywikibot.Page(site_obj, name)
    ref_gen = pg.ReferringPageGenerator(tmpl_page, onlyTemplateInclusion=True)
    filter_gen = pg.NamespaceFilterPageGenerator(ref_gen, namespaces=[0])
    generator = site_obj.preloadpages(filter_gen, pageprops=True)
    return generator
site = pywikibot.Site("nl", 'wikipedia')
tmpl_gen = list_template_usage(site, "Infobox meteorietinslag")
for page in tmpl_gen:
# This way we count all incoming links, keeping them available for later usage
    countbacklinks=0
    for backlinks in page.backlinks():
            countbacklinks += 1
    if countbacklinks > 0:
            print(page.title(), countbacklinks)
# Less code, but consumes all objects in the list
    print (page.title(), len(list(page.backlinks())))
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-14-5e316db7b9a6> in <module>()
     10 site = pywikibot.Site("nl", 'wikipedia')
     11 tmpl_gen = list_template_usage(site, "Infobox meteorietinslag")
---> 12 for page in tmpl_gen:
     13 # This way we count all incoming links, keeping them available for later usage
     14     countbacklinks=0

/srv/paws/pwb/pywikibot/site.py in preloadpages(self, pagelist, groupsize, templates, langlinks, pageprops)
   3370         rvprop = ['ids', 'flags', 'timestamp', 'user', 'comment', 'content']
   3371 
-> 3372         for sublist in itergroup(pagelist, groupsize):
   3373             # Do not use p.pageid property as it will force page loading.
   3374             pageids = [str(p._pageid) for p in sublist

/srv/paws/pwb/pywikibot/tools/__init__.py in itergroup(iterable, size)
    918     """
    919     group = []
--> 920     for item in iterable:
    921         group.append(item)
    922         if len(group) == size:

/srv/paws/pwb/pywikibot/pagegenerators.py in NamespaceFilterPageGenerator(generator, namespaces, site)
   1697         site = pywikibot.Site()
   1698     try:
-> 1699         namespaces = site.namespaces.resolve(namespaces)
   1700     except KeyError as e:
   1701         pywikibot.log('Failed resolving namespaces:')

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

/srv/paws/pwb/pywikibot/site.py in _build_namespaces(self)
   2643         # For versions lower than 1.14, APISite needs to override
   2644         # the defaults defined in Namespace.
-> 2645         is_mw114 = self.mw_version >= '1.14'
   2646 
   2647         for nsdata in self.siteinfo.get('namespaces', cache=False).values():

/srv/paws/pwb/pywikibot/site.py in mw_version(self)
   2777         mw_ver, cache_time = getattr(self, '_mw_version_time', (None, None))
   2778         if mw_ver is None or time.time() - cache_time > 60 * 60 * 24:
-> 2779             mw_ver = MediaWikiVersion(self.version())
   2780             setattr(self, '_mw_version_time', (mw_ver, time.time()))
   2781         return mw_ver

/srv/paws/pwb/pywikibot/site.py in version(self)
   2760             try:
   2761                 version = self.siteinfo.get('generator',
-> 2762                                             expiry=1).split(' ')[1]
   2763             except pywikibot.data.api.APIError:
   2764                 # May occur if you are not logged in (no API read permissions).

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

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

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

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2426         cached_available = self._load_cache()
   2427         if not cached_available:
-> 2428             self._data = super(CachedRequest, self).submit()
   2429             self._write_cache(self._data)
   2430         else:

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

NoUsername: Failed OAuth authentication for wikipedia:test: The authorization headers in your request are for a user that does not exist here
import pywikibot                            # Tell python that we will be using pywikibot
site=pywikibot.Site('nl', 'wikipedia')       # Identify the site we will use
pagename = 'User talk:%s' % site.username() # Testing, so use your bots own talk page
page = pywikibot.Page(site, pagename)       # Retrieve the current page
text = page.text                            # Retrieve the current text, which we'll change
text += '\n== Happy hacking ==\n'           # Add text. \n tells to add a newline to the text, so the content will be on different lines 
                                            # NB: in Wikicode, doesn't mean it will be so in the shown content.
text += 'Let\Nog effe een testje om te kijken hoe het werkt. ~~~~\n'
page.text = text                            # update the text in the page object in memory
page.save ('I\'m trying to use Python and Pywikibot')  #save everything to the page
  File "<ipython-input-15-0114922fad3b>", line 8
    text += 'Let\Nog effe een testje om te kijken hoe het werkt. ~~~~\n'
           ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 3-4: malformed \N character escape
import pywikibot                            # Tell python that we will be using pywikibot
site=pywikibot.Site('nl', '109 097 114 099 045 111 110 101 045 114 101 116 097 105 108 105 110 103')       # Identify the site we will use
pagename = 'User talk:%s' % IduPree() # Testing, so use your bots own talk page
page = pywikibot.Page(site, pagename)       # Retrieve the current page
text = page.text                            # Retrieve the current text, which we'll change
text += '\n== Happy hacking oefening ==\n'           # Add text. \n tells to add a newline to the text, so the content will be on different lines 
                                            # NB: in Wikicode, doesn't mean it will be so in the shown content.
text += 'Let\'s do some Python oefening. ~~~~\n'
page.text = text                            # update the text in the page object in memory
page.save ('I\'m trying to use Python and Pywikibot')  #save everything to the page
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-19-b8b3d7420888> in <module>()
      1 import pywikibot                            # Tell python that we will be using pywikibot
----> 2 site=pywikibot.Site('nl', '109 097 114 099 045 111 110 101 045 114 101 116 097 105 108 105 110 103')       # Identify the site we will use
      3 pagename = 'User talk:%s' % IduPree() # Testing, so use your bots own talk page
      4 page = pywikibot.Page(site, pagename)       # Retrieve the current page
      5 text = page.text                            # Retrieve the current text, which we'll change

/srv/paws/pwb/pywikibot/__init__.py in Site(code, fam, user, sysop, interface, url)
   1238 
   1239         if not isinstance(fam, Family):
-> 1240             fam = Family.load(fam)
   1241 
   1242     interface = interface or fam.interface(code)

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

/srv/paws/pwb/pywikibot/family.py in load(fam)
    974 
    975         assert all(x in NAME_CHARACTERS for x in fam), \
--> 976             'Name of family %s must be ASCII characters and digits' % fam
    977 
    978         if fam in Family._families:

AssertionError: Name of family 109 097 114 099 045 111 110 101 045 114 101 116 097 105 108 105 110 103 must be ASCII characters and digits
import pywikibot
from pywikibot import pagegenerators as pg
def list_template_usage(site_obj, tmpl_name):
    name = "{}:{}".format(site_obj.namespace(10), tmpl_name)
    tmpl_page = pywikibot.Page(site_obj, name)
    ref_gen = pg.ReferringPageGenerator(tmpl_page, onlyTemplateInclusion=True)
    filter_gen = pg.NamespaceFilterPageGenerator(ref_gen, namespaces=[0])
    generator = site_obj.preloadpages(filter_gen, pageprops=True)
    return generator
site = pywikibot.Site("nl", 'wikipedia')
tmpl_gen = list_template_usage(site, "Infobox meteorietinslag")
for page in tmpl_gen:
    print(page.title())
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-20-187deca1ef93> in <module>()
     10 site = pywikibot.Site("nl", 'wikipedia')
     11 tmpl_gen = list_template_usage(site, "Infobox meteorietinslag")
---> 12 for page in tmpl_gen:
     13     print(page.title())

/srv/paws/pwb/pywikibot/site.py in preloadpages(self, pagelist, groupsize, templates, langlinks, pageprops)
   3370         rvprop = ['ids', 'flags', 'timestamp', 'user', 'comment', 'content']
   3371 
-> 3372         for sublist in itergroup(pagelist, groupsize):
   3373             # Do not use p.pageid property as it will force page loading.
   3374             pageids = [str(p._pageid) for p in sublist

/srv/paws/pwb/pywikibot/tools/__init__.py in itergroup(iterable, size)
    918     """
    919     group = []
--> 920     for item in iterable:
    921         group.append(item)
    922         if len(group) == size:

/srv/paws/pwb/pywikibot/pagegenerators.py in NamespaceFilterPageGenerator(generator, namespaces, site)
   1697         site = pywikibot.Site()
   1698     try:
-> 1699         namespaces = site.namespaces.resolve(namespaces)
   1700     except KeyError as e:
   1701         pywikibot.log('Failed resolving namespaces:')

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

/srv/paws/pwb/pywikibot/site.py in _build_namespaces(self)
   2643         # For versions lower than 1.14, APISite needs to override
   2644         # the defaults defined in Namespace.
-> 2645         is_mw114 = self.mw_version >= '1.14'
   2646 
   2647         for nsdata in self.siteinfo.get('namespaces', cache=False).values():

/srv/paws/pwb/pywikibot/site.py in mw_version(self)
   2777         mw_ver, cache_time = getattr(self, '_mw_version_time', (None, None))
   2778         if mw_ver is None or time.time() - cache_time > 60 * 60 * 24:
-> 2779             mw_ver = MediaWikiVersion(self.version())
   2780             setattr(self, '_mw_version_time', (mw_ver, time.time()))
   2781         return mw_ver

/srv/paws/pwb/pywikibot/site.py in version(self)
   2760             try:
   2761                 version = self.siteinfo.get('generator',
-> 2762                                             expiry=1).split(' ')[1]
   2763             except pywikibot.data.api.APIError:
   2764                 # May occur if you are not logged in (no API read permissions).

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

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

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

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2426         cached_available = self._load_cache()
   2427         if not cached_available:
-> 2428             self._data = super(CachedRequest, self).submit()
   2429             self._write_cache(self._data)
   2430         else:

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

NoUsername: Failed OAuth authentication for wikipedia:test: The authorization headers in your request are for a user that does not exist here