コード例 #1
0
ファイル: NZBcli.py プロジェクト: dbsr/NZBcli
def main(query, param_dict):
    # Make sure we got a clean config file
    try:
        nzbcli.read_config(args)
    except NZBCliError, e:
        prettystd.err(msg="{cfgError}! {e}\n".format(cfgError='{cfgError}',
                                                     e=e),
                      format_dict={'cfgError': 'NZBCliError'},
                      indent=0,
                      newline=True)
        return 1
コード例 #2
0
ファイル: NZBcli.py プロジェクト: dbsr/NZBcli
def _validate_choice(raw_choice, len_results):
    # Make sure choices are valid
    if raw_choice == 'A' or raw_choice == 'a':
        return range(0, len_results)
    elif raw_choice == 'N' or raw_choice == 'n':
        return 'N'
    elif re.match(r'^[0-9,-]+$', raw_choice):
        # split str into single digits and ranges. Note: I bet someone
        # smart would use an iterator here. 8)
        digits = []

        for digit in raw_choice.split(','):
            # make sure its a digit, its in the result range and
            # unique. Also, should we correct possible typos or raise
            # an Exception as soon as we find an invalid digit range?
            if (re.match(r'^[0-9]+$', digit)
                    and int(digit) in range(0, len_results + 1)
                    and int(digit) not in digits):
                digits.append(int(digit))
            elif re.match(r'[0-9]+-[0-9]+', digit):
                d_range = digit.split('-')
                if re.match(r'[0-9]+', (d_range[0] + d_range[1])):
                    if int(d_range[0]) < int(d_range[1]):
                        for d in range(int(d_range[0]), int(d_range[1]) + 1):
                            if (int(d) not in digits
                                    and int(d) in range(0, len_results + 1)):
                                digits.append(int(d))

        if len(digits) != 0:
            return digits

    # Only invalid entries should end up here
    prettystd.err(msg='{error}: Invalid choice, please {try} again.',
                  format_dict={
                      'error': 'Error',
                      'try': 'try'
                  },
                  indent=1,
                  newline=True)
    return None
コード例 #3
0
ファイル: NZBcli.py プロジェクト: dbsr/NZBcli
    prettystd.out(
        msg=
        "{indent} Starting NZB search for '{query}' (category: {category}).",
        format_dict={
            'indent': '>',
            'query': query,
            'category': args['category']
        },
        indent=0)
    # Query the newznab provider
    try:
        results = newznab.do_query(query=query, category=args['category'])
    except NZBCliError:
        prettystd.err(
            msg="-> {title}... :(",
            format_dict={'title': 'no results'},
            indent=1,
        )
        return 1
    # Present results and get download targets
    print results
    download_list = _present_results(results)

    if download_list is None:
        return

    # Retrieve nzburls using the rss api from nzbindex.nl
    for url in nzbindex.get_links(download_list):
        # Print success/fail
        if url['url']:
            success = 'OK!'