DaveM@13
|
1 import random
|
DaveM@16
|
2 import csv
|
DaveM@16
|
3 import re
|
DaveM@19
|
4 import requests
|
DaveM@19
|
5 import time
|
DaveM@19
|
6 from bs4 import BeautifulSoup
|
DaveM@19
|
7
|
DaveM@16
|
8 import pdb
|
DaveM@16
|
9
|
DaveM@16
|
10 class compatibility:
|
DaveM@16
|
11 def __init__(self):
|
DaveM@16
|
12 self.rules = []
|
DaveM@16
|
13 self.uniqueID = 0
|
DaveM@23
|
14 print 'Warning, need to fix [Vertex, Ascendant House, South Node, IC/MC and None Location] issues'
|
DaveM@16
|
15
|
DaveM@16
|
16 def addRule(self,planetTuple,aspectList,score):
|
DaveM@16
|
17 rule = compatibilityRule(self.uniqueID,planetTuple,aspectList,score)
|
DaveM@16
|
18 self.rules.append(rule)
|
DaveM@16
|
19 self.uniqueID += 1
|
DaveM@16
|
20
|
DaveM@16
|
21 def findRule(self,planet):
|
DaveM@16
|
22 ruleList = [r for r in self.rules if r.planet == planet]
|
DaveM@16
|
23 print ruleList
|
DaveM@16
|
24 return ruleList
|
DaveM@16
|
25
|
DaveM@16
|
26 def readFile(self,filename):
|
DaveM@16
|
27 text = []
|
DaveM@16
|
28 with open(filename) as fp:
|
DaveM@16
|
29 line = fp.readline()
|
DaveM@16
|
30 text.append(line.strip())
|
DaveM@16
|
31 while line:
|
DaveM@16
|
32 line = fp.readline()
|
DaveM@16
|
33 text.append(line.strip())
|
DaveM@16
|
34 return text
|
DaveM@16
|
35
|
DaveM@16
|
36 def parseCompatRules(self,filename):
|
DaveM@16
|
37 comList = self.readFile(filename)
|
DaveM@16
|
38 for com in comList:
|
DaveM@23
|
39 # print com
|
DaveM@23
|
40 planetTuple = None
|
DaveM@23
|
41 aspectList = None
|
DaveM@23
|
42 score = None
|
DaveM@16
|
43 c = com.split(',')
|
DaveM@16
|
44 if len(c) == 4:
|
DaveM@16
|
45 if len(c[1]) > 1:
|
DaveM@16
|
46 aspectList = []
|
DaveM@23
|
47 planetTuple = tuple((c[0].lower(),c[2].lower()))
|
DaveM@19
|
48 score = int(c[3])
|
DaveM@23
|
49 for subset in c[1].lower().split(' '):
|
DaveM@16
|
50 aspectList.append(subset)
|
DaveM@16
|
51 elif len(c[1]) == 0 :
|
DaveM@16
|
52 if 'house' not in c[2]:
|
DaveM@16
|
53 print 'some error where rule is not house'
|
DaveM@16
|
54 planetTuple = (c[0].lower(),'house')
|
DaveM@16
|
55 houseNo = re.findall('\d+', c[2])
|
DaveM@16
|
56 if len(houseNo) != 1:
|
DaveM@16
|
57 print 'multiple house numbers found - ERROR'
|
DaveM@16
|
58 aspectList = int(houseNo[0])
|
DaveM@16
|
59 score = int(c[3])
|
DaveM@23
|
60 self.addRule(planetTuple,aspectList,score)
|
DaveM@16
|
61
|
DaveM@16
|
62 def calcCompatibility(self, horiscope):
|
DaveM@16
|
63 score = 0
|
DaveM@23
|
64 for r in sorted(self.rules):
|
DaveM@16
|
65 if 'vertex' in r.planet:
|
DaveM@16
|
66 # print 'ERROR - catch Vertex issue'
|
DaveM@16
|
67 pass
|
DaveM@23
|
68 elif 'southnode' in r.planet:
|
DaveM@23
|
69 # print 'ERROR - catch South Node issue'
|
DaveM@23
|
70 pass
|
DaveM@23
|
71 # elif 'ic/mc' in r.planet:
|
DaveM@23
|
72 # # print 'ERROR - catch IC/MC issue'
|
DaveM@23
|
73 # pass
|
DaveM@16
|
74 elif r.planet[1] == 'house' and r.planet[0] == 'asc':
|
DaveM@16
|
75 # print 'ERROR - catch Ascendant House issue'
|
DaveM@16
|
76 pass
|
DaveM@16
|
77 elif horiscope.planets[r.planet[0]].angleA is None:
|
DaveM@16
|
78 # print 'Error - None Location'
|
DaveM@16
|
79 return None
|
DaveM@16
|
80 elif r.planet[1] == 'house':
|
DaveM@16
|
81 if horiscope.isInHouse(r.planet[0],r.aspect):
|
DaveM@16
|
82 score += r.score
|
DaveM@23
|
83 print r.planet[0] +' '+ r.planet[1] +' '+ str(aspect)+' '+str(r.score)
|
DaveM@23
|
84 # print r.planet,r.aspect,r.score,score
|
DaveM@23
|
85 elif r.planet[0] == r.planet[1]:
|
DaveM@16
|
86 aspect,variance = horiscope.calcAspect(r.planet[0],r.planet[1])
|
DaveM@16
|
87 if aspect is not None:
|
DaveM@16
|
88 if aspect in r.aspect:
|
DaveM@16
|
89 score += r.score
|
DaveM@23
|
90 print r.planet[0]+' '+aspect +' '+ r.planet[1] +' '+ str(r.score)
|
DaveM@23
|
91 # print r.planet,r.aspect,aspect,r.score,score
|
DaveM@23
|
92 else:
|
DaveM@23
|
93 # print 'query standard synastry'
|
DaveM@23
|
94 for order in [0,1]:
|
DaveM@23
|
95 # print order,not order
|
DaveM@23
|
96 # print r.planet[order],r.planet[not order]
|
DaveM@23
|
97 aspect,variance = horiscope.calcAspect(r.planet[order],r.planet[not order])
|
DaveM@23
|
98 if aspect is not None:
|
DaveM@23
|
99 # print aspect
|
DaveM@23
|
100 # currentR = r
|
DaveM@23
|
101 # pdb.set_trace()
|
DaveM@23
|
102 if aspect in r.aspect:
|
DaveM@23
|
103 score += r.score
|
DaveM@23
|
104 print r.planet[0] +' '+ aspect +' '+ r.planet[1] +' '+ str(r.score)
|
DaveM@23
|
105 # print r.planet,r.aspect,aspect,r.score,score
|
DaveM@23
|
106 # else:
|
DaveM@23
|
107 # print r.planet,r.aspect,aspect,0,score
|
DaveM@23
|
108 print score
|
DaveM@16
|
109 return score
|
DaveM@16
|
110
|
DaveM@19
|
111
|
DaveM@16
|
112
|
DaveM@16
|
113
|
DaveM@16
|
114 class compatibilityRule:
|
DaveM@16
|
115 def __init__(self,uniqueId,planetTuple,aspectList,score):
|
DaveM@16
|
116 self.id = uniqueId
|
DaveM@16
|
117 self.planet = planetTuple
|
DaveM@16
|
118 self.aspect = aspectList
|
DaveM@16
|
119 self.score = score
|
DaveM@13
|
120
|
DaveM@13
|
121 class Person:
|
DaveM@13
|
122 url = 'https://horoscopes.astro-seek.com/calculate-love-compatibility/'
|
DaveM@13
|
123 def __init__(self,personDict):
|
DaveM@13
|
124 # self. = planetPositions()
|
DaveM@13
|
125 self.id = personDict['ID']
|
DaveM@13
|
126 self.dob = personDict['DOB']
|
DaveM@13
|
127 self.tob = personDict['TOB']
|
DaveM@13
|
128 self.cob = personDict['COB']
|
DaveM@13
|
129 self.p_dob = personDict['pDOB']
|
DaveM@13
|
130 self.p_tob = personDict['pTOB']
|
DaveM@13
|
131 self.p_cob = personDict['pCOB']
|
DaveM@13
|
132 self.horiscope = None
|
DaveM@22
|
133 self.resp = None
|
DaveM@13
|
134
|
DaveM@15
|
135 def identifyIssues(self):
|
DaveM@15
|
136 if self.id is None:
|
DaveM@16
|
137 self.issue = 'id'
|
DaveM@15
|
138 elif self.dob is None:
|
DaveM@16
|
139 self.issue = 'dob'
|
DaveM@15
|
140 elif self.tob is None:
|
DaveM@16
|
141 self.issue = 'tob'
|
DaveM@15
|
142 elif self.cob is None:
|
DaveM@16
|
143 self.issue = 'cob'
|
DaveM@15
|
144 elif self.p_dob is None:
|
DaveM@16
|
145 self.issue = 'p_dob'
|
DaveM@15
|
146 elif self.p_tob is None:
|
DaveM@16
|
147 self.issue = 'p_tob'
|
DaveM@15
|
148 elif self.p_cob is None:
|
DaveM@16
|
149 self.issue = 'p_cob'
|
DaveM@15
|
150 else:
|
DaveM@16
|
151 self.issue = None
|
DaveM@16
|
152 return self.issue
|
DaveM@15
|
153
|
DaveM@13
|
154 def makePayload(self):
|
DaveM@13
|
155 if type(self.cob) is str:
|
DaveM@13
|
156 cob_0 = float(self.cob.split(',')[0][1:])
|
DaveM@13
|
157 cob_1 = float(self.cob.split(',')[1])
|
DaveM@13
|
158 self.cob = (cob_0,cob_1)
|
DaveM@13
|
159 if type(self.p_cob) is str:
|
DaveM@13
|
160 pcob_0 = float(self.p_cob.split(',')[0][1:])
|
DaveM@13
|
161 pcob_1 = float(self.p_cob.split(',')[1])
|
DaveM@13
|
162 self.p_cob = (pcob_0,pcob_1)
|
DaveM@13
|
163 if type(self.dob) is str:
|
DaveM@13
|
164 self.dob = self.dob[1:-1].split(',')
|
DaveM@13
|
165 if type(self.p_dob) is str:
|
DaveM@13
|
166 self.p_dob = self.p_dob[1:-1].split(',')
|
DaveM@13
|
167 if type(self.tob) is str:
|
DaveM@13
|
168 self.tob = self.tob[1:-1].split(',')
|
DaveM@13
|
169 if type(self.p_tob) is str:
|
DaveM@13
|
170 self.p_tob = self.p_tob[1:-1].split(',')
|
DaveM@19
|
171
|
DaveM@13
|
172 self.payload = {'send_calculation':'1', #Req
|
DaveM@13
|
173 'muz_narozeni_den':self.dob[0],
|
DaveM@13
|
174 'muz_narozeni_mesic':self.dob[1],
|
DaveM@13
|
175 'muz_narozeni_rok':self.dob[2],
|
DaveM@13
|
176 'muz_narozeni_hodina':self.tob[0],
|
DaveM@13
|
177 'muz_narozeni_minuta':self.tob[1],
|
DaveM@13
|
178 'muz_narozeni_city':'',
|
DaveM@13
|
179 'muz_narozeni_mesto_hidden':'Manually+place%3A+%C2%B0%27N%2C+%C2%B0%27E',#auto
|
DaveM@13
|
180 'muz_narozeni_stat_hidden':'XX',
|
DaveM@13
|
181 'muz_narozeni_podstat_kratky_hidden':'',
|
DaveM@13
|
182 'muz_narozeni_podstat_hidden':'',
|
DaveM@13
|
183 'muz_narozeni_podstat2_kratky_hidden':'',
|
DaveM@13
|
184 'muz_narozeni_podstat3_kratky_hidden':'',
|
DaveM@13
|
185 'muz_narozeni_input_hidden':'',
|
DaveM@13
|
186 'muz_narozeni_sirka_stupne':str(abs(self.cob[0])).split('.')[0],
|
DaveM@13
|
187 'muz_narozeni_sirka_minuty':str(float('0.'+str(self.cob[0]).split('.')[1])*60).split('.')[0],
|
DaveM@13
|
188 'muz_narozeni_sirka_smer': '1' if self.cob[0]<0 else '0', #address N Dir (0':'N',1':'S)
|
DaveM@13
|
189 'muz_narozeni_delka_stupne':str(abs(self.cob[1])).split('.')[0], #address E - Main
|
DaveM@13
|
190 'muz_narozeni_delka_minuty':str(float('0.'+str(self.cob[1]).split('.')[1])*60).split('.')[0],
|
DaveM@13
|
191 'muz_narozeni_delka_smer': '1' if self.cob[1]<0 else '0', #address E Dir (0':'E',1':'W)
|
DaveM@13
|
192 'muz_narozeni_timezone_form':'auto',
|
DaveM@13
|
193 'muz_narozeni_timezone_dst_form':'auto',
|
DaveM@13
|
194 'send_calculation':'1',
|
DaveM@13
|
195 'zena_narozeni_den':self.p_dob[0],
|
DaveM@13
|
196 'zena_narozeni_mesic':self.p_dob[1],
|
DaveM@13
|
197 'zena_narozeni_rok':self.p_dob[2],
|
DaveM@13
|
198 'zena_narozeni_hodina':self.p_tob[0],
|
DaveM@13
|
199 'zena_narozeni_minuta':self.p_tob[1],
|
DaveM@13
|
200 'zena_narozeni_city':'',
|
DaveM@13
|
201 'zena_narozeni_mesto_hidden':'Manually+place%3A+%C2%B0%27N%2C+%C2%B0%27E',
|
DaveM@13
|
202 'zena_narozeni_stat_hidden':'XX',
|
DaveM@13
|
203 'zena_narozeni_podstat_kratky_hidden':'',
|
DaveM@13
|
204 'zena_narozeni_podstat_hidden':'',
|
DaveM@13
|
205 'zena_narozeni_podstat2_kratky_hidden':'',
|
DaveM@13
|
206 'zena_narozeni_podstat3_kratky_hidden':'',
|
DaveM@13
|
207 'zena_narozeni_input_hidden':'',
|
DaveM@13
|
208 'zena_narozeni_sirka_stupne':str(abs(self.p_cob[0])).split('.')[0],
|
DaveM@13
|
209 'zena_narozeni_sirka_minuty':str(float('0.'+str(self.p_cob[0]).split('.')[1])*60).split('.')[0],
|
DaveM@13
|
210 'zena_narozeni_sirka_smer': '1' if self.p_cob[0]<0 else '0',
|
DaveM@13
|
211 'zena_narozeni_delka_stupne':str(abs(self.p_cob[1])).split('.')[0],
|
DaveM@13
|
212 'zena_narozeni_delka_minuty':str(float('0.'+str(self.p_cob[1]).split('.')[1])*60).split('.')[0],
|
DaveM@13
|
213 'zena_narozeni_delka_smer': '1' if self.p_cob[1]<0 else '0',
|
DaveM@13
|
214 'zena_narozeni_timezone_form':'auto',
|
DaveM@13
|
215 'zena_narozeni_timezone_dst_form':'auto',
|
DaveM@13
|
216 'switch_interpretations':'0',
|
DaveM@13
|
217 'house_system':'placidus',
|
DaveM@13
|
218 'uhel_orbis':'#tabs_redraw'}
|
DaveM@13
|
219
|
DaveM@19
|
220 def requestURL(self):
|
DaveM@19
|
221 self.resp = requests.get(self.url, params=self.payload)
|
DaveM@19
|
222 time.sleep(5)
|
DaveM@19
|
223 return self.resp
|
DaveM@19
|
224
|
DaveM@19
|
225 def parsePage(self):
|
DaveM@22
|
226 self.horiscope = None
|
DaveM@22
|
227 if('Please use valid date.' in self.resp.content):
|
DaveM@22
|
228 self.issue = 'dob'
|
DaveM@22
|
229 return self.horiscope
|
DaveM@22
|
230 elif('Please use valid time.' in self.resp.content):
|
DaveM@22
|
231 self.issue = 'tob'
|
DaveM@22
|
232 return self.horiscope
|
DaveM@19
|
233 gotLocation = 0
|
DaveM@19
|
234 self.horiscope = planetPositions()
|
DaveM@19
|
235 soup = BeautifulSoup(self.resp.content, 'lxml')
|
DaveM@19
|
236 tcCell = soup.find_all('div', attrs={'class':'right-sedy-banner-svetlejsi'})
|
DaveM@19
|
237 for cell in tcCell:
|
DaveM@19
|
238 if "Planets in partner's house" in cell.get_text():
|
DaveM@19
|
239 gotLocation = 1
|
DaveM@19
|
240 divList = cell.find_all('div')
|
DaveM@19
|
241 for i in range(len(divList)):
|
DaveM@19
|
242 planetName = divList[i].getText().lower().strip().replace(':','').split(' ')[0]
|
DaveM@19
|
243 if planetName in planetPositions.planetNames:
|
DaveM@19
|
244 if gotLocation and not '/' in planetName:
|
DaveM@19
|
245 self.horiscope.planets[planetName].setHouse(divList[i+2].getText(),divList[i+4].getText())
|
DaveM@19
|
246 else:
|
DaveM@19
|
247 self.horiscope.planets[planetName].setLocation(divList[i+2].getText(),divList[i+1].img.attrs['alt'],0)
|
DaveM@19
|
248 self.horiscope.planets[planetName].setLocation(divList[i+4].getText(),divList[i+3].img.attrs['alt'],1)
|
DaveM@19
|
249 return self.horiscope
|
DaveM@19
|
250
|
DaveM@19
|
251
|
DaveM@13
|
252
|
DaveM@13
|
253 class planetRelation:
|
DaveM@15
|
254 noHouseList = ['asc','ic','dsc','mc','asc/mc','sun/moon']
|
DaveM@19
|
255 zodiacAngle = {'aries':0,'taurus':30,'gemini':60,'cancer':90,'leo':120,'virgo':150,'libra':180,'scorpio':210,'sagittarius':240,'capricorn':270,'aquarius':300,'pisces':330}
|
DaveM@19
|
256
|
DaveM@13
|
257 def __init__(self,planetName):
|
DaveM@13
|
258 self.name = planetName
|
DaveM@13
|
259 self.angleA = None
|
DaveM@13
|
260 self.angleB = None
|
DaveM@15
|
261 if planetName not in planetRelation.noHouseList:
|
DaveM@15
|
262 self.houseA = None
|
DaveM@15
|
263 self.houseB = None
|
DaveM@13
|
264
|
DaveM@19
|
265 def setLocation(self,value,sign,isB):
|
DaveM@19
|
266 signVal = planetRelation.zodiacAngle[sign.lower()]
|
DaveM@19
|
267 signVal+= float('.'.join(value.encode('ascii','replace').split('?'))[:-1])
|
DaveM@19
|
268 # print self.name,sign.lower(),planetRelation.zodiacAngle[sign.lower()],value,signVal
|
DaveM@19
|
269 if not isB:
|
DaveM@19
|
270 self.angleA = signVal
|
DaveM@19
|
271 else:
|
DaveM@19
|
272 self.angleB = signVal
|
DaveM@19
|
273
|
DaveM@15
|
274 def setHouse(self,A,B):
|
DaveM@15
|
275 self.houseA = int(A.encode('ascii','ignore'))
|
DaveM@15
|
276 self.houseB = int(B.encode('ascii','ignore'))
|
DaveM@13
|
277
|
DaveM@13
|
278 def test_random(self):
|
DaveM@13
|
279 self.angleA = random.random()*360
|
DaveM@13
|
280 self.angleB = random.random()*360
|
DaveM@13
|
281
|
DaveM@13
|
282
|
DaveM@13
|
283 class planetPositions:
|
DaveM@23
|
284 aspectDict = {'conjunction':0,'semi-square':45,'sextile':60,'square':90,'trine':120,'opposition':180}
|
DaveM@19
|
285 # zodiacAngle = {'aries':0,'taurus':30,'gemini':60,'cancer':90,'leo':120,'virgo':150,'libra':180,'scorpio':210,'sagittarius':240,'capricorn':270,'aquarius':300,'pisces':330}
|
DaveM@19
|
286 # Taken from https://en.wikipedia.org/wiki/Astrological_sign, with reference from https://en.wikipedia.org/wiki/Astrological_symbols#Signs_of_the_zodiac
|
DaveM@15
|
287 planetNames = ['sun','moon','mercury','venus','mars','jupiter','saturn','uranus','neptune','pluto','node','lilith','chiron','asc','ic','dsc','mc','asc/mc','sun/moon']
|
DaveM@13
|
288 def __init__(self):
|
DaveM@13
|
289 self.planets = {}
|
DaveM@15
|
290 for p in planetPositions.planetNames:
|
DaveM@15
|
291 self.planets[p] = planetRelation(p)
|
DaveM@13
|
292 self.aspect = {}
|
DaveM@13
|
293
|
DaveM@13
|
294 def test_random(self):
|
DaveM@13
|
295 for planet in self.planets:
|
DaveM@13
|
296 self.planets[planet].test_random()
|
DaveM@13
|
297
|
DaveM@13
|
298 def calcAngle(self,componentA,componentB):
|
DaveM@19
|
299 self.angle = abs(self.planets[componentA].angleA - self.planets[componentB].angleB)
|
DaveM@13
|
300 self.angleRange = self.angle-10,self.angle+10
|
DaveM@13
|
301
|
DaveM@13
|
302 def calcAspect(self,componentA,componentB):
|
DaveM@13
|
303 self.calcAngle(componentA,componentB)
|
DaveM@19
|
304 # print componentA,componentB,self.angle,self.planets[componentA].angleA,self.planets[componentB].angleB
|
DaveM@13
|
305 for aspect in planetPositions.aspectDict:
|
DaveM@13
|
306 if self.angleRange[0] < planetPositions.aspectDict[aspect] and self.angleRange[1] > planetPositions.aspectDict[aspect]:
|
DaveM@19
|
307 # print aspect#,componentA,componentB,self.angle
|
DaveM@19
|
308 aspectDiff = round(abs(self.angle - planetPositions.aspectDict[aspect]),2)
|
DaveM@16
|
309 self.aspect[componentA,componentB] = (aspect,aspectDiff)
|
DaveM@16
|
310 return aspect,aspectDiff
|
DaveM@16
|
311 return None,None
|
DaveM@13
|
312
|
DaveM@16
|
313 def isInHouse(self,component,houseNo):
|
DaveM@16
|
314 # print (self.planets[component].houseA,self.planets[component].houseB,houseNo)
|
DaveM@16
|
315 if (self.planets[component].houseA == houseNo) or (self.planets[component].houseB == houseNo):
|
DaveM@16
|
316 return True
|
DaveM@16
|
317 return False
|
DaveM@22
|
318
|
DaveM@22
|
319 def makeAllAspectTreple(self):
|
DaveM@22
|
320 self.aspectTreple = {}
|
DaveM@22
|
321 for p1 in planetPositions.planetNames:
|
DaveM@22
|
322 for p2 in planetPositions.planetNames:
|
DaveM@22
|
323 aspect = self.calcAspect(p1,p2)[0]
|
DaveM@22
|
324 if aspect is not None:
|
DaveM@22
|
325 self.aspectTreple[(p1,p2,aspect)] = 1
|
DaveM@16
|
326
|
DaveM@15
|
327 def calcAllAspects(self):
|
DaveM@15
|
328 for p1 in planetPositions.planetNames:
|
DaveM@15
|
329 for p2 in planetPositions.planetNames:
|
DaveM@15
|
330 self.calcAspect(p1,p2)
|
DaveM@13
|
331
|
DaveM@15
|
332 def printPositions(self):
|
DaveM@15
|
333 for p in planetPositions.planetNames:
|
DaveM@15
|
334 if p in planetRelation.noHouseList:
|
DaveM@15
|
335 print p,self.planets[p].angleA,self.planets[p].angleB
|
DaveM@15
|
336 else:
|
DaveM@15
|
337 print p,self.planets[p].angleA,self.planets[p].angleB,self.planets[p].houseA,self.planets[p].houseB
|
DaveM@13
|
338
|
DaveM@13
|
339
|
DaveM@13
|
340
|
DaveM@13
|
341
|
DaveM@13
|
342
|