Create tarot_reading_updated.py

added translated script
This commit is contained in:
Elias Bachaalany 2023-12-26 18:35:19 -08:00
parent f4a72ee5d0
commit ca4f8d3dd6

View file

@ -0,0 +1,66 @@
# Translated version of the provided Python code
import random
import json
import sys
# Define the Major Arcana
major_arcana = [
'The Magician', 'The High Priestess', 'The Empress', 'The Emperor',
'The Hierophant', 'The Lovers', 'The Chariot', 'Justice',
'The Hermit', 'Wheel of Fortune', 'Strength', 'The Hanged Man',
'Death', 'Temperance', 'The Devil', 'The Tower',
'The Star', 'The Moon', 'The Sun', 'Judgment', 'The World', 'The Fool'
]
# Function to generate the Minor Arcana
def generate_minor_arcana():
suits = ['Wands', 'Cups', 'Swords', 'Pentacles']
figures = ['Ace', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Page', 'Knight', 'Queen', 'King']
minor_arcana = []
for suit in suits:
for figure in figures:
minor_arcana.append(f'{figure} of {suit}')
return minor_arcana
# Add the Minor Arcana to the Major to have the complete list of tarot cards
tarot_cards = major_arcana + generate_minor_arcana()
# Function to simulate a tarot reading
def tarot_reading(spread):
reading = {'cards': []}
number_of_cards = 1 # Default one card
if spread == 'three-card':
number_of_cards = 3
elif spread == 'celtic-cross':
number_of_cards = 10
elif spread == 'single-card': # Added to allow the drawing of a single card
number_of_cards = 1
# Ensure that cards do not repeat in a reading
selected_cards = random.sample(tarot_cards, number_of_cards)
for card in selected_cards:
position = random.choice(['upright', 'reversed'])
reading['cards'].append({'name': card, 'position': position})
return reading
# This would be the function that receives the call from GPT-4
def function_calling(spread_type):
# Get the result of the reading
reading_result = tarot_reading(spread_type)
# Convert the result to JSON for output
print(json.dumps(reading_result))
if __name__ == "__main__":
# Take the type of spread from the command line
if len(sys.argv) < 2:
print("Usage: python tarot.py [single-card | three-card | celtic-cross]")
else:
spread_type = sys.argv[1]
function_calling(spread_type)