当前位置: 首页>>代码示例>>Python>>正文


Python config.datafilepath函数代码示例

本文整理汇总了Python中pywikibot.config.datafilepath函数的典型用法代码示例。如果您正苦于以下问题:Python datafilepath函数的具体用法?Python datafilepath怎么用?Python datafilepath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了datafilepath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: refresh

def refresh(site, sysop=False):
    """Fetch the watchlist."""
    if not site.logged_in(sysop=sysop):
        site.forceLogin(sysop=sysop)

    params = {
        'action': 'query',
        'list': 'watchlistraw',
        'site': site,
        'wrlimit': config.special_page_limit,
    }

    pywikibot.output(u'Retrieving watchlist for %s via API.' % str(site))
    # pywikibot.put_throttle() # It actually is a get, but a heavy one.
    watchlist = []
    while True:
        req = pywikibot.data.api.Request(**params)
        data = req.submit()
        if 'error' in data:
            raise RuntimeError('ERROR: %s' % data)
        watchlist.extend([w['title'] for w in data['watchlistraw']])

        if 'query-continue' in data:
            params.update(data['query-continue']['watchlistraw'])
        else:
            break

    # Save the watchlist to disk
    # The file is stored in the watchlists subdir. Create if necessary.
    with open(config.datafilepath('watchlists',
                                  'watchlist-%s-%s%s.dat'
                                  % (site.family.name, site.code,
                                     '-sysop' if sysop else '')),
              'wb') as f:
        pickle.dump(watchlist, f)
开发者ID:anrao91,项目名称:pywikibot-core,代码行数:35,代码来源:watchlist.py

示例2: __init__

    def __init__(self, site, mindelay=None, maxdelay=None, writedelay=None,
                 multiplydelay=True):
        """Constructor."""
        self.lock = threading.RLock()
        self.mysite = str(site)
        self.ctrlfilename = config.datafilepath('throttle.ctrl')
        self.mindelay = mindelay
        if self.mindelay is None:
            self.mindelay = config.minthrottle
        self.maxdelay = maxdelay
        if self.maxdelay is None:
            self.maxdelay = config.maxthrottle
        self.writedelay = writedelay
        if self.writedelay is None:
            self.writedelay = config.put_throttle
        self.last_read = 0
        self.last_write = 0
        self.next_multiplicity = 1.0

        # Check logfile again after this many seconds:
        self.checkdelay = 300

        # Ignore processes that have not made a check in this many seconds:
        self.dropdelay = 600

        # Free the process id after this many seconds:
        self.releasepid = 1200

        self.lastwait = 0.0
        self.delay = 0
        self.checktime = 0
        self.multiplydelay = multiplydelay
        if self.multiplydelay:
            self.checkMultiplicity()
        self.setDelays()
开发者ID:AbdealiJK,项目名称:pywikibot-core,代码行数:35,代码来源:throttle.py

示例3: __init__

 def __init__(self, rebuild=False, filename="category.dump.bz2"):
     """Constructor."""
     if not os.path.isabs(filename):
         filename = config.datafilepath(filename)
     self.filename = filename
     if rebuild:
         self.rebuild()
开发者ID:emijrp,项目名称:pywikibot-core,代码行数:7,代码来源:category.py

示例4: dump

    def dump(self, filename=None):
        """Save the dictionaries to disk if not empty.

        Pickle the contents of the dictionaries superclassDB and catContentDB
        if at least one is not empty. If both are empty, removes the file from
        the disk.

        If the filename is None, it'll use the filename determined in __init__.
        """
        if filename is None:
            filename = self.filename
        elif not os.path.isabs(filename):
            filename = config.datafilepath(filename)
        if self.is_loaded and (self.catContentDB or self.superclassDB):
            pywikibot.output("Dumping to %s, please wait..." % config.shortpath(filename))
            f = bz2.BZ2File(filename, "w")
            databases = {"catContentDB": self.catContentDB, "superclassDB": self.superclassDB}
            # store dump to disk in binary format
            try:
                pickle.dump(databases, f, protocol=config.pickle_protocol)
            except pickle.PicklingError:
                pass
            f.close()
        else:
            try:
                os.remove(filename)
            except EnvironmentError:
                pass
            else:
                pywikibot.output("Database is empty. %s removed" % config.shortpath(filename))
开发者ID:emijrp,项目名称:pywikibot-core,代码行数:30,代码来源:category.py

示例5: dump

    def dump(self, filename='category.dump.bz2'):
        '''Saves the contents of the dictionaries superclassDB and catContentDB
        to disk.

        '''
        if not os.path.isabs(filename):
            filename = config.datafilepath(filename)
        if self.catContentDB or self.superclassDB:
            pywikibot.output(u'Dumping to %s, please wait...'
                             % config.shortpath(filename))
            f = bz2.BZ2File(filename, 'w')
            databases = {
                'catContentDB': self.catContentDB,
                'superclassDB': self.superclassDB
            }
            # store dump to disk in binary format
            try:
                pickle.dump(databases, f, protocol=pickle.HIGHEST_PROTOCOL)
            except pickle.PicklingError:
                pass
            f.close()
        else:
            try:
                os.remove(filename)
            except EnvironmentError:
                pass
            else:
                pywikibot.output(u'Database is empty. %s removed'
                                 % config.shortpath(filename))
开发者ID:iamedwardshen,项目名称:pywikibot-core,代码行数:29,代码来源:category.py

示例6: get

def get(site=None):
    """Load the watchlist, fetching it if necessary."""
    if site is None:
        site = pywikibot.Site()
    if site in cache:
        # Use cached copy if it exists.
        watchlist = cache[site]
    else:
        fn = config.datafilepath('watchlists',
                                 'watchlist-%s-%s.dat'
                                 % (site.family.name, site.code))
        try:
            # find out how old our saved dump is (in seconds)
            file_age = time.time() - os.path.getmtime(fn)
            # if it's older than 1 month, reload it
            if file_age > 30 * 24 * 60 * 60:
                pywikibot.output(
                    u'Copy of watchlist is one month old, reloading')
                refresh(site)
        except OSError:
            # no saved watchlist exists yet, retrieve one
            refresh(site)
        with open(fn, 'rb') as f:
            watchlist = pickle.load(f)
        # create cached copy
        cache[site] = watchlist
    return watchlist
开发者ID:anrao91,项目名称:pywikibot-core,代码行数:27,代码来源:watchlist.py

示例7: __init__

    def __init__(self, disambPage, enabled=False):
        self.disambPage = disambPage
        self.enabled = enabled
        self.ignorelist = []

        folder = config.datafilepath('disambiguations')
        if os.path.exists(folder):
            self._read_ignorelist(folder)
开发者ID:emijrp,项目名称:pywikibot-core,代码行数:8,代码来源:solve_disambiguation.py

示例8: __init__

 def __init__(self, catTitle, catDB, filename=None, maxDepth=10):
     self.catTitle = catTitle
     self.catDB = catDB
     if filename and not os.path.isabs(filename):
         filename = config.datafilepath(filename)
     self.filename = filename
     self.maxDepth = maxDepth
     self.site = pywikibot.Site()
开发者ID:legoktm,项目名称:pywikibot-core,代码行数:8,代码来源:category.py

示例9: __init__

 def __init__(self, catTitle, catDB, filename=None, maxDepth=10):
     self.catTitle = catTitle
     self.catDB = catDB
     if filename and not os.path.isabs(filename):
         filename = config.datafilepath(filename)
     self.filename = filename
     # TODO: make maxDepth changeable with a parameter or config file entry
     self.maxDepth = maxDepth
     self.site = pywikibot.getSite()
开发者ID:iamedwardshen,项目名称:pywikibot-core,代码行数:9,代码来源:category.py

示例10: ignore

 def ignore(self, refPage):
     if self.enabled:
         # Skip this occurrence next time.
         filename = config.datafilepath(
             'disambiguations',
             self.disambPage.title(asUrl=True) + '.txt')
         try:
             # Open file for appending. If none exists yet, create a new one.
             f = codecs.open(filename, 'a', 'utf-8')
             f.write(refPage.title(asUrl=True) + '\n')
             f.close()
         except IOError:
             pass
开发者ID:donkaban,项目名称:pywiki-bot,代码行数:13,代码来源:solve_disambiguation.py

示例11: storecookiedata

    def storecookiedata(self, data):
        """
        Store cookie data.

        The argument data is the raw data, as returned by getCookie().

        Returns nothing.
        """
        # THIS IS OVERRIDDEN IN data/api.py
        filename = config.datafilepath("pywikibot.lwp")
        pywikibot.debug(u"Storing cookies to %s" % filename, _logger)
        f = open(filename, "w")
        f.write(data)
        f.close()
开发者ID:pywikibot,项目名称:core-migration-example,代码行数:14,代码来源:login.py

示例12: __init__

    def __init__(self, disambPage, enabled=False):
        """Constructor.

        @type disambPage: pywikibot.Page
        @type enabled: bool
        @rtype: None

        """
        self.disambPage = disambPage
        self.enabled = enabled
        self.ignorelist = []

        folder = config.datafilepath('disambiguations')
        if os.path.exists(folder):
            self._read_ignorelist(folder)
开发者ID:hasteur,项目名称:g13bot_tools_new,代码行数:15,代码来源:solve_disambiguation.py

示例13: __init__

    def __init__(self, disambPage, enabled=False):
        self.disambPage = disambPage
        self.enabled = enabled

        self.ignorelist = []
        filename = config.datafilepath(
            'disambiguations',
            self.disambPage.title(as_filename=True) + '.txt')
        try:
            # The file is stored in the disambiguation/ subdir.
            # Create if necessary.
            f = codecs.open(filename, 'r', 'utf-8')
            for line in f.readlines():
                # remove trailing newlines and carriage returns
                while line[-1] in ['\n', '\r']:
                    line = line[:-1]
                # skip empty lines
                if line != '':
                    self.ignorelist.append(line)
            f.close()
        except IOError:
            pass
开发者ID:donkaban,项目名称:pywiki-bot,代码行数:22,代码来源:solve_disambiguation.py

示例14: refresh_all

def refresh_all(new=False, sysop=False):
    """Fetch and locally cache several watchlists."""
    if new:
        pywikibot.output(
            'Downloading all watchlists for your accounts in user-config.py')
        for family in config.usernames:
            for lang in config.usernames[family]:
                refresh(pywikibot.Site(lang, family), sysop=sysop)
        for family in config.sysopnames:
            for lang in config.sysopnames[family]:
                refresh(pywikibot.Site(lang, family), sysop=sysop)

    else:
        import dircache
        filenames = dircache.listdir(
            config.datafilepath('watchlists'))
        watchlist_filenameR = re.compile('watchlist-([a-z\-:]+).dat')
        for filename in filenames:
            match = watchlist_filenameR.match(filename)
            if match:
                arr = match.group(1).split('-')
                family = arr[0]
                lang = '-'.join(arr[1:])
                refresh(pywikibot.Site(lang, family))
开发者ID:anrao91,项目名称:pywikibot-core,代码行数:24,代码来源:watchlist.py

示例15: _load_file

    #
    'fckeditor': {
        'regex': True,
        'msg': 'pywikibot-fixes-fckeditor',
        'replacements': [
            # replace <br> with a new line
            (r'(?i)<br>',                      r'\n'),
            # replace &nbsp; with a space
            (r'(?i)&nbsp;',                      r' '),
        ],
    },
}


def _load_file(filename):
    """Load the fixes from the given filename."""
    if os.path.exists(filename):
        # load binary, to let compile decode it according to the file header
        with open(filename, 'rb') as f:
            exec(compile(f.read(), filename, 'exec'))
        return True
    else:
        return False

#
# Load the user fixes file.
if _load_file(config.datafilepath('user-fixes.py')):
    user_fixes_loaded = True
else:
    user_fixes_loaded = False
开发者ID:TridevGuha,项目名称:pywikibot-core,代码行数:30,代码来源:fixes.py


注:本文中的pywikibot.config.datafilepath函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。