Beispiel #1
0
    def _set_headings(self):
        self.headings = False
        return
        try:
            headings = self.soup.find_all(
                "div", class_="result-text-style-normal")[0].find_all("h3")

            first_element = self.soup.find_all(
                "div", class_="result-text-style-normal")[0].find_all()[0]
            if first_element.name != "h3":
                new_heading = self._get_previous_heading()
                if new_heading:
                    headings = [new_heading] + headings

            formatted_headings = []
            for heading in headings:
                span = heading.find_next("span")
                classes = span.get_attribute_list("class")
                try:
                    classes.remove("text")
                except ValueError:
                    pass
                passage = classes[0].split("-")
                passage = "{} {}:{}".format(passage[0], passage[1], passage[2])
                passage = scriptures.extract(passage)[0]
                passage = scriptures.reference_to_string(*passage)
                formatted_headings.append((passage, heading.string))

            return formatted_headings
        except Exception as e:
            print(e)
            return None
Beispiel #2
0
 def doAction(self,r,sr,words,sensorList):
     words = words.replace("first","1")
     words = words.replace("second","2")
     words = words.replace("map","matthew")
     words = words.replace("third","3")
     words = words.replace("-","2")
     verse = words.split("read me ")[1].split(" from the king james")[0]
     cleanUp = verse.split(" ")
     if self.isNum(cleanUp[-1]) and self.isNum(cleanUp[-2]):
         verse = " ".join(cleanUp[:-2])+ " " + cleanUp[-2]+":"+cleanUp[-1]
     if self.isNum(cleanUp[-1]) and len(cleanUp[-1])==4:
         verse = " ".join(cleanUp[:-2])+" "+ "".join(cleanUp[-1][:-2]) + ":" + "".join(cleanUp[-1][-2:])
     verseTu = scriptures.extract(verse)
     if len(verseTu) == 0:
         return "I can't find that verse"
     verseTu = verseTu[0]
     book = verseTu[0]
     if "III" in book:
         book = book.replace("III","3")
     if "II" in book:
         book = book.replace("II","2")
     if "I" in book:
         book = book.replace("I","1")
     if "Revelation" in book:
         book = "Revelation"
     return self.data[book]["chapters"][verseTu[1]-1]["verses"][verseTu[2]-1][str(verseTu[2])].replace("2019","'")
Beispiel #3
0
    def ResolveRequest(self, StringRequest):
        Passage = ''
        passageRefTuple = scriptures.extract(StringRequest)
        if len(passageRefTuple) > 0:
            BookID = ''
            ChapterID = ''
            VerseStartID = ''
            VerseEndID = ''
            BookName = str(passageRefTuple[0][0])
            if BookName == 'Revelation of Jesus Christ':
                BookName = 'Revelation'
            BookName = BookName.replace('II', '2')
            BookName = BookName.replace('I', '1')
            print(
                BookName +
                '***************************************************************************'
            )
            for i, book in enumerate(__Books):
                if BookName == __Books[i]['Book']:
                    BookID = format(__Books[i]['Id'], '02')
                    ChapterID = format(passageRefTuple[0][1], '03')
                    VerseStartID = format(passageRefTuple[0][2], '03')
                    VerseEndID = format(passageRefTuple[0][4], '03')
            idStart = str(BookID + ChapterID + VerseStartID)
            idEnd = str(BookID + ChapterID + VerseEndID)

            Bible.execute('SELECT t as text FROM t_asv WHERE id BETWEEN ' +
                          idStart + ' AND ' + idEnd)
            SelectDataArray = Bible.GetResultsDictArray()
            Passage = self.__BuildPassageFromArray(SelectDataArray,
                                                   passageRefTuple[0][2])
        return Passage
    def get_testament(self, passage):

        try:
            passage = scriptures.extract(passage)[0]
            return passage[5]
        except:
            return "-"
Beispiel #5
0
    def get_passage(self, book, passage, reading_type):

        if book == "Canticle":
            canticle = self.get_canticle_class(passage)
            return "<h3>{}</h3><h4>{}</h4>{}<h5>{}</h5>".format(
                canticle.latin_name, canticle.english_name,
                canticle().content, canticle.citation)

        if reading_type == "psalm":
            passage = passage.replace("Psalms ", "")
            psalm = parse_single_psalm(passage)
            return get_psalms(psalm)

        passage = "{} {}".format(book, passage)

        if book == "Ps":
            return passage.replace("Ps", "Psalms")
        references = scriptures.extract(passage)

        passages = []
        for reference in references:
            passage = scriptures.reference_to_string(*reference)
            try:
                passages.append(Passage(passage, source="esv").html)
            except PassageNotFoundException:
                try:
                    passages.append(Passage(passage, source="rsv").html)
                except PassageNotFoundException:
                    pass

        return "<br>".join(passages)
    def parse_passage(self, passage):

        try:
            passage = scriptures.extract(passage)[0]
            return scriptures.reference_to_string(*passage)
        except:
            return None
Beispiel #7
0
def readPassage(reference):
    with open('ESV.json') as data:
        bible = json.load(data)
    ref = scriptures.extract(reference)
    print(ref)
    passage = ''
    if ref != []:
        print(ref)
        verse = ref[0][2]
        for chapter in range(ref[0][1], ref[0][3] + 1):
            if chapter < ref[0][3]:
                while 1:
                    try:
                        passage += bible[ref[0][0]][str(chapter)][str(verse)]
                        passage += ' '
                        verse += 1
                    except:
                        break
            else:
                while verse <= ref[0][4]:
                    passage += bible[ref[0][0]][str(chapter)][str(verse)]
                    passage += ' '
                    verse += 1
            chapter += 1
            verse = 1
        return passage
    else:
        return ('This is not a valid reference')
Beispiel #8
0
    def extract_from_string(value):
        """Extracts passages from a string.

         @:returns List of passages.

         """

        # Extract scriptures from the name of the task to automatically add
        # scripture relationships.
        # e.g. [('Romans', 3, 23, 3, 28), ('I John', 2, 1, 2, 29)]
        passages = []
        references = scriptures.extract(value)
        for (book, from_chapter, from_verse, to_chapter, to_verse) in references:
            start_verse = '{book} {chapter}:{verse}'.format(
                book=book,
                chapter=from_chapter,
                verse=from_verse
            )
            end_verse = '{book} {chapter}:{verse}'.format(
                book=book,
                chapter=to_chapter,
                verse=to_verse
            )
            passages.append(PassageIndex(start_verse=start_verse, end_verse=end_verse))

        return passages
Beispiel #9
0
def passage_to_citation(passage):

    if not passage:
        return None

    passage = scriptures.extract(passage)
    passage = passage[0]

    if not passage:
        return None

    if passage[0] == "Susanna":
        return "The Book of Daniel, beginning with thirteenth chapter, the first verse, the Story of Susanna"

    book_name = passage[0]
    if book_name == "Song of Solomon":
        book_name = "Song of Songs"

    book_name = passage[0]
    if book_name == "Revelation of Jesus Christ":
        book_name = "Revelation"

    book = books[book_name]

    if book[1]:  # 1 chapter book
        return "A reading from {}, beginning with the {} verse".format(
            book[0], num2words(passage[2], ordinal=True))

    return "A reading from {}, beginning with the {} chapter, the {} verse".format(
        book[0], num2words(passage[1], ordinal=True),
        num2words(passage[2], ordinal=True))
Beispiel #10
0
    def format_reading(self, book, passage):
        if book == "Canticle":
            canticle_class = self.get_canticle_class(passage)
            return canticle_class.citation

        passage = "{} {}".format(book, passage)

        if book == "Ps":
            return passage.replace("Ps", "Psalms")
        references = scriptures.extract(passage)
        if not references:
            return passage
        result = []
        for i, reference in enumerate(references):
            print(reference)
            string = scriptures.reference_to_string(*reference)
            print(string)
            if i == 0:
                result.append(string)
            elif reference[1] == references[
                    i - 1][1] and reference[1] == reference[3]:
                result.append("{}-{}".format(reference[2], reference[4]))
            elif reference[1] != references[
                    i - 1][1] and reference[1] == reference[3]:
                result.append("{}:{}-{}".format(reference[1], reference[2],
                                                reference[4]))
            elif reference[1] != reference[3]:
                result.append("{}:{}-{}:{}".format(reference[1], reference[2],
                                                   reference[3], reference[4]))

        return ", ".join(result)
Beispiel #11
0
    def getBiblePassages(self, sermon):

        text = self.extractor.text()
        lines = text.splitlines()
        i = 0
        for line in lines:
            passages = scriptures.extract(line)

            if passages:
                if i < 4:
                    i = i + 1
                    book = passages[0][0]
                    segments = []
                    texts = []
                    for passage in passages:
                        texts.append(Passage(scriptures.reference_to_string(*passage)).text)
                        segments.append("{}:{}-{}:{}".format(passage[1], passage[2], passage[3], passage[4]))
                    texts = list(filter(lambda x: x is not None, texts))
                    text = " ".join(texts)
                    segments = " ".join(segments)
                    quote = "{} {}".format(book, segments)
                    book = book.lower()
                    if book in ["psalms"]:
                        book_type = SermonBiblePassage.PSALM
                    elif book in ["matthew", "mark", "luke", "john"]:
                        book_type = SermonBiblePassage.GOSPEL
                    elif book in [
                        "acts",
                        "romans",
                        "1 corinthians",
                        "2 corinthians",
                        "galatians",
                        "ephesians",
                        "philippians",
                        "colossians",
                        "1 thessalonians",
                        "2 thessalonians",
                        "1 timothy",
                        "2 timothy",
                        "titus",
                        "philemon",
                        "hebrews",
                        "james",
                        "1 peter",
                        "2 peter",
                        "1 john",
                        "2 john",
                        "3 john",
                        "jude",
                        "revelation",
                    ]:
                        book_type = SermonBiblePassage.EPISTLE
                    else:
                        book_type = SermonBiblePassage.PROPHECY
                    SermonBiblePassage.objects.create(
                        type=book_type, text=text, html=text, passage=quote, version="nrsv", sermon=sermon
                    )
Beispiel #12
0
def readVerse(reference):
    with open('ESV.json') as data:
        bible = json.load(data)
    ref = scriptures.extract(reference)
    if ref != []:
        print(ref)
        verse = bible[ref[0][0]][str(ref[0][1])][str(ref[0][2])]
        return verse
    else:
        return ('This is not a valid reference')
Beispiel #13
0
    def get(self, passage):
        if not passage:
            self.redirect("/")
        refsearch = scriptures.extract(passage)
        data = []
        par = []
        if refsearch:
            ref = refsearch[0]
            book_name = (
                ref[0]
                .replace("III ", "3 ")
                .replace("II ", "2 ")
                .replace("I ", "1 ")
                .replace("Revelation of Jesus Christ", "Revelation")
            )
            self.cur.execute("select id, section from books where value = %s", (book_name,))
            d = self.cur.fetchone()

            book_id = d["id"]
            testament = d["section"]
            if testament == "NT":
                version_id = 3
            else:
                version_id = 4
            startchap = ref[1]
            endchap = ref[3]
            startverse = ref[2]
            endverse = ref[4]
            startfullref = scriptures.reference_to_string(book_name, startchap, startverse)
            endfullref = scriptures.reference_to_string(book_name, endchap, endverse)
            startfullref = startfullref.replace("Revelation of Jesus Christ", "Revelation")
            endfullref = endfullref.replace("Revelation of Jesus Christ", "Revelation")
            startfullref = startfullref.replace("III ", "3 ").replace("II ", "2 ").replace("I ", "1 ")
            endfullref = endfullref.replace("III ", "3 ").replace("II ", "2 ").replace("I ", "1 ")
            if ":" in startfullref and ":" in endfullref:
                if len(startfullref) - (startfullref.index(":") + 1) == 1:
                    startfullref = startfullref.replace(":", ":0")
                if len(endfullref) - (endfullref.index(":") + 1) == 1:
                    endfullref = endfullref.replace(":", ":0")
            sql = "select * from verse where version_id = 1 and searchreftext between %s and %s order by searchref asc;"

            self.cur.execute(sql, (startfullref, endfullref))
            data = self.cur.fetchall()

            sql = "select max(searchref) stopref, min(searchref) startref from verse where searchreftext between %s and %s"
            self.cur.execute(sql, (startfullref, endfullref))
            d = self.cur.fetchall()
            startref = d[0]["startref"]
            stopref = d[0]["stopref"]

            sql = "select distinct link, title 	from se_link where searchref between %s and %s"
            self.cur.execute(sql, (startref, stopref))
            par = self.cur.fetchall()

        self.render("stack.html", passage=passage, data=data, par=par, version_id=version_id)
Beispiel #14
0
    def get_testament(self, book, passage):

        if book == "Canticle":
            return "NA"

        passage = "{} {}".format(book, passage)

        try:
            return scriptures.extract(passage)[0][5]
        except IndexError:
            return "NA"
Beispiel #15
0
def biblesearch(passage):
  passage = scriptures.extract(passage)
  log.info(passage)
  url = "http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage={}%20{}:{}-{}:{}&include-passage-references=false&include-footnotes=false&include-headings=false&include-short-copyright=false&output-format=plain-text&include-passage-horizontal-lines=false&include-heading-horizontal-lines=false".format(*passage[0])
  log.info(url)
  page = get(url)
  log.info(page)
  data = page.text
  for i in re.compile("</?[A-Z0-9a-z =#\.\-\"\']*>").findall(data):
    log.info(i)
    data = data.replace(i, "")
  return data.replace("&nbsp;", " ").replace("[","\n[")
Beispiel #16
0
    def get(self, passage, version_id):
        if not passage:
            self.redirect("/")
        ref = scriptures.extract(passage)[0]
        book_name = ref[0].replace("I ", "1 ").replace("II ", "2 ").replace("III ", "3")
        startchap = ref[1]
        endchap = ref[3]
        startverse = ref[2]
        endverse = ref[4]
        version_id = self.get_argument("version_id", None)
        startfullref = scriptures.reference_to_string(book_name, startchap, startverse)
        endfullref = scriptures.reference_to_string(book_name, endchap, endverse)
        startfullref = startfullref.replace("Revelation of Jesus Christ", "Revelation")
        endfullref = endfullref.replace("Revelation of Jesus Christ", "Revelation")

        if len(startfullref) - (startfullref.index(":") + 1) == 1:
            startfullref = startfullref.replace(":", ":0")
        if len(endfullref) - (endfullref.index(":") + 1) == 1:
            endfullref = endfullref.replace(":", ":0")
        print startfullref, endfullref
        if version_id:
            sql = "select reference, chapter_num, verse_num, version_id, analysis_text from verse where version_id = %s and searchreftext between %s and %s order by searchref asc, version_id desc;"
            self.cur.execute(sql, (version_id, startfullref, endfullref))
        else:
            sql = "select reference, chapter_num, verse_num, version_id, analysis_text from verse where searchreftext between %s and %s order by searchref asc, version_id desc;"
            self.cur.execute(sql, (startfullref, endfullref))
            # self.cur.execute(sql, (version_id, startfullref,endfullref))
        data = self.cur.fetchall()
        versedata = []
        for p in data:
            versedata.append(
                {
                    "reference": p["reference"],
                    "chapter": p["chapter_num"],
                    "verse": p["verse_num"],
                    "version_id": p["version_id"],
                    #'text': p['display_text'],
                    "words": p["analysis_text"].split(" "),
                }
            )
            # print len(words)
        """versedata = []
		sql = "select * from worddetailsbyword(%s)"
		for verse in data:
			words = verse['analysis_text'].split(' ')
			for word in words:
				self.cur.execute(sql, (word,))		
				versedata.append(self.cur.fetchone())
			
		"""
        self.render("analyze.html", passage=passage, versedata=versedata)
Beispiel #17
0
    def __init__(self, passage, version="nrsv"):
        self.version = version
        # try:
        print(passage)
        print(scriptures.extract(passage))
        self.reference = scriptures.extract(passage)[0]
        self.passage = scriptures.reference_to_string(*self.reference)
        self.passage = self.passage.replace("III ", "3 ")
        self.passage = self.passage.replace("II ", "2 ")
        self.passage = self.passage.replace("I ", "1 ")

        # except Exception as e:
        #     print(e)
        #     self.text = ""
        #     self.html = ""
        #     self.headings = []
        #     return
        self.markup = self._get_markup()

        self.soup = BeautifulSoup(self.markup, "html5lib")
        self.html = self._set_html()
        self.text = self._set_text()
        self.headings = self._set_headings()
Beispiel #18
0
	def post(self):				
		key = self.get_argument('searchkey',None)		
		if not key:
			self.redirect('/')
			return		
		refsearch = scriptures.extract(key)
		redir = ''
		print refsearch
		if refsearch:
			redir = 'passage'				
		else:
			redir = 'word'
			
			
		self.redirect('/%s/%s' % (redir,key))
Beispiel #19
0
 def get_reading_type(self, book, passage):
     if book == "Canticle":
         return "psalm"
     passage = "{} {}".format(book, passage)
     try:
         reference = scriptures.extract(passage)[0]
         book = reference[0]
         testament = reference[5]
         if book in ("Matthew", "Mark", "Luke", "John"):
             return "gospel"
         if book == "Psalms":
             return "psalm"
         if testament == "NT":
             return "epistle"
         return "prophecy"
     except IndexError:
         return "unknown"
Beispiel #20
0
	def get(self,passage): 			
		'''
				TO DO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
				verify that the top and bottom constraints are REAL passages
		'''
		if not passage:
			self.redirect("/")
		refsearch = scriptures.extract(passage)		
		if refsearch:
			ref = refsearch[0]
			book_name = ref[0]
			cursor = yield gen.Task(self.db.execute, "select id, section from books where value = %s", (book_name,))
			book_id,testament = cursor.fetchone()
			
			if testament == 'NT':
				version_id = 3
			else:
				version_id = 4
			startchap = ref[1]
			endchap = ref[3]
			startverse = ref[2]
			endverse = ref[4]		
			startfullref = scriptures.reference_to_string(book_name,startchap,startverse)
			endfullref = scriptures.reference_to_string(book_name,endchap,endverse)
			'''if ':' in startfullref and ':' in endfullref:				
				if len(startfullref) - (startfullref.index(':') + 1) == 1:
					startfullref = startfullref.replace(':',':0')
				if len(endfullref) - (endfullref.index(':') + 1) == 1:
					endfullref = endfullref.replace(':',':0')
			sql = "select id,verse_num,display_text from verse where version_id = 1 and searchreftext between %s and %s order by searchref asc;"
			cursor = yield gen.Task(self.db.execute,sql, (startfullref, endfullref))
			data = cursor.fetchall()	
			sql = "select id,verse_num,display_text from verse where version_id = %s and searchreftext between %s and %s order by searchref asc;"
			cursor = yield gen.Task(self.db.execute, sql, (startfullref, endfullref))
			par = cursor.fetchall()	
			'''
			cursors = yield gen.Task(self.db.batch, {
				'LEB': ["select * from getdisplayverses(1,%s,%s);", (startfullref, endfullref)],
				'PAR': ["select * from getanalysisverses(%s,%s,%s);", (version_id,startfullref, endfullref)]
			})
			results = {}
			for key, cursor in cursors.items():
				results[key] = cursor.fetchall()
		self.render('read.html', passage=passage, verses=results, version_id=version_id)
Beispiel #21
0
def getPassage(scripture_inp, version='KJV'):
    
    # check if the scripture is valid
    scripture = scriptures.extract(scripture_inp)
    # [(book, startBook, startVerse, endBook, endVerse ]

    if scripture == []:
        print("Your input is invalid, check please")
    else:
        script_str = scriptures.reference_to_string(*scripture[0])
        url_open = urllib.quote(script_str.encode("utf-8"))
        url = "http://mobile.biblegateway.com/passage/?search="+url_open+\
              "&version="+version+"\&interface=print"
        passage_raw = PyQuery(url)
        passage = passage_raw(".passage").remove("h3").find('[class^="text"]').\
                  remove(".chapternum").\
                  remove(".crossrefs").remove(".footnote")
        passage = passage.text().encode("utf-8")
        return passage
Beispiel #22
0
def bible(components):
	spec = components['arguments'].split('!bible ')[1]
	refs = scriptures.extract(spec)
	if len(refs) == 0:
		return ''
	response = ''
	verse_length = 0
	for r in refs:
		start_string = scriptures.reference_to_string(r[0], r[1], r[2], r[1], r[2])
		end_string = scriptures.reference_to_string(r[0], r[3], r[4], r[3], r[4])
		verse_length = verse_length + len(Passage(start_string, end_string))
		if verse_length > 5:
			return 'Could not fetch verses: length of passage too long'.encode('utf8')
		vs = GetPassage(r)
		response = '%(old_resp)s%(spec)s (ESV)\r\n%(verses)s\r\n' % {
			'old_resp': response,
			'spec': scriptures.reference_to_string(r[0], r[1], r[2], r[3], r[4]),
			'verses': vs
		}
	return response.encode('utf8')
Beispiel #23
0
	def get(self,passage): 			
		if not passage:
			self.redirect("/")
		refsearch = scriptures.extract(passage)
		
		if refsearch:
			ref = refsearch[0]
			book_name = ref[0]
			cursor = yield gen.Task(self.db.execute, "select id, section from books where value = %s", (book_name,))
			book_id,testament = cursor.fetchone()
			if testament == 'NT':
				version_id = 3
			else:
				version_id = 4
			startchap = ref[1]
			endchap = ref[3]
			startverse = ref[2]
			endverse = ref[4]		
			startfullref = scriptures.reference_to_string(book_name,startchap,startverse)
			endfullref = scriptures.reference_to_string(book_name,endchap,endverse)
			if ':' in startfullref and ':' in endfullref:				
				if len(startfullref) - (startfullref.index(':') + 1) == 1:
					startfullref = startfullref.replace(':',':0')
				if len(endfullref) - (endfullref.index(':') + 1) == 1:
					endfullref = endfullref.replace(':',':0')
			
			cursor = yield gen.Task(self.db.execute,"select max(searchref) stopref, min(searchref) startref from verse where searchreftext between %s and %s", (startfullref, endfullref))			
			stopref, startref = cursor.fetchone()						
			
			cursors = yield gen.Task(self.db.batch, {
				'LEB': ["select id,verse_num,display_text from verse where version_id = 1 and searchreftext between %s and %s order by searchref asc;",(startfullref, endfullref)],
				'PAR': ["select distinct link, title from se_link where searchref between %s and %s", (startref,stopref)]
			})
			
			results = {}
			for key, cursor in cursors.items():
				results[key] = cursor.fetchall()
			
		self.render('stack.html', passage=passage, verses=results, version_id = version_id)
Beispiel #24
0
def modify_readings(passages, topics, kids):
    feedback = ''
    changes = Changes()
    passages = scriptures.extract(passages)
    for (book, chapter1, verse1, chapterN, verseN) in passages:
        r = Reading(book, chapter1, verse1, chapterN, verseN)
        r.kids = kids
        for t in topics:
            r.topics.add(t)
        for b in blocks:
            new_readings = set()
            old_readings = set()
            for rr in b.readings:
                if rr.book != r.book:
                    break
                if rr.overlaps(r):
                    old_readings.add(rr)
                    for rrr in rr - r:
                        new_readings.add(rrr)
                        changes.cut.append(rrr)
                    new_readings.add(r)
            if len(new_readings) > 0:
                changes.passages.append(r)
                for rr in old_readings:
                    b.readings.remove(rr)
                b.readings.extend(new_readings)
                b.readings.sort()
                changes.books.append(b)

    now = datetime.date.today()
    daynum = int((now - schedule[0]).total_seconds() / 24 / 60 / 60)
    if len(schedule[1]) > daynum + 1:
        del schedule[1][daynum + 1:]
        save_schedule()
    save_blocks()
    return changes
Beispiel #25
0
    days = []

    # Add bible text
    last_book_name = None
    for i, h in enumerate(headings):

        if i == len(headings) - 1:
            break

        jt_lines = jt[h:headings[i + 1]].split("\n")

        first_line = jt_lines[0]
        translated_first_line, last_book_name = replace_korean_book_name_with_english(
            first_line, last_book_name)
        print(translated_first_line, last_book_name)
        extracted_ranges = scriptures.extract(translated_first_line)
        parsed_text_lines = get_lines_over_chapters(extracted_ranges[0])
        text_lines = functools.reduce(
            lambda v, e: v + ([e[1]]
                              if e[0] else ["", e[1]]), parsed_text_lines, [])

        day_lines = [jt_lines[0]] + text_lines + jt_lines[1:]

        note_link = "(이번주 JT: http://bit.ly/2IiNLfe)"
        day_lines.append(note_link)

        days.append("\n".join([x.strip() for x in day_lines]))

    assert len(days) == 6, len(days)

    # Remove old files
Beispiel #26
0
for filename in sorted(os.listdir(questionPath)):
    text = extract_text(f'{questionPath}/{filename}')
    text = text.replace('\n', '~~~')
    lessonLine = re.match(
        r".*Lesson (\d+)\s*~~~Adult Questions\s*~~~(.*?)\s*~~~.*", text)
    text = re.sub(r"Lesson (\d+)\s*~~~Adult Questions\s*~~~(.*?)\s*~~~", '',
                  text)
    text = text.replace('~~~', '')
    text = re.sub('([A-Z]+ DAY)', r'\n\1', text)
    text = re.sub('(Focus Verse)', r'\n\1', text)

    daySeen = False

    if (lessonLine):
        lessonNumber = lessonLine.group(1)
        lessonVerses = scriptures.extract(lessonLine.group(2))

        print(f'\n\n## Lesson {lessonNumber}')
        print(f'**Scripture**')
        for verse in RemoveDupicates(lessonVerses):
            print(f'- {GetVerseMarkdown(verse)}\n')

    for line in text.splitlines():
        if re.match('[A-Z]+ DAY', line):
            section = re.match('[A-Z]+ DAY', line)
            if section:
                if not daySeen:
                    daySeen = True
                    print(f'**Days**')
                verses = scriptures.extract(line)
                print(
Beispiel #27
0
def main():
    # look for command line arguments
    args = sys.argv[1:]

    if '-h' in args or '--help' in args or '-?' in args:
        helptext()
        sys.exit(0)

    if '-l' in args:
        logging = True
        logfilename = args[args.index('-l') + 1]
        trimlogfile(logfilename)
        logfile = open(logfilename, 'a')
        oldstdout = sys.stdout
        oldstderr = sys.stderr
        logsplit = LogFileSplitter(sys.stdout, logfile)
        sys.stdout = logsplit
        sys.stderr = logsplit
        print('Logging started.')

    if '-c' in args:
        configfile = args[args.index('-c') + 1]
        if not os.path.isfile(configfile):
            print(configfile + ' does not exist, create it? (Y/N):')
            if not raw_input().lower() == 'y':
                print('OK, config file will not be created')
                if logging == True:
                    sys.stdout = oldstdout
                    sys.stderr = oldstderr
                    logfile.close()
                sys.exit(0)
    else:
        configfile = '/etc/ssp_sermon_podcast.xml'

    if ('--config' in args) or not os.path.isfile(configfile):
        edit_config_file(configfile)
        print('Config file created and will be used on next run.')
        if logging:
            sys.stdout = oldstdout
            sys.stderr = oldstderr
            logfile.close()
        sys.exit(0)

    #load the config file
    if os.path.isfile(configfile):
        try:
            configET = ET.parse(configfile)
        except:
            print('Can\'t parse config file ' + configfile)
            sys.exit(1)
        config = configET.getroot()
        if not ((config.tag == 'config') and
                (config.attrib['description']
                 == 'Seriously Simple Podcasting Sermon Podcast settings')):
            print(configfile + ' is not a SSP Sermon Podcast config file.')
            if logging:
                sys.stdout = oldstdout
                sys.stderr = oldstderr
                logfile.close()
            sys.exit(1)

    #get the settings from the config
    settings = config.find('settings')

    #open the wordpress object
    wordpress_url = settings.find('wordpress_url').text
    if wordpress_url.endswith('/'):
        xmlrpc_url = wordpress_url + 'xmlrpc.php'
    else:
        xmlrpc_url = wordpress_url + '/xmlrpc.php'

    wp = Client(xmlrpc_url,
                settings.find('wordpress_user').text,
                decryptpassword(settings.find('wordpress_pass').text))

    #get a list of podcast objects
    allpodcasts = []
    interval = 20
    offset = 0
    while True:
        podcastbatch = wp.call(
            GetPosts({
                'post_type': 'podcast',
                'number': interval,
                'offset': offset
            }))
        if len(podcastbatch) == 0:
            break
        allpodcasts.extend(podcastbatch)
        offset += interval

    print('Retrieved ' + str(len(allpodcasts)) +
          ' podcasts from WordPress site.')

    #get the series settings from the config and find out which series will be podcast
    allseriesconfigs = config.findall('series_config')
    termids_to_podcast = []
    for seriesconfig in allseriesconfigs:
        termids_to_podcast.append(seriesconfig.attrib['term_id'])

    #get a list of series from the blog
    listofseriesterms = []
    interval = 20
    offset = 0
    while True:
        termsbatch = wp.call(
            GetTerms('series', {
                'number': interval,
                'offset': offset
            }))
        if len(termsbatch) == 0:
            break
        listofseriesterms.extend(termsbatch)
        offset += interval

    print('Found ' + str(len(listofseriesterms)) +
          ' podcast series on the WordPress site.')

    #find out the hierarchy of the series so we can do the lowest children first
    termpriority = {}
    term_parents = {}

    for term in listofseriesterms:
        term_parents[term.id] = term.parent
        order = 0
        parentid = term.parent
        while parentid != '0':
            order += 1
            for parentterm in listofseriesterms:
                if parentid == parentterm.id:
                    parentid = parentterm.parent
                    break
        termpriority[term.id] = order

    #so the order to approach term.ids is
    termid_order = []

    for termid, order in sorted(termpriority.iteritems(),
                                key=lambda x: x[1],
                                reverse=True):
        termid_order.append(termid)

    print('This is the order the series terms will be published:')
    print(', '.join(termid_order))

    #find which series config the posts should be published with (if any)
    podcasts_to_do = {}
    extension = extension_dot(settings.findtext('source_audio_type'))
    for termid in termid_order:
        if termid in termids_to_podcast:
            for podcast in allpodcasts:
                #check whether the podcast is flagged to be published and has a date:
                date_recorded = get_post_custom_field(podcast, 'date_recorded')
                if get_post_custom_field(podcast,
                                         'publish_now') and date_recorded:
                    podcast_termids = ['0']
                    for podcastterm in podcast.terms:
                        podcast_termids.append(podcastterm.id)
                    for podcast_termid in podcast_termids:
                        if podcast_termid in term_parents:
                            podcast_termids.append(
                                term_parents[podcast_termid])
                    if termid in podcast_termids and not podcast.id in podcasts_to_do:
                        #work out what the start of the source file name will be:
                        termid_seriesconfig = seriescfg_from_term_id(
                            allseriesconfigs, termid)
                        source_date_format = termid_seriesconfig.find(
                            'source_date_format').text
                        date_recorded_format = settings.find(
                            'date_recorded_format').text
                        sourcefile_name_start = getdatetime(
                            date_recorded, user_format=date_recorded_format
                        ).strftime(
                            source_date_format) + termid_seriesconfig.findtext(
                                'source_file_code', default='')
                        sourcepath = termid_seriesconfig.findtext(
                            'source_path')
                        #and does it exist?
                        directorylist = []
                        if os.path.exists(sourcepath):
                            #this seems to timeout sometimes, so will loop if need be:
                            retrycount = 3
                            while retrycount:
                                try:
                                    directorylist = os.listdir(sourcepath)
                                    retrycount = 0
                                except OSError as errmsg:
                                    print(errmsg)
                                    retrycount -= 1
                                    if retrycount:
                                        print('Retrying directory list...')
                        for filename in directorylist:
                            if filename[:len(sourcefile_name_start
                                             )] == sourcefile_name_start:
                                if extension:
                                    extposn = -len(extension)
                                if filename[
                                        extposn:] == extension or extension == None:
                                    ordered_podcast_termids = []
                                    for termid_again in termid_order:
                                        if termid_again in podcast_termids:
                                            ordered_podcast_termids.append(
                                                termid_again)
                                    ordered_podcast_termids.append('0')
                                    podcasts_to_do[podcast.id] = [
                                        podcast, termid_seriesconfig,
                                        os.path.abspath(
                                            os.path.join(sourcepath,
                                                         filename)),
                                        ordered_podcast_termids
                                    ]

    print('There are ' + str(len(podcasts_to_do)) +
          ' podcasts to process in this pass.')

    if len(podcasts_to_do) != 0:
        listofposttags = []
        interval = 20
        offset = 0
        while True:
            termsbatch = wp.call(
                GetTerms('post_tag', {
                    'number': interval,
                    'offset': offset
                }))
            if len(termsbatch) == 0:
                break
            listofposttags.extend(termsbatch)
            offset += interval
        posttagsdict = {}
        for posttag in listofposttags:
            posttagsdict[posttag.name.lower()] = posttag
        print('Retrieved ' + str(len(posttagsdict)) +
              ' post tags from WordPress site.')

    #iterate over the podcasts
    for podcast_id, podcast_and_config in podcasts_to_do.iteritems():
        #open the audio file
        print('\n')
        print('Now processing file ' + podcast_and_config[2])
        backuppodcast = copy.deepcopy(podcast_and_config[0])
        try:
            sourceaudio = audiotools.open(podcast_and_config[2])
            sourcepcm = sourceaudio.to_pcm()

            #calculate its loudness
            loudness = audiotools.calculate_replay_gain([sourceaudio])
            for loudnesstuple in loudness:
                gain = loudnesstuple[1]
                peak = loudnesstuple[2]
            if peak == 0:
                print('This audio file is silent, ignoring it.')
                continue

            #mix it to the specified number of channels
            gaincorrection = 0
            if settings.findtext('audiochannels') == '1':
                print('Converting to mono.')
                sourcepcm_mixed = audiotools.pcmconverter.Averager(sourcepcm)
            elif settings.findtext('audiochannels') == '2':
                print('Converting to stereo.')
                sourcepcm_mixed = audiotools.pcmconverter.Downmixer(sourcepcm)
                if sourceaudio.channels() == 1:
                    gaincorrection = 6.0
            else:
                sourcepcm_mixed = sourcepcm

            #adjust the gain to the users' preference instead of replaygain's target -20
            target_loudness = float(
                settings.findtext('target_loudness', default='-24'))
            newgain = gain + (target_loudness + 20.0) + gaincorrection
            newpeak = 1.0 / (10.0**(newgain / 20.0))
            if (peak / (10.0**(gaincorrection / 20.0))) > newpeak:
                newpeak = peak / (10.0**(gaincorrection / 20.0))
            print(
                'Normalising for gain: ' + str(round(newgain, 2)) +
                'dB, peak = ' + str(
                    round(
                        (20.0 * log10(peak /
                                      (10.0**(gaincorrection / 20.0)))), 2)) +
                'dBFS.')
            #normalise the audio to the target loudness
            sourcepcm_normalised = audiotools.replaygain.ReplayGainReader(
                sourcepcm_mixed, newgain, newpeak)

            try:
                bitspersample = int(settings.findtext('bitspersample'))
            except:
                bitspersample = None
            if bitspersample:
                print('Quantising to ' + str(bitspersample) + '-bit.')
                sourcepcm_resampled = audiotools.pcmconverter.BPSConverter(
                    sourcepcm_normalised, bitspersample)

            #make some tempfiles:
            process_tempfile = tempfile.mkstemp(
                suffix='.wav', prefix='sermon_process_tempfile')
            processed_tempfile = tempfile.mkstemp(
                suffix='.wav', prefix='sermon_processed_tempfile')
            encoded_tempfile = tempfile.mkstemp(
                suffix=extension_dot(settings.findtext('encoded_audio_type')),
                prefix='sermon_encoded_tempfile')
            print('tempfiles: ' + process_tempfile[1] + ', ' +
                  processed_tempfile[1] + ', ' + encoded_tempfile[1])

            #write the audio back out to a wave file for processing
            audiotools.WaveAudio.from_pcm(process_tempfile[1],
                                          sourcepcm_resampled)

            sourcepcm_normalised.close()
            sourcepcm_mixed.close()
            sourcepcm.close()
            sourceaudio = None

            audioparams = getaudioparams(sourcepcm_resampled)
            sourcepcm_resampled.close()
            subprocess_args = [settings.findtext('processing_utility')]
            for argsubelement in settings.findall('processing_utility_arg'):
                subprocess_args.append(
                    Template(argsubelement.text).substitute(audioparams))
            tempstring = settings.findtext('processing_utility_infile')
            if tempstring:
                subprocess_args.append(tempstring)
            subprocess_args.append(process_tempfile[1])
            tempstring = settings.findtext('processing_utility_outfile')
            if tempstring:
                subprocess_args.append(tempstring)
            subprocess_args.append(processed_tempfile[1])

            print('Now processing audio ...')

            print(
                subprocess.Popen(subprocess_args,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT,
                                 universal_newlines=True).communicate()[0])
            os.remove(process_tempfile[1])

            processedfile = audiotools.open(processed_tempfile[1])
            audioparams = getaudioparams(processedfile.to_pcm())
            subprocess_args = [settings.findtext('encoding_utility')]
            for argsubelement in settings.findall('encoding_utility_arg'):
                subprocess_args.append(
                    Template(argsubelement.text).substitute(audioparams))
            tempstring = settings.findtext('encoding_utility_infile')
            if tempstring:
                subprocess_args.append(tempstring)
            subprocess_args.append(processed_tempfile[1])
            tempstring = settings.findtext('encoding_utility_outfile')
            if tempstring:
                subprocess_args.append(tempstring)
            subprocess_args.append(encoded_tempfile[1])

            print('Now encoding audio ...')

            print(
                subprocess.Popen(subprocess_args,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT,
                                 universal_newlines=True).communicate()[0])
            os.remove(processed_tempfile[1])

            wp_details = make_podcast_dict(podcast_and_config, wp, settings)

            wp_details['post_status'] = 'publish'
            wp_details['publish_now'] = ''

            updated_podcast = publish_post(podcast_and_config, wp_details, wp,
                                           settings)
            podcast_and_config[0] = updated_podcast
            updated_details = make_podcast_dict(podcast_and_config,
                                                wp,
                                                settings,
                                                final_pass=True)

            try:
                imageurl = urllib2.urlopen(updated_details['image'])
                podcastimage = imageurl.read()
            except:
                podcastimage = False
            try:
                audioimage = [
                    audiotools.Image.new(podcastimage, u'Artwork', 0)
                ]
            except:
                audioimage = []
            outputmetadata = audiotools.MetaData(
                track_name=updated_details['title'],
                track_number=int(updated_details['episode_number']),
                album_name=updated_details['series'],
                artist_name=updated_details['preacher'],
                copyright=updated_details['copyright'],
                publisher=updated_details['publisher'],
                year=updated_details['date'].strftime('%Y'),
                date=updated_details['date_recorded'],
                comment=updated_details['content'],
                images=audioimage)
            outputfile = audiotools.open(encoded_tempfile[1])
            outputfile.set_metadata(outputmetadata)
            outputfile_seconds = int(outputfile.seconds_length())

            outputfile_name = updated_details[
                'output_file_template'] + extension_dot(
                    settings.findtext('encoded_audio_type'))

            outputfile_size = ftp_encodedfile(encoded_tempfile[1],
                                              outputfile_name,
                                              podcast_and_config[1])
            if outputfile_size == None:
                raise Exception('FTP appears not to have worked.')

            print('\n')
            print('Output file size = ' + str(outputfile_size))
            print('Output file duration = ' + str(outputfile_seconds))
            print('\n')

            os.remove(encoded_tempfile[1])

            urlpath = podcast_and_config[1].findtext('download_path')
            if not urlpath[-1] == '/':
                urlpath = urlpath + '/'
            updated_details['audio_file'] = urlpath + outputfile_name
            updated_details['filesize_raw'] = str(outputfile_size)
            mins = str(outputfile_seconds / 60)
            secs = str(outputfile_seconds % 60)
            if len(secs) == 1:
                secs = '0' + secs
            updated_details['duration'] = mins + ':' + secs

            #put the preacher in as a tag:
            updated_details['tags'] = []
            if updated_details['preacher'].lower() in posttagsdict:
                updated_details['tags'].append(
                    posttagsdict[updated_details['preacher'].lower()])
            else:
                tag = WordPressTerm()
                tag.taxonomy = 'post_tag'
                tag.name = updated_details['preacher']
                tag.id = wp.call(NewTerm(tag))
                updated_details['tags'].append(tag)
                posttagsdict[tag.name.lower()] = tag

            #put the book(s) of the bible in as tags:
            #This bit is really messy and I should try to write my own scripture regular expressions, but in the interest of speed:
            listofpassages = scriptures.extract(
                updated_details['bible_passage'])
            if 'song of songs' in updated_details['bible_passage'].lower():
                listofpassages.append(('Song of Songs', 1, 1, 1, 1))
            for passage in listofpassages:
                book = passage[0]
                if book[:4] == 'III ':
                    bookname = '3 ' + book[4:]
                elif book[:3] == 'II ':
                    bookname = '2 ' + book[3:]
                elif book[:2] == 'I ':
                    bookname = '1 ' + book[2:]
                elif book == 'Song of Solomon':
                    bookname = 'Song of Songs'
                else:
                    bookname = book
                if bookname.lower() in posttagsdict:
                    updated_details['tags'].append(
                        posttagsdict[bookname.lower()])
                else:
                    tag = WordPressTerm()
                    tag.taxonomy = 'post_tag'
                    tag.name = bookname
                    tag.id = wp.call(NewTerm(tag))
                    updated_details['tags'].append(tag)
                    posttagsdict[tag.name.lower()] = tag

            finalpost = publish_post(podcast_and_config, updated_details, wp,
                                     settings)

            print('Final Post details are as follows:\n')

            for field, contents in finalpost.struct.iteritems():
                try:
                    if type(contents) == types.StringType:
                        print(field + ' : ' + contents)
                    elif type(contents) == types.ListType:
                        for subcontents in contents:
                            print(field + ' : ' + str(subcontents))
                    elif type(contents) == types.DictType:
                        for subfield, subcontents in contents.iteritems():
                            print(field + ' : ' + subfield + ' : ' +
                                  str(subcontents))
                    elif type(contents) == types.UnicodeType:
                        print(field + ' : ' +
                              contents.encode('ascii', 'ignore'))
                    else:
                        print(field + ' : ' + str(contents))
                except:
                    print('Can\'t print field')
        except Exception as message:
            print('ERROR: Exception raised while processing that podcast:')
            print(message)
            print(
                'Attempting to restore original post prior to modification...')
            try:
                if wp.call(EditPost(backuppodcast.id, backuppodcast)):
                    print('Post restored.')
                else:
                    print('Unable to restore original post.')
            except Exception as message:
                print('Unable to restore original post: ')
                print(message)
            try:
                os.remove(encoded_tempfile[1])
            except:
                pass
            try:
                os.remove(processed_tempfile[1])
            except:
                pass
            try:
                os.remove(process_tempfile[1])
            except:
                pass

    logsplit.write('Completed with normal exit\n\n\n')
    if logging:
        sys.stdout = oldstdout
        sys.stderr = oldstderr
        logfile.close()
Beispiel #28
0
from pdfminer.high_level import extract_text
import scriptures
import re
import os

questionPath = '/media/data/data/Media/BSF/2020-2021/Adult Questions'

for filename in sorted(os.listdir(questionPath)):
    text = extract_text(f'{questionPath}/{filename}')

    p = re.compile('Lesson \d+')
    lesson = p.findall(text)[0]
    print(f'## {lesson}')

    verses = scriptures.extract(text)

    for verse in verses:
        str = scriptures.reference_to_string(verse[0], verse[1], verse[2],
                                             verse[3], verse[4])
        str = str.replace('Revelation of Jesus Christ', 'Revelation')
        urlStr = str.replace(' ', '+').replace(':', '%3A')
        url = f'https://www.biblegateway.com/passage/?search={urlStr}&version=NLT&interface=print'
        print(f'- [{str}]({url})')
Beispiel #29
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

import psycopg2, scriptures
dbconn = psycopg2.connect("host=192.168.57.128 dbname=bhse-bible user=swasheck")
cur = dbconn.cursor()
notes = []
cur.execute("select * from se_question")
for question in cur.fetchall():
	refs = scriptures.extract(question[2])
	for ref in refs:
		if ref[1] == ref[3]:
			book = ref[0]
			book_db = book.replace('III ','3 ').replace('II ','2 ').replace('I ','1 ').replace('Revelation of Jesus Christ','Revelation')
			startchap = ref[1]
			startverse = ref[2]
			endchap = ref[3]
			endverse = ref[4]	
			#reference = scriptures.reference_to_string(book,startchap,startverse,endchap,endverse)					
			
			for verse in range(startverse,endverse+1):
					if scriptures.is_valid_reference(book, startchap, verse):
						notes.add({
							'question_id': question[0],
							'link':question[1], 
							'reference': scriptures.reference_to_string(book, startchap, verse
								).replace('III ','3 ').replace('II ','2 ').replace('I ','1 ').replace('Revelation of Jesus Christ','Revelation')
						})			
			
		else:
			print ref
Beispiel #30
0
import pickle, argparse, lectionary, scriptures

parser = argparse.ArgumentParser(description='Modify the lectionary readings.')
parser.add_argument('passage', action='store', nargs='+')
parser.add_argument('--kids', action='store_true')
parser.add_argument('--no-kids', action='store_true')
parser.add_argument('--tag', action='append', default=[])

args = parser.parse_args()
print(args)

with open("readings", "rb") as f:
    blocks = pickle.load(f)

passages = scriptures.extract(' '.join(args.passage))
print('passages are', passages, 'from', ' '.join(args.passage))

for (book, chapter1, verse1, chapterN, verseN) in passages:
    r = lectionary.Reading(book, chapter1, verse1, chapterN, verseN)
    if args.kids:
        r.kids = True
    if args.no_kids:
        r.kids = False
    for t in args.tag:
        r.topics.add(t)
    print(r)
    for b in blocks:
        new_readings = set()
        old_readings = set()
        for rr in b.readings:
            if rr.book != r.book:
Beispiel #31
0
	def get(self,passage):
		refsearch = scriptures.extract(passage)
		'''
			Extract the passage range 
		'''
		ref = refsearch[0]
		book_name = ref[0]		
		startchap = ref[1]
		endchap = ref[3]
		startverse = ref[2]
		endverse = ref[4]		
		startfullref = scriptures.reference_to_string(book_name,startchap,startverse)
		endfullref = scriptures.reference_to_string(book_name,endchap,endverse)
		if book_name in ['2 John','Philemon','Jude','Obadiah','3 John']:
			startfullref = '%s %s' % (book_name,startverse)
			endfullref = '%s %s' % (book_name,endverse)
		else:
			startfullref = '%s %s:%s' % (book_name,startchap,startverse)
			endfullref = '%s %s:%s' % (book_name,endchap,endverse)
		print startfullref,endfullref
		self.cur.execute('select searchref from verse where reference in (%s,%s) order by searchref', (startfullref,endfullref))
		results = self.cur.fetchall()
		if len(results) == 2:
			startsearchref = results[0]['searchref']		
			endsearchref = results[1]['searchref']
		else:
			startsearchref = endsearchref = results[0]['searchref']		
			
		
		'''
			Get verse information 
		'''
		self.cur.execute('select displaytext from verse where searchref between %s and %s', (startsearchref,endsearchref))			
		versetext = self.cur.fetchall()
			
		self.cur.execute('select * from getanalysis(%s,%s)', (startsearchref,endsearchref))
		analysistext = self.cur.fetchall()
		self.cur.execute('select * from getwordriver(%s,%s,%s)', (4,startsearchref,endsearchref))
		wordriver = self.cur.fetchall()
			
		'''tenseriver = [['Reference', 'Present', 'Perfect','Imperfect','Pluperfect','Aorist','Future'],]
		for row in wordriver:
			tenseriver.append([row['reference'],row['present'],row['perfect'],row['imperfect'],row['pluperfect'],
				row['aorist'],row['future']])
		'''
		tenses = ['future','present','perfect','imperfect','pluperfect','aorist','noneorunknowntense']
		voices = ['active','passive','middle','noneorunknownvoice']
		moods = ['infinitive','indicative','imperative','optative','subjunctive','participial','noneorunknownmood']
		#tenseaggs = {key:[] for key in tenses}
		tenseticks = []
		tenseriver = []		
		rid = 1
		for row in wordriver:
			tenseticks.append([rid,row['reference']])
			rid += 1		
		for tense in tenses:
			tenseagg = {}			
			tensedata = []
			rid = 1
			for row in wordriver:
				tensedata.append([rid,row[tense]])
				rid += 1
			tenseagg['data'] = tensedata
			tenseagg['label'] = tense
			tenseriver.append(tenseagg)
			
		#tenseaggs = {key:[] for key in tenses}
		voiceticks = []
		voiceriver = []		
		rid = 1
		for row in wordriver:
			voiceticks.append([rid,row['reference']])
			rid += 1		
		for voice in voices:
			voiceagg = {}			
			voicedata = []
			rid = 1
			for row in wordriver:
				voicedata.append([rid,row[voice]])
				rid += 1
			voiceagg['data'] = voicedata
			voiceagg['label'] = voice
			voiceriver.append(voiceagg)
			
		#tenseaggs = {key:[] for key in tenses}
		moodticks = []
		moodriver = []		
		rid = 1
		for row in wordriver:
			moodticks.append([rid,row['reference']])
			rid += 1		
		for mood in moods:
			moodagg = {}			
			mooddata = []
			rid = 1
			for row in wordriver:
				mooddata.append([rid,row[mood]])
				rid += 1
			moodagg['data'] = mooddata
			moodagg['label'] = mood
			moodriver.append(moodagg)
			
		self.cur.execute('select displaytext from verse where searchref between %s and %s', (startsearchref,endsearchref))			
		versetext = self.cur.fetchall()
			
		self.cur.execute('select * from getanalysis(%s,%s)', (startsearchref,endsearchref))
		analysistext = self.cur.fetchall()
		
		#self.write('%s<br />%s' % (json.dumps(tenseriver),ticks))
		self.render("passage.html",versetext=versetext,analysistext=analysistext,passage=passage,
			tenseriver=json.dumps(tenseriver),tenseticks=json.dumps(tenseticks),
			voiceriver=json.dumps(voiceriver),voiceticks=json.dumps(voiceticks),
			moodriver=json.dumps(moodriver),moodticks=json.dumps(moodticks)
			)
Beispiel #32
0
             counter = 3
         elif counter == 2:
             title = title + " " + line.strip()
 title = title.strip()
 author = author.strip()
 if (not "!" in author) and (not "ˇ" in author) and (
         not "ˆ" in author) and (not ":" in author) and (
             not '"' in author):
     docid = year + ":" + author.replace(
         " ", "_") + ":" + title[:10]
     for i in range(0, number_of_pages):
         pageObj = read_pdf.getPage(i)
         content = content + "\n" + pageObj.extractText()
     if options.usebible:
         # Bibelstellen
         bs = scriptures.extract(content)
         if not options.verbose:
             print("Found Bible References: " +
                   str(len(bs)))
         for s in bs:
             if s[0].replace(" ", "_") not in G:
                 # Create new node for book
                 nodedict = {}
                 nodedict['Name'] = s[0].replace(" ", "_")
                 nodedict['Type'] = "biblicalbook"
                 nodedict['Title'] = s[0]
                 G.add_node(nodedict['Name'])
                 G.nodes[nodedict['Name']].update(nodedict)
             # Kante hinzufügen
             G.add_edge(docid, s[0].replace(" ", "_"))
             G[docid][s[0].replace(
Beispiel #33
0
def get_devo(delta=0):
    def strip_markdown(string):
        return string.replace('*', ' ').replace('_', ' ')

    today_date = datetime.utcnow() + timedelta(hours=8, days=delta)
    date_url = today_date.strftime('%Y-%m-%d')
    devo_url = 'http://qt.swim.org/user_dir/living/user_print_web.php?edit_all=' + date_url

    try:
        result = urlfetch.fetch(devo_url, deadline=10)
    except Exception as e:
        logging.warning('Error fetching devo:\n' + str(e))
        return None

    try:
        html = result.content
        soup = BeautifulSoup(html, 'lxml')

        date = today_date.strftime('%b %-d, %Y ({})').format(today_date.strftime('%a').upper())
        heading = strip_markdown(soup.select_one('.main_title').text).strip()
        verse = strip_markdown(soup.select_one('.bible_no').text).lstrip('[ ').rstrip(' ]')
        verse = scriptures.reference_to_string(*scriptures.extract(verse)[0])
        first_word = verse.partition(' ')[0]
        if first_word in ('I', 'II', 'III'):
            verse = str(len(first_word)) + verse.lstrip('I')
        elif first_word == 'Revelation':
            verse = first_word + verse[26:]

        lines = soup.select_one('.main_body').text.splitlines()
        passage = ''
        for line in lines:
            idx = line.find(' ')
            num = '_' + strip_markdown(line[:idx]).rstrip('.') + '_'
            rest_of_line = strip_markdown(line[idx:]).strip()
            passage += '{} {}\n'.format(num, rest_of_line)
        passage = passage.strip()

        ref_soup = soup.select_one('.main_body2')
        for tag in ref_soup.select('b'):
            text = strip_markdown(tag.text).strip()
            tag.string = '*' + text.replace(' ', '\a') + '*'
        reflection = ref_soup.text.strip() + '\n\n'
        reflection += strip_markdown(soup.select_one('.main_body3').text).strip()

        prayer = strip_markdown(soup.select('.main_body2')[1].text).strip()

        daynames = ['Yesterday\'s', 'Today\'s', 'Tomorrow\'s']

        devo = u'\U0001F4C5' + ' ' + daynames[delta + 1] + ' QT - _' + date + '_\n\n' + \
               '*' + heading + '*\n' + verse + '\n\n' + \
               u'\U0001F4D9' + ' *Scripture* _(NIV)_\n\n' + passage + '\n\n' + \
               u'\U0001F4DD' + ' *Reflection*\n\n' + reflection + '\n\n' + \
               u'\U0001F64F' + ' *Prayer*\n\n' + prayer
        return devo

    except:
        if delta == -1:
            return 'Sorry, the LLJ website is no longer hosting yesterday\'s material.'
        elif delta == 0:
            return 'Sorry, the LLJ website does not have today\'s material yet.'
        else:
            return 'Sorry, the LLJ website hasn\'t made tomorrow\'s material available yet.'
Beispiel #34
0
	def get(self,passage,version_id): 			
		print passage, version_id
		if not passage:
			self.redirect("/")
		ref = scriptures.extract(passage)[0]
		book_name = ref[0]		
		startchap = ref[1]
		endchap = ref[3]
		startverse = ref[2]
		endverse = ref[4]		
		startfullref = scriptures.reference_to_string(book_name,startchap,startverse)
		endfullref = scriptures.reference_to_string(book_name,endchap,endverse)
		
		if len(startfullref) - (startfullref.index(':') + 1) == 1:
			startfullref = startfullref.replace(':',':0')
		if len(endfullref) - (endfullref.index(':') + 1) == 1:
			endfullref = endfullref.replace(':',':0')			

		results = OrderedDict()
		cursor = yield gen.Task(self.db.execute, 'select reference, chapter_num, verse_num, version_id, analysis_text, parsed_text from verse where version_id = %s and searchreftext between %s and %s order by searchref asc, version_id desc;', (version_id,startfullref,endfullref))
		for verse in cursor.fetchall():
			results[verse[0]] = []
			print 'ZOMG BBQ!!!'
			results[verse[0]].append(verse[5])
			
		'''for verse in cursor.fetchall():
			queries = {}
			id = 0
			for word in verse[4].split(' '):
				queries[id] = ['select * from worddetailsbyword(%s);',(word,)]
				id += 1
			cursors = yield gen.Task(self.db.batch, queries)
			
			
			for key,cursor in cursors.items():
				worddata = {}
				if verse[0] not in results.keys():
					results[verse[0]] = []	
				datapoints = cursor.fetchone()
				results[verse[0]].append( {
						'wordid': datapoints[0],
						'word': datapoints[1],
						'inflectedmeaning': datapoints[2],
						'root': datapoints[3],
						'rootmeaning': datapoints[4],
						'case': datapoints[5],
						'person': datapoints[6],
						'gender': datapoints[7],
						'number': datapoints[8],
						'tense': datapoints[9],
						'voice': datapoints[10],
						'mood': datapoints[11],
				} )		
				
			for word in verse[4].split(' '):	
				cursor = yield gen.Task(self.db.execute, 'select * from worddetailsbyword(%s);', (word,))
				if verse[0] not in results.keys():
					results[verse[0]] = []
				datapoints = cursor.fetchone()
				results[verse[0]].append( {
						'wordid': datapoints[0],
						'word': datapoints[1],
						'inflectedmeaning': datapoints[2],
						'root': datapoints[3],
						'rootmeaning': datapoints[4],
						'case': datapoints[5],
						'person': datapoints[6],
						'gender': datapoints[7],
						'number': datapoints[8],
						'tense': datapoints[9],
						'voice': datapoints[10],
						'mood': datapoints[11],
				})'''
		self.render('analyze.html', passage=passage, versedata=results)
        storytitle = ''
        image_urls = []
        references = ''
        story = ''

        matchobj = re.search(storytitle_pattern, full_content)
        storytitle = matchobj.group(1)
        matchobj = None
        # print('storytitle:',storytitle)

        image_urls = re.findall(image_urls_pattern, full_content)
        # print('image_urls:',image_urls)

        matchobj = re.search(reference_pattern, full_content)
        reference_line = matchobj.group(1)
        references = scriptures.extract(reference_line)
        matchobj = None
        # print('reference:',references)

        story = " ".join(re.findall(story_snippet_pattern, full_content)[:-1])
        story.replace("\t", ' ')
        story.replace("\n", ' ')
        # print('story:',story)
        outputline = str(
            sl_no) + "\t" + storytitle + "\t" + story + "\t" + ', '.join([
                "from " + str(ref[0]) + " " + str(ref[1]) + ":" + str(ref[2]) +
                " to " + str(ref[0]) + " " + str(ref[3]) + ":" + str(ref[4])
                for ref in references
            ]) + "\t" + ", ".join(image_urls) + "\n"
        outputfile.write(outputline)
    else: