view V4/synastry.py @ 15:50a95089414d

updating to allow for all aspects to be calculated, and remove default value passing for people.
author DaveM
date Sun, 04 Mar 2018 17:09:50 +0000
parents b253748dbb11
children b11cff4b7f83
line wrap: on
line source
import random

class Person:
	url = 'https://horoscopes.astro-seek.com/calculate-love-compatibility/'
	def __init__(self,personDict):
		# self. = planetPositions()
		self.id = personDict['ID']
		self.dob = personDict['DOB']
		self.tob = personDict['TOB']
		self.cob = personDict['COB']
		self.p_dob = personDict['pDOB']
		self.p_tob = personDict['pTOB']
		self.p_cob = personDict['pCOB']
		self.horiscope = None

	def identifyIssues(self):
		if self.id is None:
			return 'id'
		elif self.dob is None:
			return 'dob'
		elif self.tob is None:
			return 'tob'
		elif self.cob is None:
			return 'cob'
		elif self.p_dob is None:
			return 'p_dob'
		elif self.p_tob is None:
			return 'p_tob'
		elif self.p_cob is None:
			return 'p_cob'
		else:
			return None

	def makePayload(self):
		if type(self.cob) is str:
			cob_0 = float(self.cob.split(',')[0][1:])
			cob_1 = float(self.cob.split(',')[1])
			self.cob = (cob_0,cob_1)
		if type(self.p_cob) is str:
			pcob_0 = float(self.p_cob.split(',')[0][1:])
			pcob_1 = float(self.p_cob.split(',')[1])
			self.p_cob = (pcob_0,pcob_1)
		if type(self.dob) is str:
			self.dob = self.dob[1:-1].split(',')
		if type(self.p_dob) is str:
			self.p_dob = self.p_dob[1:-1].split(',')
		if type(self.tob) is str:
			self.tob = self.tob[1:-1].split(',')
		if type(self.p_tob) is str:
			self.p_tob = self.p_tob[1:-1].split(',')
		# pdb.set_trace()

		# print dataDict['pDOB']

		self.payload = {'send_calculation':'1', #Req
			'muz_narozeni_den':self.dob[0],
			'muz_narozeni_mesic':self.dob[1],
			'muz_narozeni_rok':self.dob[2],
			'muz_narozeni_hodina':self.tob[0],
			'muz_narozeni_minuta':self.tob[1],
			'muz_narozeni_city':'',
			'muz_narozeni_mesto_hidden':'Manually+place%3A+%C2%B0%27N%2C+%C2%B0%27E',#auto
			'muz_narozeni_stat_hidden':'XX',
			'muz_narozeni_podstat_kratky_hidden':'',
			'muz_narozeni_podstat_hidden':'',
			'muz_narozeni_podstat2_kratky_hidden':'',
			'muz_narozeni_podstat3_kratky_hidden':'',
			'muz_narozeni_input_hidden':'',
			'muz_narozeni_sirka_stupne':str(abs(self.cob[0])).split('.')[0],
			'muz_narozeni_sirka_minuty':str(float('0.'+str(self.cob[0]).split('.')[1])*60).split('.')[0],
			'muz_narozeni_sirka_smer': '1' if self.cob[0]<0 else '0', #address N Dir (0':'N',1':'S)
			'muz_narozeni_delka_stupne':str(abs(self.cob[1])).split('.')[0], #address E - Main
			'muz_narozeni_delka_minuty':str(float('0.'+str(self.cob[1]).split('.')[1])*60).split('.')[0],
			'muz_narozeni_delka_smer': '1' if self.cob[1]<0 else '0', #address E Dir (0':'E',1':'W)
			'muz_narozeni_timezone_form':'auto',
			'muz_narozeni_timezone_dst_form':'auto',
			'send_calculation':'1',
			'zena_narozeni_den':self.p_dob[0],
			'zena_narozeni_mesic':self.p_dob[1],
			'zena_narozeni_rok':self.p_dob[2],
			'zena_narozeni_hodina':self.p_tob[0],
			'zena_narozeni_minuta':self.p_tob[1],
			'zena_narozeni_city':'',
			'zena_narozeni_mesto_hidden':'Manually+place%3A+%C2%B0%27N%2C+%C2%B0%27E',
			'zena_narozeni_stat_hidden':'XX',
			'zena_narozeni_podstat_kratky_hidden':'',
			'zena_narozeni_podstat_hidden':'',
			'zena_narozeni_podstat2_kratky_hidden':'',
			'zena_narozeni_podstat3_kratky_hidden':'',
			'zena_narozeni_input_hidden':'',
			'zena_narozeni_sirka_stupne':str(abs(self.p_cob[0])).split('.')[0],
			'zena_narozeni_sirka_minuty':str(float('0.'+str(self.p_cob[0]).split('.')[1])*60).split('.')[0],
			'zena_narozeni_sirka_smer': '1' if self.p_cob[0]<0 else '0',
			'zena_narozeni_delka_stupne':str(abs(self.p_cob[1])).split('.')[0],
			'zena_narozeni_delka_minuty':str(float('0.'+str(self.p_cob[1]).split('.')[1])*60).split('.')[0],
			'zena_narozeni_delka_smer': '1' if self.p_cob[1]<0 else '0',
			'zena_narozeni_timezone_form':'auto',
			'zena_narozeni_timezone_dst_form':'auto',
			'switch_interpretations':'0',
			'house_system':'placidus',
			'uhel_orbis':'#tabs_redraw'}


class planetRelation:
	noHouseList = ['asc','ic','dsc','mc','asc/mc','sun/moon']
	def __init__(self,planetName):
		self.name = planetName
		self.angleA = None
		self.angleB = None
		if planetName not in planetRelation.noHouseList:
			self.houseA = None
			self.houseB = None

	def setLocation(self,A,B):
		self.angleA = float('.'.join(A.encode('ascii','replace').split('?'))[:-1])
		self.angleB = float('.'.join(B.encode('ascii','replace').split('?'))[:-1])
		# print self.angleA,self.angleB

	def setHouse(self,A,B):
		self.houseA = int(A.encode('ascii','ignore'))
		self.houseB = int(B.encode('ascii','ignore'))
		# print self.houseA,self.houseB

	def test_random(self):
		self.angleA = random.random()*360
		self.angleB = random.random()*360


class planetPositions:
	aspectDict = {'conjunction':0,'semi-square':45,'sextile':60,'square':90,'trine':120,'opposite':180}
	planetNames = ['sun','moon','mercury','venus','mars','jupiter','saturn','uranus','neptune','pluto','node','lilith','chiron','asc','ic','dsc','mc','asc/mc','sun/moon']
	def __init__(self):
		self.planets = {}
		for p in planetPositions.planetNames:
			self.planets[p] = planetRelation(p)
		self.aspect = {}

	def test_random(self):
		for planet in self.planets:
			self.planets[planet].test_random()

	def calcAngle(self,componentA,componentB):
		self.angle = max(self.planets[componentA].angleA,self.planets[componentB].angleB) - min(self.planets[componentA].angleA,self.planets[componentB].angleB)
		self.angleRange = self.angle-10,self.angle+10

	def calcAspect(self,componentA,componentB):
		self.calcAngle(componentA,componentB)
		for aspect in planetPositions.aspectDict:
			if self.angleRange[0] < planetPositions.aspectDict[aspect] and self.angleRange[1] > planetPositions.aspectDict[aspect]:
				self.aspect[componentA,componentB] = aspect
				self.aspectDiff = abs(self.angle - planetPositions.aspectDict[aspect])
				return self.aspect,self.aspectDiff

	def calcAllAspects(self):
		for p1 in planetPositions.planetNames:
			for p2 in planetPositions.planetNames:
				self.calcAspect(p1,p2)

	def printPositions(self):
		for p in planetPositions.planetNames:
			if p in planetRelation.noHouseList:
				print p,self.planets[p].angleA,self.planets[p].angleB
			else:
				print p,self.planets[p].angleA,self.planets[p].angleB,self.planets[p].houseA,self.planets[p].houseB