pynzb


Namepynzb JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttp://github.com/ericflo/pynzb/tree/master
Summarypynzb is a unified API for parsing NZB files, with several concrete implementations included
upload_time2009-05-11 08:14:43
maintainer
docs_urlNone
authorEric Florenzano
requires_pythonNone
licenseBSD
keywords nzb parser xml
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Introduction
------------

NZB is an XML-based file format for retrieving posts from NNTP (Usenet) 
servers.
Since NZB is XML-based, it's relatively easy to build one-off parsers to parse
NZB files.  This project is an attempt to consolidate those many one-off NZB
parsers into one simple interface.

This package includes three implementations: one based on expat, another 
based
on ElementTree, and a final implementation based on lxml.  The order in which
they were listed is in order of compatibility.  The expat version should work on
all versions of Python > 2.0, the lxml one will work on all versions > 2.5, and
lxml will only work if you have lxml installed.


A Note on Installing lxml
-------------------------

While lxml is not a requirement, I have had a hard time installing lxml in the
past.  I have found this set of commands to work perfectly::

    STATIC_DEPS=true easy_install 'lxml>=2.2beta4'
    STATIC_DEPS=true sudo easy_install 'lxml>=2.2beta4'


API Documentation
-----------------


Accessing the Default Parser
============================

Simply import nzb_parser from the pynzb package.  It's an instantiated version
of the fastest available parser that your system can support.


Other Parser Locations
======================

``ExpatNZBParser``:
    Available in the ``pynzb.expat_nzb`` namespace.

``ETreeNZBParser``:
    Available in the ``pynzb.etree_nzb`` namespace.

``LXMLNZBParser``:
    Available in the ``pynzb.lxml_nzb`` namespace.


Using the NZB Parser
====================

If you're using a specific parser, like the ``ETreeNZBParser``, you will first
have to instantiate it::

    nzb_parser = ETreeNZBParser()


Otherwise, you can just import the default parser for your system::

    from pynzb import nzb_parser


Then, simply call the ``parse`` method, giving it the xml string as the only
argument::

    files = nzb_parser.parse('<?xml ... my nzb file here ... </nzb>')


This will return a list of ``NZBFiles`` for you to use.


NZBFile Objects
===============

All of the parsers return ``NZBFile`` objects, which are objects with the
following properties:

``poster``:
    The name of the user who posted the file to the newsgroup.

``date``:
    A ``datetime.date`` representation of when the server first saw the file.

``subject``:
    The subject used when the user posted the file to the newsgroup.

``groups``:
    A list of strings representing the newsgroups in which this file may be
    found.

``segments``:
    A list of ``NZBSegment`` objects talking about where to get the contents
    of this file.


NZBSegment Objects
==================

Each ``NZBFile`` has a list of ``NZBSegment`` objects, which include 
information
on how to retrieve a part of a file.  Here's what you can find on an
``NZBSegment`` object:

``number``:
    The number of the segment in the list of files.

``bytes``:
    The size of the segment, in bytes.

``message_id``:
    The Message-ID of the segment (useful for retrieving the full contents)


Example
--------

In this example, we will grab an Ubuntu NZB and parse the file, printing out
some information about each file and its segments::

    from pynzb import nzb_parser
    from urllib2 import urlopen

    # Grab a sample Ubuntu NZB
    ubuntu_nzb = urlopen('http://media.eflorenzano.com/misc/sample-ubuntu-
nzb.nzb').read()

    # Parse the NZB into files
    files = nzb_parser.parse(ubuntu_nzb)

    # Print out each file's subject and the first two segment message ids
    for nzb_file in files:
        print nzb_file.subject
        for segment in nzb_file.segments[:2]:
            print '    ' + segment.message_id
        if len(nzb_file.segments) > 2:
            print '    ...'
            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/ericflo/pynzb/tree/master",
    "name": "pynzb",
    "maintainer": "",
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": "",
    "keywords": "nzb,parser,xml",
    "author": "Eric Florenzano",
    "author_email": "floguy@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b1/90/b71ca66e2fee3f46281b3ecc853abe407a5ecd0cb4898af5bab48af63590/pynzb-0.1.0.tar.gz",
    "platform": "UNKNOWN",
    "description": "Introduction\r\n------------\r\n\r\nNZB is an XML-based file format for retrieving posts from NNTP (Usenet) \r\nservers.\r\nSince NZB is XML-based, it's relatively easy to build one-off parsers to parse\r\nNZB files.  This project is an attempt to consolidate those many one-off NZB\r\nparsers into one simple interface.\r\n\r\nThis package includes three implementations: one based on expat, another \r\nbased\r\non ElementTree, and a final implementation based on lxml.  The order in which\r\nthey were listed is in order of compatibility.  The expat version should work on\r\nall versions of Python > 2.0, the lxml one will work on all versions > 2.5, and\r\nlxml will only work if you have lxml installed.\r\n\r\n\r\nA Note on Installing lxml\r\n-------------------------\r\n\r\nWhile lxml is not a requirement, I have had a hard time installing lxml in the\r\npast.  I have found this set of commands to work perfectly::\r\n\r\n    STATIC_DEPS=true easy_install 'lxml>=2.2beta4'\r\n    STATIC_DEPS=true sudo easy_install 'lxml>=2.2beta4'\r\n\r\n\r\nAPI Documentation\r\n-----------------\r\n\r\n\r\nAccessing the Default Parser\r\n============================\r\n\r\nSimply import nzb_parser from the pynzb package.  It's an instantiated version\r\nof the fastest available parser that your system can support.\r\n\r\n\r\nOther Parser Locations\r\n======================\r\n\r\n``ExpatNZBParser``:\r\n    Available in the ``pynzb.expat_nzb`` namespace.\r\n\r\n``ETreeNZBParser``:\r\n    Available in the ``pynzb.etree_nzb`` namespace.\r\n\r\n``LXMLNZBParser``:\r\n    Available in the ``pynzb.lxml_nzb`` namespace.\r\n\r\n\r\nUsing the NZB Parser\r\n====================\r\n\r\nIf you're using a specific parser, like the ``ETreeNZBParser``, you will first\r\nhave to instantiate it::\r\n\r\n    nzb_parser = ETreeNZBParser()\r\n\r\n\r\nOtherwise, you can just import the default parser for your system::\r\n\r\n    from pynzb import nzb_parser\r\n\r\n\r\nThen, simply call the ``parse`` method, giving it the xml string as the only\r\nargument::\r\n\r\n    files = nzb_parser.parse('<?xml ... my nzb file here ... </nzb>')\r\n\r\n\r\nThis will return a list of ``NZBFiles`` for you to use.\r\n\r\n\r\nNZBFile Objects\r\n===============\r\n\r\nAll of the parsers return ``NZBFile`` objects, which are objects with the\r\nfollowing properties:\r\n\r\n``poster``:\r\n    The name of the user who posted the file to the newsgroup.\r\n\r\n``date``:\r\n    A ``datetime.date`` representation of when the server first saw the file.\r\n\r\n``subject``:\r\n    The subject used when the user posted the file to the newsgroup.\r\n\r\n``groups``:\r\n    A list of strings representing the newsgroups in which this file may be\r\n    found.\r\n\r\n``segments``:\r\n    A list of ``NZBSegment`` objects talking about where to get the contents\r\n    of this file.\r\n\r\n\r\nNZBSegment Objects\r\n==================\r\n\r\nEach ``NZBFile`` has a list of ``NZBSegment`` objects, which include \r\ninformation\r\non how to retrieve a part of a file.  Here's what you can find on an\r\n``NZBSegment`` object:\r\n\r\n``number``:\r\n    The number of the segment in the list of files.\r\n\r\n``bytes``:\r\n    The size of the segment, in bytes.\r\n\r\n``message_id``:\r\n    The Message-ID of the segment (useful for retrieving the full contents)\r\n\r\n\r\nExample\r\n--------\r\n\r\nIn this example, we will grab an Ubuntu NZB and parse the file, printing out\r\nsome information about each file and its segments::\r\n\r\n    from pynzb import nzb_parser\r\n    from urllib2 import urlopen\r\n\r\n    # Grab a sample Ubuntu NZB\r\n    ubuntu_nzb = urlopen('http://media.eflorenzano.com/misc/sample-ubuntu-\r\nnzb.nzb').read()\r\n\r\n    # Parse the NZB into files\r\n    files = nzb_parser.parse(ubuntu_nzb)\r\n\r\n    # Print out each file's subject and the first two segment message ids\r\n    for nzb_file in files:\r\n        print nzb_file.subject\r\n        for segment in nzb_file.segments[:2]:\r\n            print '    ' + segment.message_id\r\n        if len(nzb_file.segments) > 2:\r\n            print '    ...'",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "pynzb is a unified API for parsing NZB files, with several concrete implementations included",
    "version": "0.1.0",
    "project_urls": {
        "Download": "UNKNOWN",
        "Homepage": "http://github.com/ericflo/pynzb/tree/master"
    },
    "split_keywords": [
        "nzb",
        "parser",
        "xml"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b190b71ca66e2fee3f46281b3ecc853abe407a5ecd0cb4898af5bab48af63590",
                "md5": "63c74a36348ac28aa99732dcb8be8c59",
                "sha256": "0735b3889a1174bbb65418ee503629d3f5e4a63f04b16f46ffba18253ec3ef17"
            },
            "downloads": -1,
            "filename": "pynzb-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "63c74a36348ac28aa99732dcb8be8c59",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5598,
            "upload_time": "2009-05-11T08:14:43",
            "upload_time_iso_8601": "2009-05-11T08:14:43.592352Z",
            "url": "https://files.pythonhosted.org/packages/b1/90/b71ca66e2fee3f46281b3ecc853abe407a5ecd0cb4898af5bab48af63590/pynzb-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2009-05-11 08:14:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ericflo",
    "github_project": "pynzb",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pynzb"
}
        
Elapsed time: 0.79026s