def __init__(self): from pywikibot import Site from pywikibot.config2 import register_family_file register_family_file('garoa', URL_WIKI) self.site = Site() self.page_regulares = None self.page_proximos = None self.load_Proximos_Eventos() self.load_Eventos_Regulares()
def checkFamily(self): ''' check if a family file exists and if not create it ''' iniFile = WikiUser.iniFilePath(self.wikiUser.wikiId) famfile = iniFile.replace(".ini", ".py") if not isfile(famfile): print("creating family file %s" % famfile) template = '''# -*- coding: utf-8 -*- from pywikibot import family class Family(family.Family): name = '%s' langs = { 'en': '%s', } def scriptpath(self, code): return '%s' def isPublic(self): return %s def version(self, code): return "%s" # The MediaWiki version used. Very important in most cases. (contrary to documentation) def protocol(self, code): return '%s' ''' mw_version = self.wikiUser.version.lower().replace( "mediawiki ", "") ispublic = 'False' if self.wikiUser.user is not None else 'True' code = template % (self.family, self.netloc, self.scriptPath, ispublic, mw_version, self.scheme) with open(famfile, "w") as py_file: py_file.write(code) config2.register_family_file(self.family, famfile) if self.wikiUser.user: config2.usernames[self.family]['en'] = self.wikiUser.user #config2.authenticate[self.netloc] = (self.user,self.getPassword()) self.site = pywikibot.Site('en', self.family) if self.wikiUser.user is not None: # needs patch as outlined in https://phabricator.wikimedia.org/T248471 #self.site.login(password=self.wikiUser.getPassword()) lm = LoginManager(password=self.wikiUser.getPassword(), site=self.site, user=self.wikiUser.user) lm.login()
import time import pywikibot from SPARQLWrapper import SPARQLWrapper, JSON from pywikibot import config2 import configparser app_config = configparser.ConfigParser() app_config.read('config/application.config.ini') family = 'my' mylang = 'my' familyfile=os.path.relpath("./config/my_family.py") if not os.path.isfile(familyfile): print ("family file %s is missing" % (familyfile)) config2.register_family_file(family, familyfile) config2.password_file = "user-password.py" config2.usernames['my']['my'] = app_config.get('wikibase', 'user') #connect to the wikibase wikibase = pywikibot.Site("my", "my") wikibase_repo = wikibase.data_repository() wikibase_repo.login() #connect to wikidata wikidata = pywikibot.Site("wikidata", "wikidata") wikidata_repo = wikidata.data_repository() #import an item from util.util import WikibaseImporter wikibase_importer = WikibaseImporter(wikibase_repo,wikidata_repo)
def test_register_file(): family = "projectgorgon" config2.register_family_file(family, f"{family}_family.py") main()
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # # import pywikibot from pywikibot.config2 import register_family_file URL_WIKI = "https://garoa.net.br" register_family_file('garoa', URL_WIKI) site = pywikibot.Site() class Evento: def __init__(self, line, recorrencia=False): if recorrencia: self.parse_evento_regular(line, recorrencia) else: self.parse_evento(line) def __str__(self): return self.__repr__() def __repr__(self): if self.recorrencia:
def __init__(self, *args): super(FSD, self).__init__(*args) config2.register_family_file( 'fsd', os.path.join(os.path.dirname(__file__), 'families/fsd_family.py')) self.fsd = pywikibot.Site(code="en", fam="fsd")