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


Python Weboob.get_backend方法代码示例

本文整理汇总了Python中weboob.core.Weboob.get_backend方法的典型用法代码示例。如果您正苦于以下问题:Python Weboob.get_backend方法的具体用法?Python Weboob.get_backend怎么用?Python Weboob.get_backend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weboob.core.Weboob的用法示例。


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

示例1: get_accounts

# 需要导入模块: from weboob.core import Weboob [as 别名]
# 或者: from weboob.core.Weboob import get_backend [as 别名]
def get_accounts(bname):
    w = Weboob()

    w.load_backends(names=[bname])
    backend = w.get_backend(bname)

    results = {}
    for account in backend.iter_accounts():
        # a unicode bigger than 8 characters used as key of the table make some bugs in the C++ code
        # convert to string before to use it
        results[str(account.id)] = {'name':    account.label,
                               'balance': int(account.balance * 100),
                               'type':    int(account.type),
                              }
    return results
开发者ID:CGenie,项目名称:kmymoney,代码行数:17,代码来源:weboob.py

示例2: get_transactions

# 需要导入模块: from weboob.core import Weboob [as 别名]
# 或者: from weboob.core.Weboob import get_backend [as 别名]
def get_transactions(bname, accid, maximum):
    w = Weboob()

    w.load_backends(names=[bname])
    backend = w.get_backend(bname)

    acc = backend.get_account(accid)
    results = {}
    results['id'] = acc.id
    results['name'] = acc.label
    results['balance'] = int(acc.balance * 100)
    results['type'] = int(acc.type)
    results['transactions'] = []

    try:
        count = int(maximum)
        if count < 1:
            count = 0
    except:
        count = 0
    i = 0
    first = True
    rewriteid = False
    seen = set()
    for tr in backend.iter_history(acc):
        if first:
            if tr.id == u'0' or tr.id == u'':
                rewriteid = True
            first = False
        if rewriteid:
            tr.id = tr.unique_id(seen)
        t = {'id':          tr.id,
             'date':        tr.date.strftime('%Y-%m-%d'),
             'rdate':       tr.rdate.strftime('%Y-%m-%d'),
             'type':        int(tr.type),
             'raw':         tr.raw,
             'category':    tr.category,
             'label':       tr.label,
             'amount':      int(tr.amount * 100),
        }
        results['transactions'].append(t)
        i += 1
        if count != 0 and i >= count:
            break

    return results
开发者ID:CGenie,项目名称:kmymoney,代码行数:48,代码来源:weboob.py

示例3: Downloadboob

# 需要导入模块: from weboob.core import Weboob [as 别名]
# 或者: from weboob.core.Weboob import get_backend [as 别名]
class Downloadboob(object):

    def __init__(self, backend_name, download_directory, links_directory):
        self.download_directory = download_directory
        self.links_directory = links_directory
        self.backend_name = backend_name
        self.backend = None
        self.weboob = Weboob()
        self.weboob.load_backends(modules=[self.backend_name])
        self.backend=self.weboob.get_backend(self.backend_name)

    def purge(self):
        if not os.path.isdir(self.links_directory):
            return
        dirList=os.listdir(self.links_directory)
        for local_link_name in dirList:
            link_name = self.links_directory + "/" + local_link_name
            if not self.check_link(link_name):
                print u"Remove %s" % link_name
                os.remove(link_name)
            else:
                print u"Keep %s" % link_name

    def check_link(self, link_name):
        if os.path.islink(link_name):
            file_name = os.readlink(link_name)
            absolute_file_name = os.path.join(self.links_directory, file_name)
            if os.path.isfile(absolute_file_name):
                return True
            return False
        else:
            return True

    def download(self, pattern=None, sortby=CapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None, title_exclude=[], id_regexp=None):
        print "For backend %s, search for '%s'" % (backend_name, pattern)

        # create directory for links
        print "  create link to %s" % self.links_directory
        if not os.path.isdir(self.links_directory):
            os.makedirs(self.links_directory)

        # search for videos
        videos = []
        for i, video in enumerate(self.backend.search_videos(pattern, sortby, nsfw)):
            if i == max_results:
                break

            if not self.is_downloaded(video):
                self.backend.fill_video(video, ('url','title', 'url', 'duration'))
                if not(self.is_excluded(video.title, title_exclude)) and self.id_regexp_matched(video.id, id_regexp):
                    print "  %s\n    Id:%s\n    Duration:%s" % (video.title, video.id, video.duration)
                    videos.append(video)
            else:
                print "Already downloaded, check %s" % video.id
                self.backend.fill_video(video, ('url','title', 'url', 'duration'))
                linkname = self.get_linkname(video)
                if not os.path.exists(linkname):
                    self.remove_download(video)

        # download videos
        print "Downloading..."
        for video in videos:
            self.do_download(video)

    def is_excluded(self, title, title_exclude):
        for exclude in title_exclude:
            if title.find(exclude) > -1:
                return True
        return False

    def id_regexp_matched(self, video_id, id_regexp):
        if id_regexp:
            return re.search(id_regexp, video_id) is not None
        return True

    def get_filename(self, video, relative=False):
        if relative:
            directory = os.path.join("..", DOWNLOAD_DIRECTORY, self.backend_name)
        else:
            directory = os.path.join(self.download_directory, self.backend_name)
            if not os.path.exists(directory):
                os.makedirs(directory)

        ext = video.ext
        if not ext:
            ext = 'avi'

        return u"%s/%s.%s" % (directory, removeNonAscii(video.id), ext)

    def get_linkname(self, video):
        if not os.path.exists(self.links_directory):
            os.makedirs(self.links_directory)

        ext = video.ext
        if not ext:
            ext = 'avi'

        misc = video.date
        if not misc:
            misc = video.id
#.........这里部分代码省略.........
开发者ID:juliaL03,项目名称:weboob,代码行数:103,代码来源:downloadboob.py

示例4: DownloadBoob

# 需要导入模块: from weboob.core import Weboob [as 别名]
# 或者: from weboob.core.Weboob import get_backend [as 别名]
class DownloadBoob(object):
    """
        Search and download
        :param name:
        :param backend_name:
        :param my_download_directory:
        :param my_links_directory:
    """

    def __init__(self, name, backend_name, my_download_directory,
                 my_links_directory):
        self.download_directory = my_download_directory
        self.links_directory = my_links_directory
        self.backend_name = backend_name
        self.backend = None
        self.weboob = Weboob()
        self.weboob.load_backends(modules=self.backend_name, )
        self.backend = self.weboob.get_backend(self.backend_name)
        self.name = name

    def get_filename(self, video, relative=False, m3u=False):
        """
            Generate filename for the video
            :param relative:
            :param m3u:
            :param video:
            :rtype : string
        """
        if relative:
            directory = os.path.join("..", DOWNLOAD_DIRECTORY,
                                     self.backend_name)
        else:
            directory = os.path.join(self.download_directory, self.backend_name)
            if not os.path.exists(directory.encode('utf8')):
                os.makedirs(directory.encode('utf8'))
        if not m3u:
            ext = video.ext
            if not ext:
                ext = 'avi'
        else:
            ext = 'm3u'
        return "%s/%s.%s" % (directory, removenonascii(video.id), ext)

    def get_linkname(self, video, m3u=False):
        """
            Generate filename for the link
            :param m3u:
            :param video:
            :rtype : string
        """
        if not os.path.exists(self.links_directory.encode('utf8')):
            os.makedirs(self.links_directory.encode('utf8'))
        if not m3u:
            ext = video.ext
            if not ext:
                ext = 'avi'
        else:
            ext = 'm3u'
        if not kodi:
            misc = video.date.strftime("%y-%m-%d")
            if not misc:
                misc = video.id
            return "%s/%s (%s).%s" % (self.links_directory,
                                      removespecial(video.title),
                                      removespecial(misc), ext)
        else:
            return "%s/%s.%s" % (self.links_directory,
                                 removespecial(video.title), ext)

    def is_downloaded(self, video):
        """
            Check if the video has already been downloaded
            :param video:
            :rtype : bool
        """
        if (os.path.isfile(self.get_filename(video).encode('utf8')) or
            os.path.isfile(self.get_filename(video,
                                             m3u=True).encode('utf8'))):
            logging.info("%s Already downloaded : %s" %
                         (video.id, video.title))
            return True
        logging.debug("%s To be downloaded : %s" %
                      (video.id, video.title))
        return False

    def init_dir(self):
        """
            create directory
        """
        if not os.path.isdir(self.links_directory.encode('utf8')):
            logging.debug("  create link directory : %s" % self.links_directory)
            os.makedirs(self.links_directory.encode('utf8'))
        else:
            logging.debug("  existing link directory : %s" % self.links_directory)
        if kodi:
            file_name = os.path.join(self.links_directory, 'tvshow.nfo')
            show_name = self.links_directory.split("/")[-1]
            if not os.path.isfile(file_name.encode('utf8')):
                logging.debug("  create %s" % file_name)
                f = codecs.open(file_name, "w", "utf-8")
#.........这里部分代码省略.........
开发者ID:jmpoux,项目名称:downloadboob,代码行数:103,代码来源:downloadboob_downloader.py


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