mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2026-05-05 11:00:47 +02:00
Removing all filter()/map() calls--not consistent between Py2/Py3.
This commit is contained in:
parent
881c55026f
commit
7e80dacd92
8 changed files with 59 additions and 60 deletions
|
|
@ -4,7 +4,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
|||
print_function)
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2018, Jim Miller'
|
||||
__copyright__ = '2019, Jim Miller'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import logging
|
||||
|
|
@ -299,10 +299,10 @@ class ConfigWidget(QWidget):
|
|||
|
||||
if self.readinglist_tab:
|
||||
# lists
|
||||
prefs['send_lists'] = ', '.join(map( lambda x : x.strip(), filter( lambda x : x.strip() != '', unicode(self.readinglist_tab.send_lists_box.text()).split(','))))
|
||||
prefs['read_lists'] = ', '.join(map( lambda x : x.strip(), filter( lambda x : x.strip() != '', unicode(self.readinglist_tab.read_lists_box.text()).split(','))))
|
||||
# print("send_lists: %s"%prefs['send_lists'])
|
||||
# print("read_lists: %s"%prefs['read_lists'])
|
||||
prefs['send_lists'] = ', '.join([ x.strip() for x in unicode(self.readinglist_tab.send_lists_box.text()).split(',') if x.strip() ])
|
||||
prefs['read_lists'] = ', '.join([ x.strip() for x in unicode(self.readinglist_tab.read_lists_box.text()).split(',') if x.strip() ])
|
||||
logger.debug("send_lists: %s"%prefs['send_lists'])
|
||||
logger.debug("read_lists: %s"%prefs['read_lists'])
|
||||
prefs['addtolists'] = self.readinglist_tab.addtolists.isChecked()
|
||||
prefs['addtoreadlists'] = self.readinglist_tab.addtoreadlists.isChecked()
|
||||
prefs['addtolistsonread'] = self.readinglist_tab.addtolistsonread.isChecked()
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ class FanFicFarePlugin(InterfaceAction):
|
|||
|
||||
mime = 'application/calibre+from_library'
|
||||
if mime_data.hasFormat(mime):
|
||||
dropped_ids = tuple(map(int, str(mime_data.data(mime)).split()))
|
||||
dropped_ids = [ int(x) for x in str(mime_data.data(mime)).split() ]
|
||||
|
||||
mimetype='text/uri-list'
|
||||
filelist="%s"%event.mimeData().data(mimetype)
|
||||
|
|
@ -573,14 +573,12 @@ class FanFicFarePlugin(InterfaceAction):
|
|||
return
|
||||
|
||||
if self.is_library_view():
|
||||
book_list = map( partial(self.make_book_id_only),
|
||||
self.gui.library_view.get_selected_ids() )
|
||||
book_list = [ self.make_book_id_only(x) for x in
|
||||
self.gui.library_view.get_selected_ids() ]
|
||||
|
||||
else: # device view, get from epubs on device.
|
||||
view = self.gui.current_view()
|
||||
rows = view.selectionModel().selectedRows()
|
||||
# paths = view.model().paths(rows)
|
||||
book_list = map( partial(self.make_book_from_device_row), rows )
|
||||
book_list = [ self.make_book_from_device_row(x) for x in
|
||||
self.gui.current_view().selectionModel().selectedRows() ]
|
||||
|
||||
LoopProgressDialog(self.gui,
|
||||
book_list,
|
||||
|
|
@ -625,8 +623,8 @@ class FanFicFarePlugin(InterfaceAction):
|
|||
3000)
|
||||
return
|
||||
|
||||
book_list = map( partial(self.make_book_id_only),
|
||||
self.gui.library_view.get_selected_ids() )
|
||||
book_list = [ self.make_book_id_only(x) for x in
|
||||
self.gui.library_view.get_selected_ids() ]
|
||||
|
||||
tdir = PersistentTemporaryDirectory(prefix='fanficfare_')
|
||||
LoopProgressDialog(self.gui,
|
||||
|
|
@ -686,14 +684,14 @@ class FanFicFarePlugin(InterfaceAction):
|
|||
|
||||
def reject_list_urls(self):
|
||||
if self.is_library_view():
|
||||
book_list = map( partial(self.make_book_id_only),
|
||||
self.gui.library_view.get_selected_ids() )
|
||||
book_list = [ self.make_book_id_only(x) for x in
|
||||
self.gui.library_view.get_selected_ids() ]
|
||||
|
||||
else: # device view, get from epubs on device.
|
||||
view = self.gui.current_view()
|
||||
rows = view.selectionModel().selectedRows()
|
||||
#paths = view.model().paths(rows)
|
||||
book_list = map( partial(self.make_book_from_device_row), rows )
|
||||
book_list = [ self.make_book_from_device_row(x) for x in rows ]
|
||||
|
||||
if len(book_list) == 0 :
|
||||
self.gui.status_bar.show_message(_('No Selected Books have URLs to Reject'), 3000)
|
||||
|
|
@ -887,7 +885,7 @@ class FanFicFarePlugin(InterfaceAction):
|
|||
#print("update_dialog()")
|
||||
|
||||
db = self.gui.current_db
|
||||
books = map( self.make_book_id_only, id_list )
|
||||
books = [ self.make_book_id_only(x) for x in id_list ]
|
||||
|
||||
for j, book in enumerate(books):
|
||||
book['listorder'] = j
|
||||
|
|
@ -1596,15 +1594,15 @@ class FanFicFarePlugin(InterfaceAction):
|
|||
'''Notify calibre about updated rows, update external plugins
|
||||
(Reading Lists & Count Pages) as configured'''
|
||||
|
||||
add_list = filter(lambda x : x['good'] and x['added'], book_list)
|
||||
add_list = [ x for x in book_list if x['good'] and x['added'] ]
|
||||
add_ids = [ x['calibre_id'] for x in add_list ]
|
||||
update_list = filter(lambda x : x['good'] and not x['added'], book_list)
|
||||
update_list = [ x for x in book_list if x['good'] and not x['added'] ]
|
||||
update_ids = [ x['calibre_id'] for x in update_list ]
|
||||
all_ids = add_ids + update_ids
|
||||
all_not_calonly_list = filter(lambda x : x['collision'] not in (CALIBREONLY, CALIBREONLYSAVECOL), add_list + update_list)
|
||||
all_not_calonly_list = [ x for x in add_list + update_list if x['collision'] not in (CALIBREONLY, CALIBREONLYSAVECOL) ]
|
||||
all_not_calonly_ids = [ x['calibre_id'] for x in all_not_calonly_list ]
|
||||
|
||||
failed_list = filter(lambda x : not x['good'] , book_list)
|
||||
failed_list = [ x for x in book_list if not x['good'] ]
|
||||
failed_ids = [ x['calibre_id'] for x in failed_list ]
|
||||
|
||||
if all_not_calonly_ids and \
|
||||
|
|
@ -1655,8 +1653,7 @@ class FanFicFarePlugin(InterfaceAction):
|
|||
## have to be launched separately.
|
||||
if prefs['wordcountmissing'] and 'WordCount' in countpagesstats:
|
||||
# print("numWords:%s"%[ y['all_metadata']['numWords'] for y in add_list + update_list ])
|
||||
wc_ids = [ y['calibre_id'] for y in filter(
|
||||
lambda x : '' == x['all_metadata'].get('numWords',''), add_list + update_list ) ]
|
||||
wc_ids = [ x['calibre_id'] for x in add_list + update_list if '' == x['all_metadata'].get('numWords','') ]
|
||||
## not all need word count
|
||||
# print("wc_ids:%s"%wc_ids)
|
||||
## if lists don't match
|
||||
|
|
@ -1684,8 +1681,8 @@ class FanFicFarePlugin(InterfaceAction):
|
|||
db = self.gui.current_db
|
||||
|
||||
book_list = job.result
|
||||
good_list = filter(lambda x : x['good'], book_list)
|
||||
bad_list = filter(lambda x : not x['good'], book_list)
|
||||
good_list = [ x for x in book_list if x['good'] ]
|
||||
bad_list = [ x for x in book_list if not x['good'] ]
|
||||
good_list = sorted(good_list,key=lambda x : x['listorder'])
|
||||
bad_list = sorted(bad_list,key=lambda x : x['listorder'])
|
||||
#print("book_list:%s"%book_list)
|
||||
|
|
@ -1991,10 +1988,10 @@ class FanFicFarePlugin(InterfaceAction):
|
|||
#print("mi.tags:%s"%mi.tags)
|
||||
# remove old Completed/In-Progress only if there's a new one.
|
||||
if 'Completed' in mi.tags or 'In-Progress' in mi.tags:
|
||||
old_tags = filter( lambda x : x not in ('Completed', 'In-Progress'), old_tags)
|
||||
old_tags = [ x for x in old_tags if x not in ('Completed', 'In-Progress') ]
|
||||
# remove old Last Update tags if there are new ones.
|
||||
if sum(1 for x in mi.tags if not x.startswith("Last Update")):
|
||||
old_tags = filter( lambda x : not x.startswith("Last Update"), old_tags)
|
||||
old_tags = [ x for x in old_tags if not x.startswith("Last Update") ]
|
||||
|
||||
# mi.tags needs to be list, but set kills dups.
|
||||
# this way also removes case-mismatched dups, keeping old_tags version.
|
||||
|
|
@ -2098,11 +2095,11 @@ class FanFicFarePlugin(InterfaceAction):
|
|||
# cliches=>\#acolumn,r
|
||||
for line in configuration.getConfig('custom_columns_settings').splitlines():
|
||||
if "=>" in line:
|
||||
(meta,custcol) = map( lambda x: x.strip(), line.split("=>") )
|
||||
(meta,custcol) = [ x.strip() for x in line.split("=>") ]
|
||||
flag='r'
|
||||
anthaver=False
|
||||
if "," in custcol:
|
||||
(custcol,flag) = map( lambda x: x.strip(), custcol.split(",") )
|
||||
(custcol,flag) = [ x.strip() for x in custcol.split(",") ]
|
||||
anthaver = 'anthaver' in flag
|
||||
flag=flag[0] # first char only.
|
||||
|
||||
|
|
@ -2233,12 +2230,6 @@ class FanFicFarePlugin(InterfaceAction):
|
|||
if not configuration: # might already have it from allow_custcol_from_ini
|
||||
configuration = get_fff_config(book['url'],options['fileform'])
|
||||
|
||||
# template => regexp to match => GC Setting to use.
|
||||
# generate_cover_settings:
|
||||
# ${category} => Buffy:? the Vampire Slayer => Buffy
|
||||
# for line in configuration.getConfig('generate_cover_settings').splitlines():
|
||||
# if "=>" in line:
|
||||
# (template,regexp,setting) = map( lambda x: x.strip(), line.split("=>") )
|
||||
for (template,regexp,setting) in configuration.get_generate_cover_settings():
|
||||
value = Template(template).safe_substitute(book['all_metadata'])
|
||||
# print("%s(%s) => %s => %s"%(template,value,regexp,setting))
|
||||
|
|
@ -2298,7 +2289,7 @@ class FanFicFarePlugin(InterfaceAction):
|
|||
if lists == None or lists.strip() == "" :
|
||||
return []
|
||||
else:
|
||||
return filter( lambda x : x, map( lambda x : x.strip(), lists.split(',') ) )
|
||||
return [ x.strip() for x in lists.split(',') ]
|
||||
|
||||
def update_reading_lists(self,book_ids,add=True):
|
||||
try:
|
||||
|
|
@ -2696,7 +2687,7 @@ def split_text_to_urls(urls):
|
|||
return True
|
||||
else:
|
||||
return False
|
||||
return filter(f,urls.strip().splitlines())
|
||||
return [ x for x in urls.strip().splitlines() if f(x)]
|
||||
|
||||
def escapehtml(txt):
|
||||
return txt.replace("&","&").replace(">",">").replace("<","<")
|
||||
|
|
|
|||
|
|
@ -94,10 +94,10 @@ def do_download_worker(book_list,
|
|||
|
||||
if count >= total:
|
||||
## ordering first by good vs bad, then by listorder.
|
||||
good_list = filter(lambda x : x['good'], book_list)
|
||||
bad_list = filter(lambda x : not x['good'], book_list)
|
||||
good_list = [ x for x in book_list if x['good'] ]
|
||||
bad_list = [ x for x in book_list if not x['good'] ]
|
||||
good_list = sorted(good_list,key=lambda x : x['listorder'])
|
||||
bad_list = sorted(bad_list,key=lambda x : x['listorder'])
|
||||
bad_list = sorted(bad_list,key=lambda x : x['listorder'])
|
||||
|
||||
logger.info("\n"+_("Download Results:")+"\n%s\n"%("\n".join([ "%(url)s %(comment)s" % book for book in good_list+bad_list])))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2011 Fanficdownloader team, 2018 FanFicFare team
|
||||
# Copyright 2011 Fanficdownloader team, 2019 FanFicFare team
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
|
@ -259,8 +259,7 @@ def getConfigSections():
|
|||
def get_bulk_load_sites():
|
||||
# for now, all eFiction Base adapters are assumed to allow bulk_load.
|
||||
sections = set()
|
||||
for cls in filter( lambda x : issubclass(x,base_efiction_adapter.BaseEfictionAdapter),
|
||||
__class_list):
|
||||
for cls in [x for x in __class_list if issubclass(x,base_efiction_adapter.BaseEfictionAdapter) ]:
|
||||
sections.update( [ x.replace('www.','') for x in cls.getConfigSections() ] )
|
||||
return sections
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 FanFicFare team
|
||||
# Copyright 2019 FanFicFare team
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
|
@ -623,13 +623,13 @@ class Chapter(object):
|
|||
return canonicalName
|
||||
|
||||
if re.match(u'жанры?', key, re.UNICODE):
|
||||
genres = filter(bool, map(unicode.strip, re.split(u'[,;/]', value)))
|
||||
genres = [ u.strip() for u in re.split(u'[,;/]', value) ]
|
||||
return {'genres': genres}
|
||||
elif key == u'статус':
|
||||
isInProgress = value == u'в процессе'
|
||||
return {'isInProgress': isInProgress}
|
||||
elif key == u'персонажи':
|
||||
participants = map(refineCharacter, re.split(u'[,;]', value))
|
||||
participants = [ refineCharacter(x) for x in re.split(u'[,;]', value) ]
|
||||
characters = []
|
||||
pairings = []
|
||||
for participant in participants:
|
||||
|
|
@ -710,6 +710,6 @@ def _getLargestCommonPrefix(*args):
|
|||
"""Returns largest common prefix of all unicode arguments, ignoring case.
|
||||
:rtype : unicode
|
||||
"""
|
||||
toLower = lambda xs: map(lambda x: x.lower(), xs)
|
||||
toLower = lambda xs: [ x.lower() for x in xs ]
|
||||
allSame = lambda xs: len(set(toLower(xs))) == 1
|
||||
return u''.join([i[0] for i in takewhile(allSame, izip(*args))])
|
||||
|
|
|
|||
|
|
@ -1,5 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2019 FanFicFare team
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
from __future__ import absolute_import
|
||||
import re
|
||||
import datetime
|
||||
|
|
@ -22,17 +37,12 @@ STORY_URL_TEMPLATE = 'https://www.quotev.com/story/%s'
|
|||
def getClass():
|
||||
return QuotevComAdapter
|
||||
|
||||
|
||||
def get_url_path_segments(url):
|
||||
return tuple(filter(None, url.split('/')[3:]))
|
||||
|
||||
|
||||
class QuotevComAdapter(BaseSiteAdapter):
|
||||
|
||||
def __init__(self, config, url):
|
||||
BaseSiteAdapter.__init__(self, config, url)
|
||||
|
||||
story_id = get_url_path_segments(url)[1]
|
||||
story_id = url.split('/')[4]
|
||||
self._setURL(STORY_URL_TEMPLATE % story_id)
|
||||
self.story.setMetadata('storyId', story_id)
|
||||
self.story.setMetadata('siteabbrev', SITE_DOMAIN)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2015 Fanficdownloader team, 2018 FanFicFare team
|
||||
# Copyright 2015 Fanficdownloader team, 2019 FanFicFare team
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
|
@ -684,7 +684,6 @@ class Configuration(configparser.SafeConfigParser):
|
|||
# split and strip each.
|
||||
def get_config_list(self, sections, key, default=[]):
|
||||
vlist = re.split(r'(?<!\\),',self.get_config(sections,key)) # don't split on \,
|
||||
# was filter( lambda x : x !='', [ v.strip().replace('\,',',') for v in vlist ])
|
||||
vlist = vlist = [x for x in [ v.strip().replace('\,',',') for v in vlist ] if x !='']
|
||||
#print("vlist("+key+"):"+unicode(vlist))
|
||||
if not vlist:
|
||||
|
|
|
|||
|
|
@ -498,7 +498,7 @@ class Story(Configurable):
|
|||
self.chapter_last=last
|
||||
|
||||
def join_list(self, key, vallist):
|
||||
return self.getConfig("join_string_"+key,u", ").replace(SPACE_REPLACE,' ').join(map(unicode, [ x for x in vallist if x is not None ]))
|
||||
return self.getConfig("join_string_"+key,u", ").replace(SPACE_REPLACE,' ').join([ unicode(x) for x in vallist if x is not None ])
|
||||
|
||||
def setMetadata(self, key, value, condremoveentities=True):
|
||||
|
||||
|
|
@ -643,8 +643,8 @@ class Story(Configurable):
|
|||
raise
|
||||
|
||||
for val in retlist:
|
||||
retlist = list(map(partial(self.do_in_ex_clude,'include_metadata_post',key=key,seen_list=seen_list),retlist))
|
||||
retlist = list(map(partial(self.do_in_ex_clude,'exclude_metadata_post',key=key,seen_list=seen_list),retlist))
|
||||
retlist = [ self.do_in_ex_clude('include_metadata_post',x,key=key,seen_list=seen_list) for x in retlist ]
|
||||
retlist = [ self.do_in_ex_clude('exclude_metadata_post',x,key=key,seen_list=seen_list) for x in retlist ]
|
||||
|
||||
if return_list:
|
||||
return retlist
|
||||
|
|
@ -998,7 +998,7 @@ class Story(Configurable):
|
|||
retlist = newretlist
|
||||
|
||||
if removeallentities:
|
||||
retlist = list(map(removeAllEntities,retlist))
|
||||
retlist = [ removeAllEntities(x) for x in retlist ]
|
||||
|
||||
retlist = [x for x in retlist if x!=None and x!='']
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue