forked from openlp/openlp
Make OpenLP run on Python 3.3-3.5
bzr-revno: 2564
This commit is contained in:
commit
6894f92927
@ -27,7 +27,6 @@ import re
|
|||||||
import socket
|
import socket
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.error
|
import urllib.error
|
||||||
from html.parser import HTMLParseError
|
|
||||||
|
|
||||||
from bs4 import BeautifulSoup, NavigableString, Tag
|
from bs4 import BeautifulSoup, NavigableString, Tag
|
||||||
|
|
||||||
@ -290,7 +289,7 @@ class BGExtract(RegistryProperties):
|
|||||||
page_source = str(page_source, 'cp1251')
|
page_source = str(page_source, 'cp1251')
|
||||||
try:
|
try:
|
||||||
soup = BeautifulSoup(page_source)
|
soup = BeautifulSoup(page_source)
|
||||||
except HTMLParseError:
|
except Exception:
|
||||||
log.error('BeautifulSoup could not parse the Bible page.')
|
log.error('BeautifulSoup could not parse the Bible page.')
|
||||||
send_error_message('parse')
|
send_error_message('parse')
|
||||||
return None
|
return None
|
||||||
@ -762,7 +761,7 @@ def get_soup_for_bible_ref(reference_url, header=None, pre_parse_regex=None, pre
|
|||||||
try:
|
try:
|
||||||
soup = BeautifulSoup(page_source)
|
soup = BeautifulSoup(page_source)
|
||||||
CLEANER_REGEX.sub('', str(soup))
|
CLEANER_REGEX.sub('', str(soup))
|
||||||
except HTMLParseError:
|
except Exception:
|
||||||
log.exception('BeautifulSoup could not parse the bible page.')
|
log.exception('BeautifulSoup could not parse the bible page.')
|
||||||
if not soup:
|
if not soup:
|
||||||
send_error_message('parse')
|
send_error_message('parse')
|
||||||
|
@ -23,10 +23,13 @@
|
|||||||
The :mod:`~openlp.plugins.songs.lib.songselect` module contains the SongSelect importer itself.
|
The :mod:`~openlp.plugins.songs.lib.songselect` module contains the SongSelect importer itself.
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
from http.cookiejar import CookieJar
|
from http.cookiejar import CookieJar
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from urllib.request import HTTPCookieProcessor, URLError, build_opener
|
from urllib.request import HTTPCookieProcessor, URLError, build_opener
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
if sys.version_info > (3, 4):
|
||||||
|
from html import unescape
|
||||||
|
|
||||||
|
|
||||||
from bs4 import BeautifulSoup, NavigableString
|
from bs4 import BeautifulSoup, NavigableString
|
||||||
@ -129,11 +132,18 @@ class SongSelectImport(object):
|
|||||||
if not search_results:
|
if not search_results:
|
||||||
break
|
break
|
||||||
for result in search_results:
|
for result in search_results:
|
||||||
song = {
|
if sys.version_info > (3, 4):
|
||||||
'title': self.html_parser.unescape(result.find('h3').string),
|
song = {
|
||||||
'authors': [self.html_parser.unescape(author.string) for author in result.find_all('li')],
|
'title': unescape(result.find('h3').string),
|
||||||
'link': BASE_URL + result.find('a')['href']
|
'authors': [unescape(author.string) for author in result.find_all('li')],
|
||||||
}
|
'link': BASE_URL + result.find('a')['href']
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
song = {
|
||||||
|
'title': self.html_parser.unescape(result.find('h3').string),
|
||||||
|
'authors': [self.html_parser.unescape(author.string) for author in result.find_all('li')],
|
||||||
|
'link': BASE_URL + result.find('a')['href']
|
||||||
|
}
|
||||||
if callback:
|
if callback:
|
||||||
callback(song)
|
callback(song)
|
||||||
songs.append(song)
|
songs.append(song)
|
||||||
@ -167,7 +177,10 @@ class SongSelectImport(object):
|
|||||||
if callback:
|
if callback:
|
||||||
callback()
|
callback()
|
||||||
song['copyright'] = '/'.join([li.string for li in song_page.find('ul', 'copyright').find_all('li')])
|
song['copyright'] = '/'.join([li.string for li in song_page.find('ul', 'copyright').find_all('li')])
|
||||||
song['copyright'] = self.html_parser.unescape(song['copyright'])
|
if sys.version_info > (3, 4):
|
||||||
|
song['copyright'] = unescape(song['copyright'])
|
||||||
|
else:
|
||||||
|
song['copyright'] = self.html_parser.unescape(song['copyright'])
|
||||||
song['ccli_number'] = song_page.find('ul', 'info').find('li').string.split(':')[1].strip()
|
song['ccli_number'] = song_page.find('ul', 'info').find('li').string.split(':')[1].strip()
|
||||||
song['verses'] = []
|
song['verses'] = []
|
||||||
verses = lyrics_page.find('section', 'lyrics').find_all('p')
|
verses = lyrics_page.find('section', 'lyrics').find_all('p')
|
||||||
@ -180,9 +193,15 @@ class SongSelectImport(object):
|
|||||||
else:
|
else:
|
||||||
verse['lyrics'] += '\n'
|
verse['lyrics'] += '\n'
|
||||||
verse['lyrics'] = verse['lyrics'].strip(' \n\r\t')
|
verse['lyrics'] = verse['lyrics'].strip(' \n\r\t')
|
||||||
song['verses'].append(self.html_parser.unescape(verse))
|
if sys.version_info > (3, 4):
|
||||||
|
song['verses'].append(unescape(verse))
|
||||||
|
else:
|
||||||
|
song['verses'].append(self.html_parser.unescape(verse))
|
||||||
for counter, author in enumerate(song['authors']):
|
for counter, author in enumerate(song['authors']):
|
||||||
song['authors'][counter] = self.html_parser.unescape(author)
|
if sys.version_info > (3, 4):
|
||||||
|
song['authors'][counter] = unescape(author)
|
||||||
|
else:
|
||||||
|
song['authors'][counter] = self.html_parser.unescape(author)
|
||||||
return song
|
return song
|
||||||
|
|
||||||
def save_song(self, song):
|
def save_song(self, song):
|
||||||
|
Loading…
Reference in New Issue
Block a user