· 6 years ago · May 17, 2019, 10:20 PM
1from flask import Flask, request, render_template
2from flatlib.datetime import Datetime
3from flatlib.geopos import GeoPos
4from flatlib.chart import Chart
5from flatlib import const
6from flatlib.tools.chartdynamics import ChartDynamics
7from geopy.geocoders import Nominatim
8from quiz_forms import Quiz
9import os
10from openpyxl import Workbook
11from openpyxl.styles import Color, PatternFill, Font, Border, Side, Alignment, Protection
12from openpyxl.styles import colors
13from openpyxl.cell import Cell
14from header import *
15
16app = Flask(__name__)
17app.config["DEBUG"] = True
18app.config['key'] = 'test'
19SECRET_KEY = os.urandom(32)
20app.config['SECRET_KEY'] = SECRET_KEY
21geolocator = Nominatim(user_agent="transits")
22
23
24@app.route("/", methods=["GET", "POST"])
25def quizlet():
26 error = ''
27 form = Quiz()
28 if request.method == 'POST':
29 #TODO grab user input from the form
30 #make the dates
31 #start = int(input('enter a starting year: '))
32 #end = int(input('enter an ending year: ')) + 1
33 dates = []
34 start = 2019
35 end = 2020
36 for y in range(start, end):
37 jan = [str(y) + '/01/' + str(i).zfill(2) for i in range(1,32,7)]
38 feb = [str(y) + '/02/' + str(i).zfill(2) for i in range(1,29,7)]
39 mar = [str(y) + '/03/' + str(i).zfill(2) for i in range(1,32,7)]
40 apr = [str(y) + '/04/' + str(i).zfill(2) for i in range(1,31,7)]
41 may = [str(y) + '/05/' + str(i).zfill(2) for i in range(1,32,7)]
42 jun = [str(y) + '/06/' + str(i).zfill(2) for i in range(1,31,7)]
43 jul = [str(y) + '/07/' + str(i).zfill(2) for i in range(1,32,7)]
44 aug = [str(y) + '/08/' + str(i).zfill(2) for i in range(1,32,7)]
45 sep = [str(y) + '/09/' + str(i).zfill(2) for i in range(1,31,7)]
46 oct = [str(y) + '/10/' + str(i).zfill(2) for i in range(1,32,7)]
47 nov = [str(y) + '/11/' + str(i).zfill(2) for i in range(1,31,7)]
48 dec = [str(y) + '/12/' + str(i).zfill(2) for i in range(1,32,7)]
49 temp = jan + feb + mar + apr + may + jun + jul + aug + sep + oct + nov + dec
50 dates += temp
51
52
53 #initialize excel workbook and geoposition for the chart drawing
54 planets = ['Sun', 'Mercury', 'Venus', 'Mars', 'Jupiter', 'Saturn', 'Chiron', 'Uranus', 'Neptune', 'Pluto']
55 pos = GeoPos('38n32', '8w54')
56 book = Workbook()
57 sheet = book.active
58
59 #user info, will take as input in future
60 natal_date = Datetime('1986/11/11', '11:37', '+00:00')
61 natal_pos = GeoPos('41n55','88w19')
62 natal_chart = Chart(natal_date, natal_pos,IDs=const.LIST_OBJECTS)
63 natal_planets = [natal_chart.get('Sun'),
64 natal_chart.get('Moon'),
65 natal_chart.get('Mercury'),
66 natal_chart.get('Venus'),
67 natal_chart.get('Mars'),
68 natal_chart.get('Jupiter'),
69 natal_chart.get('Saturn'),
70 natal_chart.get('Chiron'),
71 natal_chart.get('Uranus'),
72 natal_chart.get('Neptune'),
73 natal_chart.get('Pluto'),
74 natal_chart.get('North Node'),
75 natal_chart.get('South Node'),
76 natal_chart.get('Asc'),
77 natal_chart.get('Desc'),
78 natal_chart.get('MC'),
79 natal_chart.get('IC')]
80
81 #setup initial cells of sorted planets
82 c = 7
83 send_to_cell(sheet, 6, 1, 'POSITION', grey, 8, black)
84 send_to_cell(sheet, 6, 2, 'PLANET', grey, 8, black)
85 natal_planets.sort(key=lambda x: x.signlon)
86 for planet in natal_planets:
87 send_to_cell(sheet, c, 1, angle.toString(planet.signlon)[1:3] + ' ' + planet.sign[:3] + ' ' + angle.toString(planet.signlon)[4:6], white, 8, elements_font[planet.sign[:3]])
88 send_to_cell(sheet, c, 2, planet.id, white, 8, black)
89 c+=1
90
91 i = 1
92 for object in planets:
93 j = 3
94 send_to_cell(sheet, i+2, j-2, object, tan, 12, black)
95 sheet.merge_cells(start_row=i+2, start_column=j-2, end_row=i+3, end_column=j-1)
96 sheet.merge_cells(start_row=i+4, start_column=j-2, end_row=i+4, end_column=j-1)
97 for d in range(0,len(dates)):
98 retro = False
99 sheet.column_dimensions[get_column_letter(j)].width = 4
100 day = dates[d]
101 if d < len(dates) - 1:
102 next_day = dates [d+1]
103 #print(day + ' ' + next_day)
104 date = Datetime(day, '00:00')
105 next_date = Datetime(next_day, '00:00')
106 chart = Chart(date, pos,IDs=const.LIST_OBJECTS)
107 next_chart = Chart(next_date, pos,IDs=const.LIST_OBJECTS)
108 planet_next = next_chart.get(object)
109 planet = chart.get(object)
110 if planet.lonspeed < 0:
111 fontcolor = 'ffffff'
112 color = red_fill
113 retro = True
114 else:
115 fontcolor = blue
116 color = white
117 retro = False
118 element = elements_fill[planet.sign[:3]]
119 print(angle.toString(planet.signlon)[1:3] + ' ' + planet.sign[:3] + ' ' + angle.toString(planet.signlon)[4:6])
120 send_to_cell(sheet, i,j, month_text[int(day[5:7])], white, 8,black)
121 send_to_cell(sheet, i+1,j, day[5:10], white, 7,black)
122 send_to_cell(sheet, i+2,j, angle.toString(planet.signlon)[1:3], color, 8, fontcolor)
123 send_to_cell(sheet, i+3,j, planet.sign[:3], element, 8, 'ffffff')
124 send_to_cell(sheet, i+4,j, angle.toString(planet.signlon)[4:6], color, 8, fontcolor)
125 send_to_cell(sheet, i+5, j, '', grey, 8,black)
126 for n_planet in natal_planets:
127
128 if (n_planet.signlon >= planet.signlon and n_planet.signlon < planet_next.signlon) and retro == False:
129 #print(n_planet.id + ' aspect found' )
130 send_to_cell(sheet, i+6+natal_planets.index(n_planet),j,nearest_angle(planet.lon - n_planet.lon), white, 8, black)
131 if (n_planet.signlon <= planet.signlon and n_planet.signlon > planet_next.signlon and retro == True):
132 #print(n_planet.id + ' aspect found' )
133 send_to_cell(sheet, i+6+natal_planets.index(n_planet),j,nearest_angle(planet.lon - n_planet.lon), white, 8, black)
134 if (planet.sign is not planet_next.sign) and (n_planet.signlon >= planet.signlon or n_planet.signlon < planet_next.signlon) and retro == False:
135 #print(n_planet.id + ' non-retro sign change aspect found' )
136 send_to_cell(sheet, i+6+natal_planets.index(n_planet),j,nearest_angle(planet.lon - n_planet.lon), white, 8, black)
137 if (planet.sign is not planet_next.sign) and (n_planet.signlon > planet_next.signlon or n_planet.signlon <= planet.signlon) and retro == True:
138 #print(n_planet.id + ' retro sign change2019 aspect found' )
139 send_to_cell(sheet, i+6+natal_planets.index(n_planet),j,nearest_angle(planet.lon - n_planet.lon), white, 8, black)
140 j+=1
141 i += 24
142 set_planet_list(sheet, i+5, 1)
143 book.save('weeklytransits.xlsx')
144
145 return render_template('download_page.html') #pass the workbook somehow?
146
147 return render_template('index.html', form=form)