text: # coding=utf-8
  
  books = (
      {
          'template_id': 0,
          'template_text_file': 'When_I_met_the_Pirates.txt',
          'template_dir': 'When_I_met_the_Pirates',
          'title': 'When I met the Pirates',
          'title_brief': 'Pirates',
          'title_RO': u'Aventuri cu pirații',
          'title_IT': 'Avventure coi pirati',
          'sku': 'SKU #83321',
          'languages': 'English, Italian, Romanian',
          'issuu_id': '8868387/4252762',
          'cover_image': 'When_I_met_the_Pirates.jpg',
          'bookimg_girl': 'cover_pirates_girl.jpg',
          'bookimg_boy': 'cover_pirates.jpg',
          'sidebar_pic': 'rustic_pirate.jpg',
          'prot_boy': 'prot_pirate_boy.jpg',
          'prot_girl': 'prot_pirate_girl.jpg',
          'sex_recomm': 'MF',
          'default_sex': 'MF',
          'age_recomm_min': 5,
          'age_recomm_max': 12,
          'price_eurocents': 0,
          'author_img': 'dana.jpg',
          'author_name': 'FableMe',
          'author_ill': 'Noha Elhady',
          'author_desc': """Anna Petrescu is Chief Officer at FableMe, and a recognized writer
                                of fables and novels for teenagers. She has a beautiful daughter, 
                                Diana, who is the first passionate lover of FableMe.com fables!""",
          'desc_title': 'A great adventure...',
          'desc_desc': """This is a beautiful pirate story for boys and girls all over the world.
                              The hero/heroine joins an interesting crew made of a dog pirate, a cat pirate, 
                              a parrot pirate and a rat pirate. Together they sail the seas and have 
                              a lot of fun.""",
          'desc_short': """The hero/heroine joins an interesting crew made of a dog pirate, a cat pirate,
                              a parrot pirate and a rat pirate. Together they sail the seas and have 
                              a lot of fun...."""
  
      },
      {
          'template_id': 1,
          'template_text_file': 'My_voyage_to_Aragon.txt',
          'template_dir': 'My_voyage_to_Aragon',
          'title': 'My voyage to Aragon',
          'title_brief': 'Aragon',
          'title_RO': u'Voiajul meu în Aragon',
          'title_IT': 'Il mio viaggio ad Aragon',
          'sku': 'SKU #83203',
          'languages': 'English, Italian, Romanian',
          'issuu_id': '8025851/5449283',
          'cover_image': 'My_voyage_to_Aragon.jpg',
          'bookimg_girl': 'cover_voyage.jpg',
          'bookimg_boy': 'cover_voyage_boy.jpg',
          'sex_recomm': 'MF',
          'default_sex': 'MF',
          'age_recomm_min': 5,
          'age_recomm_max': 12,
          'price_eurocents': 0,
          'sidebar_pic': 'Anna.jpg',
          'prot_boy': 'prot_voyage_boy.jpg',
          'prot_girl': 'prot_voyage_girl.jpg',
          'author_img': 'dana.jpg',
          'author_name': 'FableMe',
          'author_ill': 'Noha Elhady',
          'author_desc': """Anna Petrescu is Chief Officer at FableMe, and a recognized writer
                                    of fables and novels for teenagers. She has a beautiful daughter, 
                                    Diana, who is the first passionate lover of FableMe.com fables!""",
          'desc_title': 'A dream comes true',
          'desc_desc': """This is the story of a little prince/princess who travels
                                  to the land of Aragon and discovers that wisdom (knowledge) and wit
                                  (perception and learning) are both needed in life. It is written 
                                  with a medieval feel and as a rhyming ode. The story follows 
                                  the hero/heroine who is riding to school on his/her pony and becomes distracted 
                                  when they meet a fox. Accompanied by the pony and the fox, a fantastic journey 
                                  through the forest begins.""",
          'desc_short': """A beautiful prince/princess travels
                                  to the land of Aragon and discovers that wisdom and wit
                                  are both needed in life..."""
  
      },
      {
          'template_id': 2,
          'template_text_file': 'The_talisman_of_the_Badia.txt',
          'template_dir': 'The_talisman_of_the_Badia',
          'title': 'The Amazing story of the Badia Talisman',
          'title_brief': 'Badia',
          'title_RO': 'Povestea talismanului din Badia',
          'title_IT': 'La fantastica storia del talismano della Badia',
          'sku': 'SKU #83232',
          'languages': 'English, Italian, Romanian',
          'issuu_id': '8868387/6765671',
          'cover_image': 'The_talisman_of_the_Badia.jpg',
          'bookimg_girl': 'cover_badia.jpg',
          'bookimg_boy': 'cover_badia.jpg',
          'sex_recomm': 'MF',
          'default_sex': 'MF',
          'age_recomm_min': 8,
          'age_recomm_max': 16,
          'price_eurocents': 0,
          'sidebar_pic': 'Capture.jpg',
          'prot_boy': 'prot_badia_boy.jpg',
          'prot_girl': 'prot_badia_girl.jpg',
          'author_img': 'alessio.jpg',
          'author_name': 'FableMe',
          'author_ill': 'Teodora Reytor',
          'author_desc': """Alessio Saltarin is an italian writer of novels and short-stories.
                                In his spare time he designs and programs videogames.""",
          'desc_title': 'An old tale retold again',
          'desc_desc': """In a green and flat land crossed by a river whose waters flowed
                              impetuous and full of fish, a young princess is imprisoned in the
                              high tower of a castle. A young prince, the so-called God-Of-The-Turks,
                              comes out of the blue to rescue her. A classic fable for every
                              dreamer boy or girl.""",
          'desc_short': """A young princess is imprisoned in the
                              high tower of a castle. A young prince, the so-called God-Of-The-Turks,
                              comes out of the blue to rescue her..."""
      },
      {
          'template_id': 3,
          'template_text_file': 'Cinderella.txt',
          'template_dir': 'Cinderella',
          'title': 'Cinderella',
          'title_brief': 'Cinderella',
          'title_RO': u'Cenuşăreasa',
          'title_IT': 'Cenerentola',
          'sku': 'SKU #83232',
          'languages': 'English, Italian, Romanian',
          'issuu_id': '8868387/55010296',
          'cover_image': 'cover_cinderella.jpg',
          'bookimg_girl': 'cover_cinderella.jpg',
          'bookimg_boy': 'cover_cinderella.jpg',
          'sex_recomm': 'F',
          'default_sex': 'F',
          'age_recomm_min': 5,
          'age_recomm_max': 12,
          'price_eurocents': 0,
          'sidebar_pic': 'Capture.jpg',
          'prot_boy': 'prot_cinderella_boy.jpg',
          'prot_girl': 'prot_cinderella_girl.jpg',
          'author_img': 'GrimmBrothers.jpg',
          'author_name': 'Jacob Grimm, Wilhelm Grimm',
          'author_ill': 'Teodora Reytor',
          'author_desc': """The Brothers Grimm (or Die Brüder Grimm), Jacob (1785–1863) and Wilhelm Grimm (1786–1859), were
                            German academics, linguists, cultural researchers, lexicographers and authors who together 
                            specialized in collecting and publishing folklore during the 19th century. They were among the 
                            best-known storytellers of folk tales, and popularized stories such as "Cinderella" 
                            ("Aschenputtel"), "The Frog Prince" ("Der Froschkönig"), "Hansel and Gretel" 
                            ("Hänsel und Gretel"), "Rapunzel", "Rumpelstiltskin" ("Rumpelstilzchen"), and "Snow White" 
                            ("Schneewittchen"). Their first collection of folk tales, Children's and Household Tales 
                            (Kinder- und Hausmärchen), was published in 1812.""",
          'desc_title': 'Cinderella',
          'desc_desc': """Cinderella is living happily with her mother and father until her mother dies.
                              Cinderella's father remarries a cold, cruel woman who has two cruel daughters who turn her into a servant 
                              in her own house. Meanwhile, across town in the castle, the King invites every eligible maiden in the 
                              kingdom to a fancy ball, where his son will be able to choose his bride. Cinderella has no suitable 
                              party dress for a ball but a fairy godmother helps her. At the ball Cinderella dances with the Prince
                              who falls in love with her. However, at the stroke of midnight ... """,
          'desc_short': """Cinderella is the story of a girl that after the death of her mother becomes a servant for her step mother
                               and two step sisters. With the help of a fairy godmother she turns into a beautiful princess and goes 
                               to the ball at the castle where the prince falls in love with her. When the clock turns..."""
      },
      {
          'template_id': 4,
          'template_text_file': 'TomThumb.txt',
          'template_dir': 'TomThumb',
          'title': 'Tom Thumb',
          'title_brief': 'Tom Thumb ',
          'title_RO': u'Degețel',
          'title_IT': 'Pollicino',
          'sku': 'SKU #83232',
          'languages': 'English, Italian, Romanian',
          'issuu_id': '8868387/55010352',
          'cover_image': 'cover_tomthumb.jpg',
          'bookimg_girl': 'cover_tomthumb.jpg',
          'bookimg_boy': 'cover_tomthumb.jpg',
          'sex_recomm': 'M',
          'default_sex': 'M',
          'age_recomm_min': 5,
          'age_recomm_max': 12,
          'price_eurocents': 0,
          'sidebar_pic': 'Capture.jpg',
          'prot_boy': 'prot_tomthumb_boy.jpg',
          'prot_girl': 'prot_tomthumb_girl.jpg',
          'author_img': 'GrimmBrothers.jpg',
          'author_name': 'Jacob Grimm, Wilhelm Grimm',
          'author_ill': 'Teodora Reytor',
          'author_desc': """The Brothers Grimm (or Die Brüder Grimm), Jacob (1785–1863) and Wilhelm Grimm (1786–1859), were
                            German academics, linguists, cultural researchers, lexicographers and authors who together 
                            specialized in collecting and publishing folklore during the 19th century. They were among the 
                            best-known storytellers of folk tales, and popularized stories such as "Cinderella" 
                            ("Aschenputtel"), "The Frog Prince" ("Der Froschkönig"), "Hansel and Gretel" 
                            ("Hänsel und Gretel"), "Rapunzel", "Rumpelstiltskin" ("Rumpelstilzchen"), and "Snow White" 
                            ("Schneewittchen"). Their first collection of folk tales, Children's and Household Tales 
                            (Kinder- und Hausmärchen), was published in 1812.""",
          'desc_title': 'Little Thumb',
          'desc_desc': """Little Thumb is a tale about a little boy who is as small as his mother’s thumb. The tale begins with
                              a farmer and his wife who are desperate for a child. The wife gets pregnant and after a while Thumb appears. 
                              The world is a dangerous place for little Thumb and the tale focuses on some of his many adventures.
                              He is sold by his father to two strangers, is eaten by a cow, then by a wolf. Finally he goes back home 
                              to live happily ever after. The story is personalized with the child’s name. """,
          'desc_short': """Little Thumb is a tale about a little boy who is as small as his mother’s thumb. The world is a dangerous
                               place for little Thumb and the tale focuses on some of his many adventures. He is sold by his father 
                               to two strangers, is eaten by a cow, then by a wolf. Finally he goes back home to live happily ever after. 
                               The story is personalized with the child’s name..."""
      },
      {
          'template_id': 5,
          'template_text_file': 'JackBeanstalk.txt',
          'template_dir': 'JackBeanstalk',
          'title': 'The magical beanstalk',
          'title_brief': 'The magical beanstalk',
          'title_RO': u'Vrejul de fasole fermecat',
          'title_IT': 'Il fagiolo magico',
          'sku': 'SKU #83232',
          'languages': 'English, Italian, Romanian',
          'issuu_id': '8868387/55010885',
          'cover_image': 'cover_jackbeanstalck.jpg',
          'bookimg_girl': 'cover_jackbeanstalck.jpg',
          'bookimg_boy': 'cover_jackbeanstalck.jpg',
          'sex_recomm': 'M',
          'default_sex': 'M',
          'age_recomm_min': 5,
          'age_recomm_max': 12,
          'price_eurocents': 0,
          'sidebar_pic': 'Capture.jpg',
          'prot_boy': 'prot_tomthumb_boy.jpg',
          'prot_girl': 'prot_tomthumb_girl.jpg',
          'author_img': 'JosephJacobs.jpg',
          'author_name': 'Joseph Jacobs ',
          'author_ill': 'Teodora Reytor',
          'author_desc': """ (29 August 1854 – 30 January 1916) was an Australian folklorist, literary critic, historian and
                              writer of English literature who became a notable collector and publisher of English Folklore. 
                              His work went on to popularize some of the world's best known versions of English fairy tales 
                              including "Jack and the Beanstalk", "Goldilocks and the three bears", "The Three Little Pigs", 
                              "Jack the Giant Killer" and "The History of Tom Thumb". He published his English fairy tale 
                              collections: English Fairy Tales in 1890 and More English Fairytales in 1894 but also went on
                              after and in between both books to publish fairy tales collected from continental Europe 
                              as well as Jewish, Celtic and Indian Fairytales which made him one of the most popular writers 
                              of fairytales for the English language.""",
          'desc_title': 'The magical beanstalk',
          'desc_desc': """A poor boy lives with his mother out of selling to the market the milk from their cow. One day the cow
                              stops giving milk and the boy takes the cow to market to sell it. On the way he meets a strange man 
                              who gives him five magic beans in exchange for the cow. His angry mother throws the beans into the garden. 
                              Overnight the beans grow into a huge beanstalk and the boy climbs up. At the top he
                              finds a castle where a giant and his wife live... """,
          'desc_short': """A poor boy living with his mother takes their only cow to the market to sell it.
                               On the way he meets a strange man who gives him five magic beans in exchange for the cow. 
                               The beans grow into a huge beanstalk on top of which a giant lives..."""
      },
      {
          'template_id': 6,
          'template_text_file': 'SleepingBeauty.txt',
          'template_dir': 'SleepingBeauty',
          'title': 'Sleeping Beauty',
          'title_brief': 'Sleeping Beauty',
          'title_RO': u'Frumoasa din pădurea adormită',
          'title_IT': 'La bella addormentata nel bosco',
          'sku': 'SKU #83232',
          'languages': 'English, Italian, Romanian',
          'issuu_id': '8868387/55010753',
          'cover_image': 'cover_sleepingbeauty.jpg',
          'bookimg_girl': 'cover_sleepingbeauty.jpg',
          'bookimg_boy': 'cover_sleepingbeauty.jpg',
          'sex_recomm': 'F',
          'default_sex': 'F',
          'age_recomm_min': 5,
          'age_recomm_max': 12,
          'price_eurocents': 0,
          'sidebar_pic': 'Capture.jpg',
          'prot_boy': 'prot_sleepingbeauty_boy.jpg',
          'prot_girl': 'prot_sleepingbeauty_girl.jpg',
          'author_img': 'GrimmBrothers.jpg',
          'author_name': 'Jacob Grimm, Wilhelm Grimm',
          'author_ill': 'Teodora Reytor',
          'author_desc': """The Brothers Grimm (or Die Brüder Grimm), Jacob (1785–1863) and Wilhelm Grimm (1786–1859), were
                            German academics, linguists, cultural researchers, lexicographers and authors who together 
                            specialized in collecting and publishing folklore during the 19th century. They were among the 
                            best-known storytellers of folk tales, and popularized stories such as "Cinderella" 
                            ("Aschenputtel"), "The Frog Prince" ("Der Froschkönig"), "Hansel and Gretel" 
                            ("Hänsel und Gretel"), "Rapunzel", "Rumpelstiltskin" ("Rumpelstilzchen"), and "Snow White" 
                            ("Schneewittchen"). Their first collection of folk tales, Children's and Household Tales 
                            (Kinder- und Hausmärchen), was published in 1812. """,
          'desc_title': 'Sleeping Beauty',
          'desc_desc': """A king slights the oldest fairy of thirteen in the kingdom and she curses the King's newborn princess
                              saying she will die on her fifteenth birthday by pricking her finger on a spinning wheel.  The twelfth softens 
                              the curse so that the princess will only fall asleep for one hundred years...""",
          'desc_short': """A king’s new born daughter is cursed by an evil fairy to die on her fifteenth birthday by pricking
                               her finger on a spinning wheel. She does pricks her finger falling down in a deep sleep and one hundred 
                               years later a princess awakens her with a kiss..."""
      },
      {
          'template_id': 7,
          'template_text_file': 'RedCap.txt',
          'template_dir': 'RedCap',
          'title': 'Red Cap',
          'title_brief': 'RedCap',
          'title_RO': u'Scufița roșie',
          'title_IT': 'Cappuccetto rosso',
          'sku': 'SKU #83232',
          'languages': 'English, Italian, Romanian',
          'issuu_id': '8868387/55010704',
          'cover_image': 'cover_redcap.jpg',
          'bookimg_girl': 'cover_redcap.jpg',
          'bookimg_boy': 'cover_redcap.jpg',
          'sex_recomm': 'F',
          'default_sex': 'F',
          'age_recomm_min': 5,
          'age_recomm_max': 12,
          'price_eurocents': 0,
          'sidebar_pic': 'Capture.jpg',
          'prot_boy': 'prot_redcap_boy.jpg',
          'prot_girl': 'prot_redcap_girl.jpg',
          'author_img': 'GrimmBrothers.jpg',
          'author_name': 'Jacob Grimm, Wilhelm Grimm',
          'author_ill': 'Teodora Reytor',
          'author_desc': """The Brothers Grimm (or Die Brüder Grimm), Jacob (1785–1863) and Wilhelm Grimm (1786–1859), were
                            German academics, linguists, cultural researchers, lexicographers and authors who together 
                            specialized in collecting and publishing folklore during the 19th century. They were among the 
                            best-known storytellers of folk tales, and popularized stories such as "Cinderella" 
                            ("Aschenputtel"), "The Frog Prince" ("Der Froschkönig"), "Hansel and Gretel" 
                            ("Hänsel und Gretel"), "Rapunzel", "Rumpelstiltskin" ("Rumpelstilzchen"), and "Snow White" 
                            ("Schneewittchen"). Their first collection of folk tales, Children's and Household Tales 
                            (Kinder- und Hausmärchen), was published in 1812. """,
          'desc_title': 'Red Cap',
          'desc_desc': """This is the well-known story of a little girl, Little Red Riding Hood, who is sent by her mother to take 
                          some food to her grandmother who is sick. In the woods she meets the wolf and she tells him where 
                          she is going. The wolf goes ahead of her and eats her grandmother and then waits for Little Red Riding Hood to 
                          come and eats her too. A woodcutter kills the wolf and rescues the girl and her grandmother.""",
          'desc_short': """This is the well-known story of a little girl, Little Red Riding Hood, who is sent by her mother to take
                           some food to her grandmother who is sick. Trouble begins when in the woods she meets the wolf..."""
      },
      {
          'template_id': 8,
          'template_text_file': 'Rapunzel.txt',
          'template_dir': 'Rapunzel',
          'title': 'Rapunzel',
          'title_brief': 'Rapunzel',
          'title_RO': u'Rapunzel',
          'title_IT': 'Raperenzolo',
          'sku': 'SKU #83232',
          'languages': 'English, Italian, Romanian',
          'issuu_id': '8868387/55010523',
          'cover_image': 'cover_rapunzel.jpg',
          'bookimg_girl': 'cover_rapunzel.jpg',
          'bookimg_boy': 'cover_rapunzel.jpg',
          'sex_recomm': 'F',
          'default_sex': 'F',
          'age_recomm_min': 5,
          'age_recomm_max': 12,
          'price_eurocents': 0,
          'sidebar_pic': 'Capture.jpg',
          'prot_boy': 'prot_rapunzel_boy.jpg',
          'prot_girl': 'prot_rapunzel_girl.jpg',
          'author_img': 'GrimmBrothers.jpg',
          'author_name': 'Jacob Grimm, Wilhelm Grimm',
          'author_ill': 'Teodora Reytor',
          'author_desc': """The Brothers Grimm (or Die Brüder Grimm), Jacob (1785–1863) and Wilhelm Grimm (1786–1859), were
                            German academics, linguists, cultural researchers, lexicographers and authors who together 
                            specialized in collecting and publishing folklore during the 19th century. They were among the 
                            best-known storytellers of folk tales, and popularized stories such as "Cinderella" 
                            ("Aschenputtel"), "The Frog Prince" ("Der Froschkönig"), "Hansel and Gretel" 
                            ("Hänsel und Gretel"), "Rapunzel", "Rumpelstiltskin" ("Rumpelstilzchen"), and "Snow White" 
                            ("Schneewittchen"). Their first collection of folk tales, Children's and Household Tales 
                            (Kinder- und Hausmärchen), was published in 1812. """,
          'desc_title': 'Rapunzel',
          'desc_desc': """The story of Rapunzel begins with a husband stealing rapunzel from a sorceress’s garden for his wife. 
                          He is caught in act by the angry sorceress and in return for sparing his life she demands that the husband 
                          promise her the newborn child, whom she will name Rapunzel. There follows the well-known story of a 
                          long-haired girl kept in an inaccessible tower, and a prince who finds her and wins her heart.""",
          'desc_short': """This is the well-known story of a long-haired girl kept raised by a sorceress in an inaccessible tower,
                           and a prince who finds her and wins her heart...."""
      }
  )
  
  
  class Book(object):
      """ Incapsulates the books dictionary into a class """
  
      def __init__(self, book_id):
          self.dictionary = books[book_id]
          for k, v in self.dictionary.items():
              setattr(self, k, v)
  
      @property
      def price(self):
          if self.dictionary.get('price_eurocents') == 0:
              return "FREE!"
          book_price = float(self.dictionary.get('price_eurocents') / 100.0)
          return '€ {0:.2f}'.format(book_price)
  
      def recommendation(self, sexonly=False):
          recomm = "Recommended for "
          age_min = self.dictionary['age_recomm_min']
          age_max = self.dictionary['age_recomm_max']
          sex_recomm = self.dictionary['sex_recomm']
          if sex_recomm == 'M':
              recomm += " boys"
          elif sex_recomm == 'F':
              recomm += " girls"
          else:
              recomm += " boys and girls"
          if not sexonly:
              recomm += " aged "
              recomm += str(age_min)
              recomm += "-"
              recomm += str(age_max)
              recomm += " years"
          recomm += "."
          return recomm
  
  
  def get_books(starting_index, ending_index):
      books_collection = []
      for i in range(starting_index, ending_index):
          books_collection.append(Book(i))
      return books_collection
  
  
  def get_all_books():
      return get_books(0, len(books))
  
  
  def get_classic_books():
      return get_books(3, len(books))
  
  
  def get_fableme_books():
      return get_books(0, 3)
  
  
  def get_leftright_books(tbooks):
      books_leftright = []
      books_array = [None, None]
      for i in range(1, len(tbooks)+1):
          if i % 2 != 0:
              books_array[0] = tbooks[i-1]
              if i == len(tbooks):
                  books_array[1] = None
                  books_leftright.append(books_array)
          else:
              books_array[1] = tbooks[i-1]
              books_leftright.append(books_array)
              books_array = [None, None]
      return books_leftright
  
  
  def get_book_template(book_id):
      return books[int(book_id)]
  