|  09-28-2010, 11:06 PM | #1 | 
| Member  Posts: 14 Karma: 12 Join Date: Jan 2009 Location: Lima, Perú Device: Kindle 2 and Sony Reader PRS 505 | 
				
				I need some help with a recipe
			 
			
			Hello everyone. I'm new with calibre recipes and i need some help with a recipe for 'Muy Interesante' magazine (http://www.muyinteresante.es).  First, i want to change the style for the title of the articles, maybe just to put in bold style. Second, i need to insert a <br> tag after the image in the article, so the text appears below the image and not next to it. The attached image maybe explain better what i want  Thanks in advance!. Here is my recipe: Code: 
from calibre.web.feeds.recipes import BasicNewsRecipe
from BeautifulSoup import BeautifulSoup, Tag
class RevistaMuyInteresante(BasicNewsRecipe):
    title       = 'Revista Muy Interesante'
    __author__  = 'Jefferson Frantz'
    description = 'Revista de divulgacion'
    timefmt = ' [%d %b, %Y]'
    language = 'es_ES'
    keep_only_tags = [dict(name='div', attrs={'class':['article']}),dict(name='td', attrs={'class':['txt_articulo']})]
    remove_tags        = [
                             dict(name=['object','link','script','ul'])
                            ,dict(name='div', attrs={'id':['comment']})
                            ,dict(name='td', attrs={'class':['buttonheading']})
                            ,dict(name='div', attrs={'class':['tags_articles']})
                         ]
    remove_tags_after = dict(name='div', attrs={'class':'tags_articles'})
    def nz_parse_section(self, url):
            soup = self.index_to_soup(url)
            div = soup.find(attrs={'class':'contenido'})
            current_articles = []
            for x in div.findAllNext(attrs={'class':['headline']}):
                    a = x.find('a', href=True)
                    if a is None:
                        continue
                    title = self.tag_to_string(a)
                    url = a.get('href', False)
                    if not url or not title:
                        continue
                    if url.startswith('/'):
                         url = 'http://www.muyinteresante.es'+url
                    self.log('\t\tFound article:', title)
                    self.log('\t\t\t', url)
                    current_articles.append({'title': title, 'url':url,
                        'description':'', 'date':''})
            return current_articles
    def parse_index(self):
            feeds = []
            for title, url in [
                ('Historia',
                 'http://www.muyinteresante.es/historia-articulos'),
             ]:
               articles = self.nz_parse_section(url)
               if articles:
                   feeds.append((title, articles))
            return feeds  | 
|   |   | 
|  09-28-2010, 11:32 PM | #2 | |
| Addict  Posts: 264 Karma: 62 Join Date: May 2010 Device: kindle 2, kindle 3, Kindle fire | Quote: 
 as for the image thing do something like this Spoiler: 
 and as for the bold title or whatever you add extra_css so lets say your title was in a <div class='title'>..... </div> tag and you wanted it different you would do this: Spoiler: 
 Last edited by TonytheBookworm; 09-28-2010 at 11:44 PM. | |
|   |   | 
| Advert | |
|  | 
|  09-29-2010, 01:39 AM | #3 | 
| Addict  Posts: 264 Karma: 62 Join Date: May 2010 Device: kindle 2, kindle 3, Kindle fire | 
			
			Alright time to call the pro in.  Starson17 if you have a second can you look at this and tell me why the image doesn't show up?  My thoughts in this are 
 when i used print statements it showed my newtag as <p> </p> but for whatever reason it never inserts the image data into that tag. thanks for the help in advance. Spoiler: 
 i keep getting this crap: newdiv is: <div><p></p></div> data is: <img style="float: left;" alt="ivision-marrojo" height="225" width="300" src="/images/stories/historia/ivision-marrojo.jpg" /> newtag is: <p></p> which tells me it is obviously picking up the image tag and has it stored. but for whatever reason it refuses to insert it into the newdiv   Last edited by TonytheBookworm; 09-29-2010 at 01:45 AM. | 
|   |   | 
|  09-29-2010, 11:28 AM | #4 | ||
| Wizard            Posts: 4,004 Karma: 177841 Join Date: Dec 2009 Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T | Quote: 
 Quote: 
 Code: data is: <img style="float: left;" alt="ivision-marrojo" height="225" width="300" src="/images/stories/historia/ivision-marrojo.jpg" /> Code:             data = img_tag
            new_img_tag = Tag(soup,'img')
            new_img_tag['src'] = img_tag['src']
            data = new_img_tag | ||
|   |   | 
|  09-29-2010, 12:34 PM | #5 | |
| Addict  Posts: 264 Karma: 62 Join Date: May 2010 Device: kindle 2, kindle 3, Kindle fire | Quote: 
  So could you spoon feed me just a little bit more (i'm not full yet)  thanks. edit: the soup looks like this even after the changes Spoiler: 
 notice the image tag at the beginning is still unchanged shouldn't it have <div><p><img ....... ></p></div> ? Last edited by TonytheBookworm; 09-29-2010 at 12:44 PM. | |
|   |   | 
| Advert | |
|  | 
|  09-29-2010, 01:21 PM | #6 | 
| Wizard            Posts: 4,004 Karma: 177841 Join Date: Dec 2009 Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T | 
			
			I'm not sure what you're asking.  The images appear in the html produced with your code and my changes - they don't appear in your code without them.  The img tag appears in my print of the newdiv tag with my changes, but not with your code.  Do you want me to post your code with my changes, as tested?
		 | 
|   |   | 
|  09-29-2010, 01:49 PM | #7 | |
| Addict  Posts: 264 Karma: 62 Join Date: May 2010 Device: kindle 2, kindle 3, Kindle fire | Quote: 
  here is the code i am using: Spoiler: 
 Last edited by TonytheBookworm; 09-29-2010 at 01:51 PM. Reason: code added | |
|   |   | 
|  10-01-2010, 12:49 AM | #8 | 
| Member  Posts: 14 Karma: 12 Join Date: Jan 2009 Location: Lima, Perú Device: Kindle 2 and Sony Reader PRS 505 | 
			
			Thanks Tony for your help!!! I tried your first suggestion, but the text didn't move below the image  But, this gave me an idea jeje So, after some trial and error i found the solution  ... possibly not the finest, but it works for me  Here is my new recipe: Spoiler: 
 Thanks again!  PS: The solution for the title with the extra_css works like a charm  Last edited by jefferson_frantz; 10-01-2010 at 12:52 AM. | 
|   |   | 
|  10-01-2010, 03:31 PM | #9 | 
| Addict  Posts: 264 Karma: 62 Join Date: May 2010 Device: kindle 2, kindle 3, Kindle fire | 
			
			I'm glad you figured it out.  I battled with it for a while can never could get the image to move but i see how you done it. what i don't understand is why creating the div tags like i was doing didn't work but whatever. If one bullet don't work and the other one does then that is all that matters.
		 | 
|   |   | 
|  11-21-2010, 10:20 AM | #10 | 
| Member  Posts: 10 Karma: 10 Join Date: Nov 2010 Device: nook | 
				
				Revista Muy Interesante
			 | 
|   |   | 
|  11-21-2010, 10:34 AM | #11 | 
| creator of calibre            Posts: 45,604 Karma: 28548974 Join Date: Oct 2006 Location: Mumbai, India Device: Various | 
			
			@zeener: Are there some improvements in your version that should be merged into the builtin recipe?
		 | 
|   |   | 
|  11-22-2010, 06:44 AM | #12 | 
| Member  Posts: 10 Karma: 10 Join Date: Nov 2010 Device: nook | |
|   |   | 
|  11-22-2010, 11:56 AM | #13 | 
| creator of calibre            Posts: 45,604 Karma: 28548974 Join Date: Oct 2006 Location: Mumbai, India Device: Various | 
			
			Can you tell us what the improvements are, makes it easier to test.
		 | 
|   |   | 
|  11-22-2010, 01:40 PM | #14 | 
| Member  Posts: 10 Karma: 10 Join Date: Nov 2010 Device: nook | |
|   |   | 
|  11-22-2010, 02:06 PM | #15 | 
| creator of calibre            Posts: 45,604 Karma: 28548974 Join Date: Oct 2006 Location: Mumbai, India Device: Various | 
			
			Well I've added the get_cover o the builtin recipe, for the rest, let's wait for comments from jefferson_frantz.
		 | 
|   |   | 
|  | 
| 
 | 
|  Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| New recipe | kiklop74 | Recipes | 0 | 10-05-2010 04:41 PM | 
| New recipe | kiklop74 | Recipes | 0 | 10-01-2010 02:42 PM | 
| Recipe Help | lrain5 | Calibre | 3 | 05-09-2010 10:42 PM | 
| Recipe Help | hellonewman | Calibre | 1 | 01-23-2010 03:45 AM | 
| Recipe Help Please | estral | Calibre | 1 | 06-11-2009 02:35 PM |