tImplement HTML output. - tarot - A Tarot engine
 (HTM) git clone https://git.parazyd.org/tarot
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit abef80a993a13f5de9591238dbc4d0594fd5a25d
 (DIR) parent c7b2ae6df8d509dee5450a2578c301154667742b
 (HTM) Author: parazyd <parazyd@dyne.org>
       Date:   Fri, 29 Nov 2019 12:11:21 +0100
       
       Implement HTML output.
       
       Diffstat:
         M tarot.py                            |      66 ++++++++++++++++++++++++-------
       
       1 file changed, 51 insertions(+), 15 deletions(-)
       ---
 (DIR) diff --git a/tarot.py b/tarot.py
       t@@ -2,8 +2,10 @@
        # See LICENSE file for copyright and license details.
        """ Main tarot.py module """
        
       -from random import randint
        from inspect import cleandoc
       +from os.path import join
       +from random import randint
       +from sys import argv
        
        from majorarcana import majorarcana, majorarcana_readings, majorarcana_readers
        
       t@@ -15,12 +17,12 @@ readers = majorarcana_readers
        
        
        cards = [
       -    "+++ Card 1: How you feel about yourself +++",
       -    "+++ Card 2: What you want most right now +++",
       -    "+++ Card 3: Your fears +++",
       -    "+++ Card 4: What is going for you +++",
       -    "+++ Card 5: What is going against you +++",
       -    "+++ Card 6: The likely outcome +++",
       +    'Card 1: How you feel about yourself',
       +    'Card 2: What you want most right now',
       +    'Card 3: Your fears',
       +    'Card 4: What is going for you',
       +    'Card 5: What is going against you',
       +    'Card 6: The likely outcome',
        ]
        
        
       t@@ -28,14 +30,31 @@ def draw_random_card(deck):
            return deck[randint(0, len(deck)-1)]
        
        
       -def main():
       +def main(out='text'):
            reader = readers[randint(0, len(readers)-1)]
            drawn = []
       -
       -    print("======================================")
            index = 0
       +
       +    if out == 'html':
       +        print("""<!DOCTYPE html>
       +              <html lang="en">
       +              <head>
       +                <title>Tarot Card Reading</title>
       +
       +                <style>
       +                body {
       +                    background-color: #eee;
       +                    margin: 2%;
       +                }
       +                </style>
       +              </head>
       +              <body>""")
       +
            for i in cards:
       -        print(i)
       +        if out == 'text':
       +            print('+++ %s +++' % i)
       +        else:
       +            print('<h2 class="cardmeaning">%s</h2>' % i)
                card = None
                while True:
                    if card in drawn or card is None:
       t@@ -44,12 +63,29 @@ def main():
                    drawn.append(card)
                    break
                cardname = list(card.keys())[0]
       -        print("+++ %s +++" % cardname)
       +        if out == 'text':
       +            print('+++ %s +++' % cardname)
       +        else:
       +            print('<h2 class="cardname">%s</h2>' % cardname)
       +        image_path = join('images/majorarcana',
       +                          cardname.lower().replace(' ', '-') + '.jpg')
       +        if out == 'html':
       +            print('<img src="%s">' % image_path)
                desc = readings[index][cardname][reader]
       -        print(cleandoc(desc))
       -        print("\n======================================")
       +        if out == 'text':
       +            print(cleandoc(desc))
       +        else:
       +            print('<p>%s</p>' % cleandoc(desc))
       +            print('<hr>')
                index += 1
        
       +    if out == 'html':
       +        print("""</body>
       +              </html>""")
       +
        
        if __name__ == '__main__':
       -    main()
       +    if len(argv) > 1 and argv[1] == '--html':
       +        main(out='html')
       +    else:
       +        main()