From 4ac6c3dfddd0ad10d064a5c4a24625d8836b2704 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Sun, 27 Dec 2015 17:12:03 -0600 Subject: [PATCH] Adding additional metadata collection, potionsandsnitches & walkingtheplankorg --- calibre-plugin/plugin-defaults.ini | 12 ++++++ .../adapters/adapter_potionsandsnitches.py | 37 +++++++++++++++++-- .../adapters/adapter_walkingtheplankorg.py | 3 ++ fanficfare/defaults.ini | 12 ++++++ 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/calibre-plugin/plugin-defaults.ini b/calibre-plugin/plugin-defaults.ini index f21fc7e..4d99b24 100644 --- a/calibre-plugin/plugin-defaults.ini +++ b/calibre-plugin/plugin-defaults.ini @@ -2004,9 +2004,18 @@ extracategories:Harry Potter extraships:Harry Potter/Ginny Weasley [www.potionsandsnitches.org] +extra_valid_entries:stars,reviews,reads,takesplaces,snapeflavours,sitetags +stars_label:Frogs +takesplaces_label:Takes Place +snapeflavours_label:Snape Flavour +sitetags_labels:Site Tags + ## Site dedicated to these categories/characters/ships extracategories:Harry Potter +add_to_include_subject_tags:,takesplaces,snapeflavours,sitetags +#add_to_extra_titlepage_entries:,stars,reviews,reads,takesplaces,snapeflavours,sitetags + [www.potterfics.com] ## Site dedicated to these categories/characters/ships extracategories:Harry Potter @@ -2172,6 +2181,9 @@ extracategories:Twilight collect_series: false [www.walkingtheplank.org] +extra_valid_entries:reads +reads_label:Read Count + ## Some sites do not require a login, but do require the user to ## confirm they are adult for adult content. In commandline version, ## this should go in your personal.ini, not defaults.ini. diff --git a/fanficfare/adapters/adapter_potionsandsnitches.py b/fanficfare/adapters/adapter_potionsandsnitches.py index e833d32..d13511d 100644 --- a/fanficfare/adapters/adapter_potionsandsnitches.py +++ b/fanficfare/adapters/adapter_potionsandsnitches.py @@ -126,6 +126,9 @@ class PotionsAndSnitchesOrgSiteAdapter(BaseSiteAdapter): if 'Word count' in label: self.story.setMetadata('numWords', value) + if 'Read' in label: + self.story.setMetadata('reads', value) + if 'Categories' in label: cats = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=categories')) catstext = [cat.string for cat in cats] @@ -142,12 +145,30 @@ class PotionsAndSnitchesOrgSiteAdapter(BaseSiteAdapter): else: self.story.addToList('characters',char.string) + if 'Warning' in label: + warnings = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class')) + for warning in warnings: + self.story.addToList('warnings',stripHTML(warning)) + if 'Genre' in label: genres = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class')) - genrestext = [genre.string for genre in genres] - self.genre = ', '.join(genrestext) - for genre in genrestext: - self.story.addToList('genre',genre.string) + for genre in genres: + self.story.addToList('genre',stripHTML(genre)) + + if 'Takes Place' in label: + takesplaces = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class')) + for takesplace in takesplaces: + self.story.addToList('takesplaces',stripHTML(takesplace)) + + if 'Snape flavour' in label: + snapeflavours = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class')) + for snapeflavour in snapeflavours: + self.story.addToList('snapeflavours',stripHTML(snapeflavour)) + + if 'Tags' in label: + sitetags = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class')) + for sitetag in sitetags: + self.story.addToList('sitetags',stripHTML(sitetag)) if 'Completed' in label: if 'Yes' in value: @@ -183,6 +204,14 @@ class PotionsAndSnitchesOrgSiteAdapter(BaseSiteAdapter): # I find it hard to care if the series parsing fails pass + divsort = soup.find('div',id='sort') + stars = len(divsort.find_all('img',src='images/star.gif')) + stars = stars + 0.5 * len(divsort.find_all('img',src='images/starhalf.gif')) + self.story.setMetadata('stars',stars) + + a = divsort.find_all('a', href=re.compile(r'reviews.php\?type=ST&(amp;)?item='+self.story.getMetadata('storyId')+"$"))[1] # second one. + self.story.setMetadata('reviews',stripHTML(a)) + def getChapterText(self, url): diff --git a/fanficfare/adapters/adapter_walkingtheplankorg.py b/fanficfare/adapters/adapter_walkingtheplankorg.py index abcfc27..f4eeb60 100644 --- a/fanficfare/adapters/adapter_walkingtheplankorg.py +++ b/fanficfare/adapters/adapter_walkingtheplankorg.py @@ -161,6 +161,9 @@ class WalkingThePlankOrgAdapter(BaseSiteAdapter): if 'Word count' in label: self.story.setMetadata('numWords', value) + if 'Read' in label: + self.story.setMetadata('reads', value) + if 'Categories' in label: cats = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=categories')) catstext = [cat.string for cat in cats] diff --git a/fanficfare/defaults.ini b/fanficfare/defaults.ini index 6ab9530..38e93e0 100644 --- a/fanficfare/defaults.ini +++ b/fanficfare/defaults.ini @@ -1986,9 +1986,18 @@ extracategories:Harry Potter extraships:Harry Potter/Ginny Weasley [www.potionsandsnitches.org] +extra_valid_entries:stars,reviews,reads,takesplaces,snapeflavours,sitetags +stars_label:Frogs +takesplaces_label:Takes Place +snapeflavours_label:Snape Flavour +sitetags_labels:Site Tags + ## Site dedicated to these categories/characters/ships extracategories:Harry Potter +add_to_include_subject_tags:,takesplaces,snapeflavours,sitetags +#add_to_extra_titlepage_entries:,stars,reviews,reads,takesplaces,snapeflavours,sitetags + [www.potterfics.com] ## Site dedicated to these categories/characters/ships extracategories:Harry Potter @@ -2154,6 +2163,9 @@ extracategories:Twilight collect_series: false [www.walkingtheplank.org] +extra_valid_entries:reads +reads_label:Read Count + ## Some sites do not require a login, but do require the user to ## confirm they are adult for adult content. In commandline version, ## this should go in your personal.ini, not defaults.ini.