Source

noor / noortxt.py

#!/usr/bin/env python
import sys
import textwrap

from noor import uihelpers


def write_aya(text, number=None, sajda=None, translation=None, juz_start=None):
    result = []
    if juz_start is not None:
        result.append('<%s>\n\n' % juz_start)
    result.append(textwrap.fill(text))

    if number is not None:
        sign = number
        if sajda == 'minor':
            sign = '*%s*' % sign
        if sajda == 'major':
            sign = '**%s**' % sign
        result.append('[%s]\n' % sign)
    else:
        result.append('\n')
    if translation is not None:
        result.append('%s\n' % textwrap.fill(translation))
    result.append('\n')
    return ''.join(result)


def get_sura(number):
    quran = uihelpers.get_quran()
    config = uihelpers.get_config()
    trans = uihelpers.get_translation(config)
    is_arabic = uihelpers.get_option(config, 'common.arabic_numbers', False)
    return uihelpers.write_sura(quran, number, write_aya,
                                trans, is_arabic)


if __name__ == '__main__':
    if len(sys.argv) == 1 or not sys.argv[1].isdigit():
        print 'Usage: %s sura_number [output_file]' % sys.argv[0]
    else:
        number = int(sys.argv[1])
        output = sys.stdout
        if len(sys.argv) > 2:
            output = open(sys.argv[2], 'wb')
        output.write(get_sura(number).encode('utf-8'))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.