def test_addSingleClaim(self):
        '''
        Check adding claims + sources to wikidata sandbox item = Q4115189
        claim property id='p351' value=5649
        First login to wikidata,add claim,check claim added or not
        '''
        import pywikibot
        from pywikibot.data import api
        assert len(settings.wikidata_user) != 0
        assert len(settings.wikidata_password) != 0
        base_site = pywikibot.Site(code=settings.Code_site,
                                   fam=settings.Code_site,
                                   user=settings.wikidata_user)
        Wrepo = base_site.data_repository()
        assert api.LoginManager(
            site=base_site,
            user=settings.wikidata_user,
            password=settings.wikidata_password).login() == True

        item = pywikibot.ItemPage(Wrepo, 'Q4115189')
        item.get()
        claim = pywikibot.Claim(Wrepo, 'P351')
        claim.setTarget('5649')

        sourceItem = pywikibot.ItemPage(Wrepo, 'Q1345229')
        source = pywikibot.Claim(Wrepo, unicode('P143'))  #imported from
        source.setTarget(sourceItem)
        assert api.LoginManager(
            site=base_site,
            user=settings.wikidata_user,
            password=settings.wikidata_password).login() == True
        item.addClaim(claim, bot=True)
        claim.addSource(source)
        #check claim has been added or not
        item = pywikibot.ItemPage(Wrepo, 'Q4115189')
        claims = item.get().get('claims')
        total = len(claims['P351'])

        assert claims['P351'][int(total) - 1].getTarget() == '5649'
Esempio n. 2
0
 def test_Login(self):
     '''
     Check login to wikidata
     '''
     import pywikibot
     from pywikibot.data import api
     assert len(settings.wikidata_user) != 0
     assert len(settings.wikidata_password) != 0
     base_site = pywikibot.Site(code=settings.Code_site,
                                fam=settings.Code_site)
     assert api.LoginManager(
         site=base_site,
         user=settings.wikidata_user,
         password=settings.wikidata_password).login() == True
Esempio n. 3
0
 def __init__(self):
     '''login to wikidata '''
     self.base_site = pywikibot.Site(code=self.code_site,
                                     fam=self.family,
                                     user=None,
                                     sysop=None,
                                     interface=None)
     #fam = family
     #sysop = system operator
     #TO-DO  After getting bot flag, update login here by using sysop
     api.LoginManager(site=self.base_site,
                      user=settings.wikidata_user,
                      password=settings.wikidata_password).login()
     #self.base_site.login()
     self.data_repo = self.base_site.data_repository()
Esempio n. 4
0
def login(site, username, password, sysop=False, retry=True):
    site._loginStatus = LoginStatus.IN_PROGRESS
    if hasattr(site, "_userinfo"):
        del site._userinfo

    loginMan = api.LoginManager(site=site, sysop=sysop,
                         user=username, password=password)

    if loginMan.login(retry):
        site._username[sysop] = loginMan.username
        if hasattr(site, "_userinfo"):
            del site._userinfo
        site.getuserinfo()
        site._loginstatus = (LoginStatus.AS_SYSOP if sysop else LoginStatus.AS_USER)
        return True
    else:
        site._loginstatus = LoginStatus.NOT_LOGGED_IN
        return False
Esempio n. 5
0
def login(self, sysop=False):
	print "hihi"
	"""Log the user in if not already logged in."""
        # check whether a login cookie already exists for this user
        self._loginstatus = LoginStatus.IN_PROGRESS
        if hasattr(self, "_userinfo"):
            del self._userinfo
        self.getuserinfo()
	print self.userinfo['name']
	print self._username[sysop]
	print self.logged_in(sysop)
#        if self.userinfo['name'] == self._username[sysop] and \
#           self.logged_in(sysop):
#            return
        loginMan = api.LoginManager(site=self, sysop=sysop,
                                    user=self._username[sysop])
        if loginMan.password is None:
		print "none"
        print "'" + loginMan.password + "'"
Esempio n. 6
0
 def login(self):
     site = pywikibot.Site("test", "wikidata", "FLOSSbotCI")
     api.LoginManager(site=site,
                      user="******",
                      password="******").login()