tarot

A Tarot engine
git clone https://git.parazyd.org/tarot
Log | Files | Refs | README | LICENSE

tarot.py (2345B)


      1 #!/usr/bin/env python3
      2 # See LICENSE file for copyright and license details.
      3 """ Main tarot.py module """
      4 
      5 from inspect import cleandoc
      6 from os.path import join
      7 from random import randint
      8 from sys import argv
      9 
     10 from majorarcana import majorarcana, majorarcana_readings, majorarcana_readers
     11 
     12 
     13 # Configuration
     14 card_deck = majorarcana
     15 readings = majorarcana_readings
     16 readers = majorarcana_readers
     17 
     18 
     19 cards = [
     20     'Card 1: How you feel about yourself',
     21     'Card 2: What you want most right now',
     22     'Card 3: Your fears',
     23     'Card 4: What is going for you',
     24     'Card 5: What is going against you',
     25     'Card 6: The likely outcome',
     26 ]
     27 
     28 
     29 def draw_random_card(deck):
     30     return deck[randint(0, len(deck)-1)]
     31 
     32 
     33 def main(out='html'):
     34     reader = readers[randint(0, len(readers)-1)]
     35     drawn = []
     36     index = 0
     37 
     38     if out == 'html':
     39         print("""<!DOCTYPE html>
     40               <html lang="en">
     41               <head>
     42                 <title>Tarot Card Reading</title>
     43 
     44                 <style>
     45                 body {
     46                     background-color: #eee;
     47                     margin: 2%;
     48                 }
     49                 </style>
     50               </head>
     51               <body>""")
     52 
     53     for i in cards:
     54         if out == 'text':
     55             print('+++ %s +++' % i)
     56         else:
     57             print('<h2 class="cardmeaning">%s</h2>' % i)
     58         card = None
     59         while True:
     60             if card in drawn or card is None:
     61                 card = draw_random_card(card_deck)
     62                 continue
     63             drawn.append(card)
     64             break
     65         cardname = list(card.keys())[0]
     66         if out == 'text':
     67             print('+++ %s +++' % cardname)
     68         else:
     69             print('<h2 class="cardname">%s</h2>' % cardname)
     70         image_path = join('images/majorarcana',
     71                           cardname.lower().replace(' ', '-') + '.jpg')
     72         if out == 'html':
     73             print('<img src="%s">' % image_path)
     74         desc = readings[index][cardname][reader]
     75         if out == 'text':
     76             print(cleandoc(desc))
     77         else:
     78             print('<p>%s</p>' % cleandoc(desc))
     79             print('<hr>')
     80         index += 1
     81 
     82     if out == 'html':
     83         print("""</body>
     84               </html>""")
     85 
     86 
     87 if __name__ == '__main__':
     88     if len(argv) > 1 and argv[1] == '--text':
     89         main(out='text')
     90     else:
     91         main(out='html')