Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Recipes

Notices

Reply
 
Thread Tools Search this Thread
Old 05-15-2011, 10:53 AM   #1
xXxXxXxXxXx
Enthusiast
xXxXxXxXxXx began at the beginning.
 
Posts: 37
Karma: 10
Join Date: Apr 2011
Device: none
Recipe for cosmopolitan US

J'd like to create recipe for cosmopolitan US

J want to use print version and in order to do that J need to change url of articles.

for instance:

from:

http://www.cosmopolitan.com/sex-love/dating-advice/tips-for-long-distance-relationships?src=rss

to:

http://www.cosmopolitan.com/print-this/tips-for-long-distance-relationships?src=rss

and J don't know how to do this?

any help?

this is source code:
Code:
class AdvancedUserRecipe1305470859(BasicNewsRecipe):
    title          = u'Cosmopolitan'
    oldest_article = 14
    max_articles_per_feed = 100

    feeds          = [(u'Sex & Love', u'http://www.cosmopolitan.com/sex-love/rss/'), (u'Hair & Beauty', u'http://www.cosmopolitan.com/hairstyles-beauty/rss/'), (u'Celebs & Style', u'http://www.cosmopolitan.com/celebrity/rss/'), (u'Secrets & Advice', u'http://www.cosmopolitan.com/advice/rss/')]

Last edited by xXxXxXxXxXx; 05-15-2011 at 11:24 AM.
xXxXxXxXxXx is offline   Reply With Quote
Old 05-16-2011, 08:37 AM   #2
schuster
Zealot
schuster doesn't litterschuster doesn't litter
 
Posts: 119
Karma: 100
Join Date: Jan 2011
Location: Germany / NRW /Köln
Device: prs-650 / prs-350 /kindle 3
try this

Code:
class AdvancedUserRecipe1305470859(BasicNewsRecipe):
    title          = u'Cosmopolitan Magazin'
    oldest_article = 14
    max_articles_per_feed = 20
    no_stylesheets         = True
    use_embedded_content   = False
    remove_javascript      = True
    cover_url = 'http://www.cosmopolitan.com/cm/shared/site_images/print_this/cosmopolitan_logo.gif'
    extra_css = '''
                    h2{font-family:Arial,Helvetica,sans-serif; font-size: x-small;}
                    h1{ font-family:Arial,Helvetica,sans-serif;  font-size:x-large; font-weight:bold;}
                '''
    remove_tags = [dict(name='div', attrs={'class':'printTools'})]

    def print_version(self,url):
          segments = url.split('/') 
          printURL = '/'.join(segments[0:3]) + '/print-this/' + '/'.join(segments[4:])
          return printURL

    def preprocess_html(self, soup):
        for alink in soup.findAll('a'):
            if alink.string is not None:
               tstr = alink.string
               alink.replaceWith(tstr)
        return soup

    feeds          = [(u'Sex&Love', u'http://www.cosmopolitan.com/sex-love/rss/'),
                          (u'Hair&Beauty', u'http://www.cosmopolitan.com/hairstyles-beauty/rss/'),
                          (u'Celebs & Style', u'http://www.cosmopolitan.com/celebrity/rss/'),
                          (u'Secrets & Advice', u'http://www.cosmopolitan.com/advice/rss/'),
                          (u'Sexy Beauty Secrets Blog', u'http://www.cosmopolitan.com/hairstyles-beauty/beauty-blog/rss/'),
                          (u'Joe Hottie`s Dating Blog', u'http://www.cosmopolitan.com/sex-love/joe-hottie/joe-hottie-rss/'),
                          (u'Bedroom Blog', u'http://www.cosmopolitan.com/sex-love/bedroom-blog/rss/')]
schuster is offline   Reply With Quote
Advert
Old 05-16-2011, 08:56 AM   #3
xXxXxXxXxXx
Enthusiast
xXxXxXxXxXx began at the beginning.
 
Posts: 37
Karma: 10
Join Date: Apr 2011
Device: none
Thank you,
J want to create my own recipe, but J always have problems with changing url to print version,

Could you explain this: (write comment in each line what you do )?

def print_version(self,url):
segments = url.split('/')
printURL = '/'.join(segments[0:3]) + '/print-this/' + '/'.join(segments[4:])
return printURL

def preprocess_html(self, soup):
for alink in soup.findAll('a'):
if alink.string is not None:
tstr = alink.string
alink.replaceWith(tstr)
return soup
xXxXxXxXxXx is offline   Reply With Quote
Old 05-16-2011, 09:08 AM   #4
schuster
Zealot
schuster doesn't litterschuster doesn't litter
 
Posts: 119
Karma: 100
Join Date: Jan 2011
Location: Germany / NRW /Köln
Device: prs-650 / prs-350 /kindle 3
Quote:
Could you explain this:
the explanation is better given from the original sources, i think


Code:
https://www.mobileread.com/forums/showpost.php?p=1231995&postcount=9
Code:
https://www.mobileread.com/forums/showpost.php?p=1488098&postcount=4
hope this helps

greetings
schuster is offline   Reply With Quote
Old 05-16-2011, 09:51 AM   #5
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by schuster View Post
the explanation is better given from the original sources, i think
I've added the description of split/join for URL modification in the print_version context into the code sticky. This question is often asked. See the links there.

https://www.mobileread.com/forums/sho...9&postcount=12
Starson17 is offline   Reply With Quote
Advert
Old 05-16-2011, 10:23 AM   #6
schuster
Zealot
schuster doesn't litterschuster doesn't litter
 
Posts: 119
Karma: 100
Join Date: Jan 2011
Location: Germany / NRW /Köln
Device: prs-650 / prs-350 /kindle 3
good idea
schuster is offline   Reply With Quote
Reply

Tags
recipe


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Recipe works when mocked up as Python file, fails when converted to Recipe ode Recipes 7 09-04-2011 04:57 AM
Recipe for ng.pl markoz Recipes 4 04-13-2011 05:03 PM
recipe please Torx Recipes 0 01-22-2011 12:18 PM
Recipe help kool Recipes 3 10-22-2010 03:34 PM
New recipe kiklop74 Recipes 0 10-01-2010 02:42 PM


All times are GMT -4. The time now is 05:58 AM.


MobileRead.com is a privately owned, operated and funded community.