-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenastro
executable file
·6213 lines (5520 loc) · 222 KB
/
openastro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This file is part of openastro.org.
OpenAstro.org is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenAstro.org is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenAstro.org. If not, see <http://www.gnu.org/licenses/>.
"""
#basics
import math, sys, os.path, datetime, socket, gettext, codecs, webbrowser, pytz
#copyfile
from shutil import copyfile
#pysqlite
import sqlite3
#sqlite3.dbapi2.register_adapter(str, lambda s:s.decode('utf-8')) not needed in python3
#template processing
from string import Template
#minidom parser
from xml.dom.minidom import parseString
#GTK, cairo to display svg
from gi import require_version
require_version('Rsvg', '2.0')
require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GObject, Rsvg, cairo
#internal openastro modules
sys.path.append("/usr/lib/python3.5/dist-packages") #trying to 'fix' some problems importing openastromod on some distros
sys.path.append("/usr/lib/python3.5/site-packages") #trying to 'fix' some problems importing openastromod on some distros
from openastromod import zonetab, geoname, importfile, dignities, swiss as ephemeris
#debug
LOCAL=False
DEBUG=False
VERSION='1.1.59'
#directories
if LOCAL:
DATADIR=os.path.dirname(__file__)
elif os.path.exists(os.path.join(sys.prefix,'share','openastro.org')):
DATADIR=os.path.join(sys.prefix,'share','openastro.org')
elif os.path.exists(os.path.join('usr','local','share','openastro.org')):
DATADIR=os.path.join('usr','local','share','openastro.org')
elif os.path.exists(os.path.join('usr','share','openastro.org')):
DATADIR=os.path.join('usr','share','openastro.org')
else:
print("Exiting... can't find data directory")
sys.exit()
#Translations
LANGUAGES_LABEL={
"ar":"الْعَرَبيّة",
"pt_BR":"Português brasileiro",
"bg":"български език",
"ca":"català",
"cs":"čeština",
"da":"dansk",
"nl":"Nederlands",
"eo":"Esperanto",
"en":"English",
"fi":"suomi",
"fr":"Français",
"de":"Deutsch",
"el":"ελληνικά",
"hu":"magyar nyelv",
"it":"Italiano",
"ja":"日本",
"nds":"Plattdüütsch",
"nb":"Bokmål",
"pl":"język polski",
"rom":"rromani ćhib",
"ru":"Русский",
"es":"Español",
"sv":"svenska",
"uk":"українська мова",
"zh_TW":"正體字"
}
TDomain = os.path.join(DATADIR,'locale')
LANGUAGES=list(LANGUAGES_LABEL.keys())
TRANSLATION={}
for i in range(len(LANGUAGES)):
try:
TRANSLATION[LANGUAGES[i]] = gettext.translation("openastro",TDomain,languages=[LANGUAGES[i]])
except IOError as err:
print("IOError! Invalid languages specified (%s) in %s" %(LANGUAGES[i],TDomain))
TRANSLATION[LANGUAGES[i]] = gettext.translation("openastro",TDomain,languages=['en'])
try:
TRANSLATION["default"] = gettext.translation("openastro",TDomain)
except IOError as err:
print("OpenAstro.org has not yet been translated in your language! Could not load translation...")
TRANSLATION["default"] = gettext.translation("openastro",TDomain,languages=['en'])
#config class
class openAstroCfg:
def __init__(self):
self.version = VERSION
dprint("-------------------------------")
dprint(' OpenAstro.org '+str(self.version))
dprint("-------------------------------")
self.homedir = os.path.expanduser("~")
#check for astrodir
self.astrodir = os.path.join(self.homedir, '.openastro.org')
if os.path.isdir(self.astrodir) == False:
os.mkdir(self.astrodir)
#check for tmpdir
self.tmpdir = os.path.join(self.astrodir, 'tmp')
if os.path.isdir(self.tmpdir) == False:
os.mkdir(self.tmpdir)
#check for swiss local dir
self.swissLocalDir = os.path.join(self.astrodir, 'swiss_ephemeris')
if os.path.isdir(self.swissLocalDir) == False:
os.mkdir(self.swissLocalDir)
#geonames database
self.geonamesdb = os.path.join(DATADIR, 'geonames.sql' )
#icons
icons = os.path.join(DATADIR,'icons')
self.iconWindow = os.path.join(icons, 'openastro.svg')
self.iconAspects = os.path.join(icons, 'aspects')
#basic files
self.tempfilename = os.path.join(self.tmpdir,"openAstroChart.svg")
self.tempfilenameprint = os.path.join(self.tmpdir,"openAstroChartPrint.svg")
self.tempfilenametable = os.path.join(self.tmpdir,"openAstroChartTable.svg")
self.tempfilenametableprint = os.path.join(self.tmpdir,"openAstroChartTablePrint.svg")
self.xml_ui = os.path.join(DATADIR, 'openastro-ui.xml')
self.xml_svg = os.path.join(DATADIR, 'openastro-svg.xml')
self.xml_svg_table = os.path.join(DATADIR, 'openastro-svg-table.xml')
#sqlite databases
self.astrodb = os.path.join(self.astrodir, 'astrodb.sql')
self.peopledb = os.path.join(self.astrodir, 'peopledb.sql')
self.famousdb = os.path.join(DATADIR, 'famous.sql' )
return
def checkSwissEphemeris(self,num):
#00 = -01-600
#06 = 600 - 1200
#12 = 1200 - 1800
#18 = 1800 - 2400
#24 = 2400 - 3000
seas='ftp://ftp.astro.com/pub/swisseph/ephe/seas_12.se1'
semo='ftp://ftp.astro.com/pub/swisseph/ephe/semo_12.se1'
sepl='ftp://ftp.astro.com/pub/swisseph/ephe/sepl_12.se1'
#Sqlite database
class openAstroSqlite:
def __init__(self):
self.dbcheck=False
self.dbpurge="IGNORE"
#--dbcheck puts dbcheck to true
if "--dbcheck" in sys.argv:
self.dbcheck=True
dprint(" Database Check Enabled!")
dprint("-------------------------------")
#--purge purges database
if "--purge" in sys.argv:
self.dbcheck=True
self.dbpurge="REPLACE"
dprint(" Database Check Enabled!")
dprint(" Database Purge Enabled!")
dprint("-------------------------------")
self.open()
#get table names from sqlite_master for astrodb
sql='SELECT name FROM sqlite_master'
self.cursor.execute(sql)
list=self.cursor.fetchall()
self.tables={}
for i in range(len(list)):
self.tables[list[i][0]]=1
#get table names from sqlite_master for peopledb
sql='SELECT name FROM sqlite_master'
self.pcursor.execute(sql)
list=self.pcursor.fetchall()
self.ptables={}
for i in range(len(list)):
self.ptables[list[i][0]]=1
#check for event_natal table in peopledb
self.ptable_event_natal = {
"id":"INTEGER PRIMARY KEY",
"name":"VARCHAR(50)",
"year":"VARCHAR(4)",
"month":"VARCHAR(2)",
"day":"VARCHAR(2)",
"hour":"VARCHAR(50)",
"geolon":"VARCHAR(50)",
"geolat":"VARCHAR(50)",
"altitude":"VARCHAR(50)",
"location":"VARCHAR(150)",
"timezone":"VARCHAR(50)",
"notes":"VARCHAR(500)",
"image":"VARCHAR(250)",
"countrycode":"VARCHAR(2)",
"geonameid":"INTEGER",
"timezonestr":"VARCHAR(100)",
"extra":"VARCHAR(500)"
}
if 'event_natal' not in self.ptables:
sql='CREATE TABLE IF NOT EXISTS event_natal (id INTEGER PRIMARY KEY,name VARCHAR(50)\
,year VARCHAR(4),month VARCHAR(2), day VARCHAR(2), hour VARCHAR(50), geolon VARCHAR(50)\
,geolat VARCHAR(50), altitude VARCHAR(50), location VARCHAR(150), timezone VARCHAR(50)\
,notes VARCHAR(500), image VARCHAR(250), countrycode VARCHAR(2), geonameid INTEGER\
,timezonestr VARCHAR(100), extra VARCHAR(250))'
self.pcursor.execute(sql)
dprint('creating sqlite table event_natal in peopledb')
#check for astrocfg table in astrodb
if 'astrocfg' not in self.tables:
#0=cfg_name, 1=cfg_value
sql='CREATE TABLE IF NOT EXISTS astrocfg (name VARCHAR(150) UNIQUE,value VARCHAR(150))'
self.cursor.execute(sql)
self.dbcheck=True
dprint('creating sqlite table astrocfg in astrodb')
#check for astrocfg version
sql='INSERT OR IGNORE INTO astrocfg (name,value) VALUES(?,?)'
self.cursor.execute(sql,("version",cfg.version))
#get astrocfg dict
sql='SELECT value FROM astrocfg WHERE name="version"'
self.cursor.execute(sql)
self.astrocfg = {}
self.astrocfg["version"]=self.cursor.fetchone()[0]
#check for updated version
if self.astrocfg['version'] != str(cfg.version):
dprint('version mismatch(%s != %s), checking table structure' % (self.astrocfg['version'],cfg.version))
#insert current version and set dbcheck to true
self.dbcheck = True
sql='INSERT OR REPLACE INTO astrocfg VALUES("version","'+str(cfg.version)+'")'
self.cursor.execute(sql)
#default astrocfg keys (if dbcheck)
if self.dbcheck:
dprint('dbcheck astrodb.astrocfg')
default = {
"version":str(cfg.version),
"use_geonames.org":"0",
"houses_system":"P",
"language":"default",
"postype":"geo",
"chartview":"traditional",
"zodiactype":"tropical",
"siderealmode":"FAGAN_BRADLEY"
}
for k, v in default.items():
sql='INSERT OR %s INTO astrocfg (name,value) VALUES(?,?)' % (self.dbpurge)
self.cursor.execute(sql,(k,v))
#get astrocfg dict
sql='SELECT * FROM astrocfg'
self.cursor.execute(sql)
self.astrocfg = {}
for row in self.cursor:
self.astrocfg[row['name']]=row['value']
#install language
self.setLanguage(self.astrocfg['language'])
self.lang_label=LANGUAGES_LABEL
#fix inconsitencies between in people's database
if self.dbcheck:
sql='PRAGMA table_info(event_natal)'
self.pcursor.execute(sql)
list=self.pcursor.fetchall()
vacuum = False
cnames=[]
for i in range(len(list)):
cnames.append(list[i][1])
for key,val in self.ptable_event_natal.items():
if key not in cnames:
sql = 'ALTER TABLE event_natal ADD %s %s'%(key,val)
dprint("dbcheck peopledb.event_natal adding %s %s"%(key,val))
self.pcursor.execute(sql)
vacuum = True
if vacuum:
sql = "VACUUM"
self.pcursor.execute(sql)
dprint('dbcheck peopledb.event_natal: updating table definitions!')
#check for history table in astrodb
if 'history' not in self.tables:
#0=id,1=name,2=year,3=month,4=day,5=hour,6=geolon,7=geolat,8=alt,9=location,10=tz
sql='CREATE TABLE IF NOT EXISTS history (id INTEGER PRIMARY KEY,name VARCHAR(50)\
,year VARCHAR(50),month VARCHAR(50), day VARCHAR(50), hour VARCHAR(50), geolon VARCHAR(50)\
,geolat VARCHAR(50), altitude VARCHAR(50), location VARCHAR(150), timezone VARCHAR(50)\
,notes VARCHAR(500), image VARCHAR(250), countrycode VARCHAR(2), geonameid INTEGER, extra VARCHAR(250))'
self.cursor.execute(sql)
dprint('creating sqlite table history in astrodb')
#fix inconsitencies between 0.6x and 0.7x in history table
if self.dbcheck:
sql='PRAGMA table_info(history)'
self.cursor.execute(sql)
list=self.cursor.fetchall()
cnames=[]
for i in range(len(list)):
cnames.append(list[i][1])
vacuum = False
if "notes" not in cnames:
sql = 'ALTER TABLE history ADD notes VARCHAR(500)'
self.cursor.execute(sql)
vacuum = True
if "image" not in cnames:
sql = 'ALTER TABLE history ADD image VARCHAR(250)'
self.cursor.execute(sql)
vacuum = True
if "countrycode" not in cnames:
sql = 'ALTER TABLE history ADD countrycode VARCHAR(2)'
self.cursor.execute(sql)
vacuum = True
if "geonameid" not in cnames:
sql = 'ALTER TABLE history ADD geonameid INTEGER'
self.cursor.execute(sql)
vacuum = True
if "extra" not in cnames:
sql = 'ALTER TABLE history ADD extra VARCHAR(250)'
self.cursor.execute(sql)
vacuum = True
if vacuum:
sql = "VACUUM"
self.cursor.execute(sql)
dprint('dbcheck: updating history table definitions!')
#check for settings_aspect table in astrodb
if 'settings_aspect' not in self.tables:
sql='CREATE TABLE IF NOT EXISTS settings_aspect (degree INTEGER UNIQUE, name VARCHAR(50)\
,color VARCHAR(50),visible INTEGER, visible_grid INTEGER\
,is_major INTEGER, is_minor INTEGER, orb VARCHAR(5))'
self.cursor.execute(sql)
self.dbcheck=True
dprint('creating sqlite table settings_aspect in astrodb')
#if update, check if everything is in order
if self.dbcheck:
sql='PRAGMA table_info(settings_aspect)'
self.cursor.execute(sql)
list=self.cursor.fetchall()
cnames=[]
for i in range(len(list)):
cnames.append(list[i][1])
vacuum = False
if "visible" not in cnames:
sql = 'ALTER TABLE settings_aspect ADD visible INTEGER'
self.cursor.execute(sql)
vacuum = True
if "visible_grid" not in cnames:
sql = 'ALTER TABLE settings_aspect ADD visible_grid INTEGER'
self.cursor.execute(sql)
vacuum = True
if "is_major" not in cnames:
sql = 'ALTER TABLE settings_aspect ADD is_major INTEGER'
self.cursor.execute(sql)
vacuum = True
if "is_minor" not in cnames:
sql = 'ALTER TABLE settings_aspect ADD is_minor INTEGER'
self.cursor.execute(sql)
vacuum = True
if "orb" not in cnames:
sql = 'ALTER TABLE settings_aspect ADD orb VARCHAR(5)'
self.cursor.execute(sql)
vacuum = True
if vacuum:
sql = "VACUUM"
self.cursor.execute(sql)
#default values for settings_aspect (if dbcheck)
if self.dbcheck:
dprint('dbcheck astrodb.settings_aspect')
degree = [ 0 , 30 , 45 , 60 , 72 , 90 , 120 , 135 , 144 , 150 , 180 ]
name = [ _('conjunction') , _('semi-sextile') , _('semi-square') , _('sextile') , _('quintile') , _('square') , _('trine') , _('sesquiquadrate') , _('biquintile') , _('quincunx') , _('opposition') ]
color = [ '#5757e2' , '#810757' , '#b14e58' , '#d59e28' , '#1f99b3' ,'#dc0000' , '#36d100' , '#985a10' , '#7a9810' , '#fff600' , '#510060' ]
visible = [ 1 , 0 , 0 , 1 , 1 , 1 , 1 , 0 , 1 , 1 , 1 ]
visible_grid = [ 1 , 0 , 0 , 1 , 1 , 1 , 1 , 0 , 1 , 1 , 1 ]
is_major = [ 1 , 0 , 0 , 1 , 0 , 1 , 1 , 0 , 0 , 0 , 1 ]
is_minor = [ 0 , 1 , 1 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 0 ]
orb = [ 10, 3 , 3 , 6 , 2 , 8 , 8 , 3 , 2 , 3 , 10]
#insert values
for i in range(len(degree)):
sql='INSERT OR %s INTO settings_aspect \
(degree, name, color, visible, visible_grid, is_major, is_minor, orb)\
VALUES(%s,"%s","%s",%s,%s,%s,%s,"%s")' % ( self.dbpurge,degree[i],name[i],color[i],visible[i],
visible_grid[i],is_major[i],is_minor[i],orb[i] )
self.cursor.execute(sql)
#check for colors table in astrodb
if 'color_codes' not in self.tables:
sql='CREATE TABLE IF NOT EXISTS color_codes (name VARCHAR(50) UNIQUE\
,code VARCHAR(50))'
self.cursor.execute(sql)
self.dbcheck=True
dprint('creating sqlite table color_codes in astrodb')
#default values for colors (if dbcheck)
self.defaultColors = {
"paper_0":"#000000",
"paper_1":"#ffffff",
"zodiac_bg_0":"#482900",
"zodiac_bg_1":"#6b3d00",
"zodiac_bg_2":"#5995e7",
"zodiac_bg_3":"#2b4972",
"zodiac_bg_4":"#c54100",
"zodiac_bg_5":"#2b286f",
"zodiac_bg_6":"#69acf1",
"zodiac_bg_7":"#ffd237",
"zodiac_bg_8":"#ff7200",
"zodiac_bg_9":"#863c00",
"zodiac_bg_10":"#4f0377",
"zodiac_bg_11":"#6cbfff",
"zodiac_icon_0":"#482900",
"zodiac_icon_1":"#6b3d00",
"zodiac_icon_2":"#5995e7",
"zodiac_icon_3":"#2b4972",
"zodiac_icon_4":"#c54100",
"zodiac_icon_5":"#2b286f",
"zodiac_icon_6":"#69acf1",
"zodiac_icon_7":"#ffd237",
"zodiac_icon_8":"#ff7200",
"zodiac_icon_9":"#863c00",
"zodiac_icon_10":"#4f0377",
"zodiac_icon_11":"#6cbfff",
"zodiac_radix_ring_0":"#ff0000",
"zodiac_radix_ring_1":"#ff0000",
"zodiac_radix_ring_2":"#ff0000",
"zodiac_transit_ring_0":"#ff0000",
"zodiac_transit_ring_1":"#ff0000",
"zodiac_transit_ring_2":"#0000ff",
"zodiac_transit_ring_3":"#0000ff",
"houses_radix_line":"#ff0000",
"houses_transit_line":"#0000ff",
"aspect_0":"#5757e2",
"aspect_30":"#810757",
"aspect_45":"#b14e58",
"aspect_60":"#d59e28",
"aspect_72":"#1f99b3",
"aspect_90":"#dc0000",
"aspect_120":"#36d100",
"aspect_135":"#985a10",
"aspect_144":"#7a9810",
"aspect_150":"#fff600",
"aspect_180":"#510060",
"planet_0":"#984b00",
"planet_1":"#150052",
"planet_2":"#520800",
"planet_3":"#400052",
"planet_4":"#540000",
"planet_5":"#47133d",
"planet_6":"#124500",
"planet_7":"#6f0766",
"planet_8":"#06537f",
"planet_9":"#713f04",
"planet_10":"#4c1541",
"planet_11":"#4c1541",
"planet_12":"#331820",
"planet_13":"#585858",
"planet_14":"#000000",
"planet_15":"#666f06",
"planet_16":"#000000",
"planet_17":"#000000",
"planet_18":"#000000",
"planet_19":"#000000",
"planet_20":"#000000",
"planet_21":"#000000",
"planet_22":"#000000",
"planet_23":"#ff7e00",
"planet_24":"#FF0000",
"planet_25":"#0000FF",
"planet_26":"#000000",
"planet_27":"#000000",
"planet_28":"#000000",
"planet_29":"#000000",
"planet_30":"#000000",
"planet_31":"#000000",
"planet_32":"#000000",
"planet_33":"#000000",
"planet_34":"#000000",
"lunar_phase_0":"#000000",
"lunar_phase_1":"#FFFFFF",
"lunar_phase_2":"#CCCCCC"
}
if self.dbcheck:
dprint('dbcheck astrodb.color_codes')
#insert values
for k,v in self.defaultColors.items():
sql='INSERT OR %s INTO color_codes \
(name, code)\
VALUES("%s","%s")' % ( self.dbpurge , k, v )
self.cursor.execute(sql)
#check for label table in astrodb
if 'label' not in self.tables:
sql='CREATE TABLE IF NOT EXISTS label (name VARCHAR(150) UNIQUE\
,value VARCHAR(200))'
self.cursor.execute(sql)
self.dbcheck=True
dprint('creating sqlite table label in astrodb')
#default values for label (if dbcheck)
self.defaultLabel = {
"cusp":_("Cusp"),
"longitude":_("Longitude"),
"latitude":_("Latitude"),
"north":_("North"),
"east":_("East"),
"south":_("South"),
"west":_("West"),
"apparent_geocentric":_("Apparent Geocentric"),
"true_geocentric":_("True Geocentric"),
"topocentric":_("Topocentric"),
"heliocentric":_("Heliocentric"),
"fire":_("Fire"),
"earth":_("Earth (element)"),
"air":_("Air"),
"water":_("Water"),
"radix":_("Radix"),
"transit":_("Transit"),
"synastry":_("Synastry"),
"composite":_("Composite"),
"combine":_("Combine"),
"solar":_("Solar"),
"secondary_progressions":_("Secondary Progressions")
}
if self.dbcheck:
dprint('dbcheck astrodb.label')
#insert values
for k,v in self.defaultLabel.items():
sql='INSERT OR %s INTO label \
(name, value)\
VALUES("%s","%s")' % ( self.dbpurge , k, v )
self.cursor.execute(sql)
#check for settings_planet table in astrodb
self.table_settings_planet={
"id":"INTEGER UNIQUE",
"name":"VARCHAR(50)",
"color":"VARCHAR(50)",
"visible":"INTEGER",
"element_points":"INTEGER",
"zodiac_relation":"VARCHAR(50)",
"label":"VARCHAR(50)",
"label_short":"VARCHAR(20)",
"visible_aspect_line":"INTEGER",
"visible_aspect_grid":"INTEGER"
}
if 'settings_planet' not in self.tables:
sql='CREATE TABLE IF NOT EXISTS settings_planet (id INTEGER UNIQUE, name VARCHAR(50)\
,color VARCHAR(50),visible INTEGER, element_points INTEGER, zodiac_relation VARCHAR(50)\
,label VARCHAR(50), label_short VARCHAR(20), visible_aspect_line INTEGER\
,visible_aspect_grid INTEGER)'
self.cursor.execute(sql)
self.dbcheck=True
dprint('creating sqlite table settings_planet in astrodb')
#default values for settings_planet (if dbcheck)
if self.dbcheck:
dprint('dbcheck astrodb.settings_planet')
self.value_settings_planet={}
self.value_settings_planet['name'] = [
'sun','moon','mercury','venus','mars','jupiter','saturn',
'uranus','neptune','pluto','mean node','true node','mean apogee','osc. apogee',
'earth','chiron','pholus','ceres','pallas','juno','vesta',
'intp. apogee','intp. perigee','Asc','Mc','Dsc','Ic','day pars',
'night pars','south node', 'marriage pars', 'black sun', 'vulcanus', 'persephone',
'true lilith']
orb = [
#sun
'{0:10,180:10,90:10,120:10,60:6,30:3,150:3,45:3,135:3,72:1,144:1}',
#moon
'{0:10,180:10,90:10,120:10,60:6,30:3,150:3,45:3,135:3,72:1,144:1}',
#mercury
'{0:10,180:10,90:10,120:10,60:6,30:3,150:3,45:3,135:3,72:1,144:1}',
#venus
'{0:10,180:10,90:10,120:10,60:6,30:3,150:3,45:3,135:3,72:1,144:1}',
#mars
'{0:10,180:10,90:10,120:10,60:6,30:3,150:3,45:3,135:3,72:1,144:1}',
#jupiter
'{0:10,180:10,90:10,120:10,60:6,30:3,150:3,45:3,135:3,72:1,144:1}',
#saturn
'{0:10,180:10,90:10,120:10,60:6,30:3,150:3,45:3,135:3,72:1,144:1}',
#uranus
'{0:10,180:10,90:10,120:10,60:6,30:3,150:3,45:3,135:3,72:1,144:1}',
#neptunus
'{0:10,180:10,90:10,120:10,60:6,30:3,150:3,45:3,135:3,72:1,144:1}',
#pluto
'{0:10,180:10,90:10,120:10,60:6,30:3,150:3,45:3,135:3,72:1,144:1}'
]
self.value_settings_planet['label'] = [
_('Sun'),_('Moon'),_('Mercury'),_('Venus'),_('Mars'),_('Jupiter'),_('Saturn'),
_('Uranus'),_('Neptune'),_('Pluto'),_('North Node'),'?',_('Lilith'),_('Osc. Lilith'),
_('Earth'),_('Chiron'),_('Pholus'),_('Ceres'),_('Pallas'),_('Juno'),_('Vesta'),
'intp. apogee','intp. perigee',_('Asc'),_('Mc'),_('Dsc'),_('Ic'),_('Day Pars'),
_('Night Pars'),_('South Node'),_('Marriage Pars'),_('Black Sun'),_('Vulcanus'),
_('Persephone'),_('True Lilith')]
self.value_settings_planet['label_short'] = [
'sun','moon','mercury','venus','mars','jupiter','saturn',
'uranus','neptune','pluto','Node','?','Lilith','?',
'earth','chiron','pholus','ceres','pallas','juno','vesta',
'intp. apogee','intp. perigee','Asc','Mc','Dsc','Ic','DP',
'NP','SNode','marriage','blacksun','vulcanus','persephone','truelilith']
self.value_settings_planet['color'] = [
'#984b00','#150052','#520800','#400052','#540000','#47133d','#124500',
'#6f0766','#06537f','#713f04','#4c1541','#4c1541','#33182','#000000',
'#000000','#666f06','#000000','#000000','#000000','#000000','#000000',
'#000000','#000000','orange','#FF0000','#0000FF','#000000','#000000',
'#000000','#000000','#000000','#000000','#000000','#000000','#000000']
self.value_settings_planet['visible'] = [
1,1,1,1,1,1,1,
1,1,1,1,0,1,0,
0,1,0,0,0,0,0,
0,0,1,1,0,0,1,
1,0,0,0,0,0,0]
self.value_settings_planet['visible_aspect_line'] = [
1,1,1,1,1,1,1,
1,1,1,1,0,1,0,
0,1,0,0,0,0,0,
0,0,1,1,0,0,1,
1,0,0,0,0,0,0]
self.value_settings_planet['visible_aspect_grid'] = [
1,1,1,1,1,1,1,
1,1,1,1,0,1,0,
0,1,0,0,0,0,0,
0,0,1,1,0,0,1,
1,0,0,0,0,0,0]
self.value_settings_planet['element_points'] = [
40,40,15,15,15,10,10,
10,10,10,20,0,0,0,
0,5,0,0,0,0,0,
0,0,40,20,0,0,0,
0,0,0,0,0,0,0]
#zodiac relation gives 10 extra points in element calculation
self.value_settings_planet['zodiac_relation'] = [
'4','3','2,5','1,6','0','8','9',
'10','11','7','-1','-1','-1','-1',
'-1','-1','-1','-1','-1','-1','-1',
'-1','-1','-1','-1','-1','-1','-1',
'-1','-1','-1','-1','-1','-1','-1']
#if update, check if everything is in order with settings_planet
sql='PRAGMA table_info(settings_planet)'
self.cursor.execute(sql)
list=self.cursor.fetchall()
vacuum = False
cnames=[]
for i in range(len(list)):
cnames.append(list[i][1])
for key,val in self.table_settings_planet.items():
if key not in cnames:
sql = 'ALTER TABLE settings_planet ADD %s %s'%(key,val)
dprint("dbcheck astrodb.settings_planet adding %s %s"%(key,val))
self.cursor.execute(sql)
#update values for col
self.cursor.execute("SELECT id FROM settings_planet ORDER BY id DESC LIMIT 1")
c = self.cursor.fetchone()[0]+1
for rowid in range(c):
sql = 'UPDATE settings_planet SET %s=? WHERE id=?' %(key)
self.cursor.execute(sql,(self.value_settings_planet[key][rowid],rowid))
vacuum = True
if vacuum:
sql = "VACUUM"
self.cursor.execute(sql)
#insert values for planets that don't exists
for i in range(len(self.value_settings_planet['name'])):
sql='INSERT OR %s INTO settings_planet VALUES(?,?,?,?,?,?,?,?,?,?)'%(self.dbpurge)
values=(i,
self.value_settings_planet['name'][i],
self.value_settings_planet['color'][i],
self.value_settings_planet['visible'][i],
self.value_settings_planet['element_points'][i],
self.value_settings_planet['zodiac_relation'][i],
self.value_settings_planet['label'][i],
self.value_settings_planet['label_short'][i],
self.value_settings_planet['visible_aspect_line'][i],
self.value_settings_planet['visible_aspect_grid'][i]
)
self.cursor.execute(sql,values)
#commit initial changes
self.updateHistory()
self.link.commit()
self.plink.commit()
self.close()
def setLanguage(self, lang=None):
if lang==None or lang=="default":
TRANSLATION["default"].install()
dprint("installing default language")
else:
TRANSLATION[lang].install()
dprint("installing language (%s)"%(lang))
return
def addHistory(self):
self.open()
sql = 'INSERT INTO history \
(id,name,year,month,day,hour,geolon,geolat,altitude,location,timezone,countrycode) VALUES \
(null,?,?,?,?,?,?,?,?,?,?,?)'
tuple = (openAstro.name,openAstro.year,openAstro.month,openAstro.day,openAstro.hour,
openAstro.geolon,openAstro.geolat,openAstro.altitude,openAstro.location,
openAstro.timezone,openAstro.countrycode)
self.cursor.execute(sql,tuple)
self.link.commit()
self.updateHistory()
self.close()
def getAstrocfg(self,key):
self.open()
sql='SELECT value FROM astrocfg WHERE name="%s"' % key
self.cursor.execute(sql)
one=self.cursor.fetchone()
self.close()
if one == None:
return None
else:
return one[0]
def setAstrocfg(self,key,val):
sql='INSERT OR REPLACE INTO astrocfg (name,value) VALUES (?,?)'
self.query([sql],[(key,val)])
self.astrocfg[key]=val
return
def getColors(self):
self.open()
sql='SELECT * FROM color_codes'
self.cursor.execute(sql)
list=self.cursor.fetchall()
out={}
for i in range(len(list)):
out[list[i][0]] = list[i][1]
self.close()
return out
def getLabel(self):
self.open()
sql='SELECT * FROM label'
self.cursor.execute(sql)
list=self.cursor.fetchall()
out={}
for i in range(len(list)):
out[list[i][0]] = list[i][1]
self.close()
return out
def getDatabase(self):
self.open()
sql = 'SELECT * FROM event_natal ORDER BY id ASC'
self.pcursor.execute(sql)
dict = []
for row in self.pcursor:
s={}
for key,val in self.ptable_event_natal.items():
if row[key] == None:
s[key]=""
else:
s[key]=row[key]
dict.append(s)
self.close()
return dict
def getDatabaseFamous(self,limit="2000",search=None):
self.flink = sqlite3.connect(cfg.famousdb)
self.flink.row_factory = sqlite3.Row
self.fcursor = self.flink.cursor()
if search:
sql='SELECT * FROM famous WHERE year>? AND \
(lastname LIKE ? OR firstname LIKE ? OR name LIKE ?)\
LIMIT %s'%(limit)
self.fcursor.execute(sql,(1800,search,search,search))
else:
sql='SELECT * FROM famous WHERE year>? LIMIT %s'%(limit)
self.fcursor.execute(sql,(1800,))
oldDB=self.fcursor.fetchall()
self.fcursor.close()
self.flink.close()
#process database
newDB = []
for a in range(len(oldDB)):
#minus years
if oldDB[a][12] == '571/': #Muhammad
year = 571
elif oldDB[a][12] <= 0:
year = 1
else:
year = oldDB[a][12]
month = oldDB[a][13]
day = oldDB[a][14]
hour = oldDB[a][15]
h,m,s = openAstro.decHour(hour)
#aware datetime object
dt_input = datetime.datetime(year,month,day,h,m,s)
dt = pytz.timezone(oldDB[a][20]).localize(dt_input)
#naive utc datetime object
dt_utc = dt.replace(tzinfo=None) - dt.utcoffset()
#timezone
timezone=openAstro.offsetToTz(dt.utcoffset())
year = dt_utc.year
month = dt_utc.month
day = dt_utc.day
hour = openAstro.decHourJoin(dt_utc.hour,dt_utc.minute,dt_utc.second)
newDB.append({
"id":oldDB[a][0], #id INTEGER
"name":str(a+1)+". "+oldDB[a][3]+" "+oldDB[a][4], #name
"year":year, #year
"month":month, #month
"day":day, #day
"hour":hour, #hour
"geolon":oldDB[a][18], #geolon
"geolat":oldDB[a][17], #geolat
"altitude":"25", #altitude
"location":oldDB[a][16], #location
"timezone":timezone, #timezone
"notes":"",#notes
"image":"",#image
"countrycode":oldDB[a][8], #countrycode
"geonameid":oldDB[a][19], #geonameid
"timezonestr":oldDB[a][20], #timezonestr
"extra":"" #extra
})
return newDB
def getSettingsPlanet(self):
self.open()
sql = 'SELECT * FROM settings_planet ORDER BY id ASC'
self.cursor.execute(sql)
dict = []
for row in self.cursor:
s={}
for key,val in self.table_settings_planet.items():
s[key]=row[key]
dict.append(s)
self.close()
return dict
def getSettingsAspect(self):
self.open()
sql = 'SELECT * FROM settings_aspect ORDER BY degree ASC'
self.cursor.execute(sql)
dict = []
for row in self.cursor:
#degree, name, color, visible, visible_grid, is_major, is_minor, orb
dict.append({'degree':row['degree'],'name':row['name'],'color':row['color']
,'visible':row['visible'],'visible_grid':row['visible_grid']
,'is_major':row['is_major'],'is_minor':row['is_minor'],'orb':row['orb']})
self.close()
return dict
def getSettingsLocation(self):
#look if location is known
if 'home_location' not in self.astrocfg or 'home_timezonestr' not in self.astrocfg:
self.open()
sql='INSERT OR REPLACE INTO astrocfg (name,value) VALUES("home_location","")'
self.cursor.execute(sql)
sql='INSERT OR REPLACE INTO astrocfg (name,value) VALUES("home_geolat","")'
self.cursor.execute(sql)
sql='INSERT OR REPLACE INTO astrocfg (name,value) VALUES("home_geolon","")'
self.cursor.execute(sql)
sql='INSERT OR REPLACE INTO astrocfg (name,value) VALUES("home_countrycode","")'
self.cursor.execute(sql)
sql='INSERT OR REPLACE INTO astrocfg (name,value) VALUES("home_timezonestr","")'
self.cursor.execute(sql)
self.link.commit()
self.close
return '','','','',''
else:
return self.astrocfg['home_location'],self.astrocfg['home_geolat'],self.astrocfg['home_geolon'],self.astrocfg['home_countrycode'],self.astrocfg['home_timezonestr']
def setSettingsLocation(self, lat, lon, loc, cc, tzstr):
self.open()
sql = 'UPDATE astrocfg SET value="%s" WHERE name="home_location"' % loc
self.cursor.execute(sql)
sql = 'UPDATE astrocfg SET value="%s" WHERE name="home_geolat"' % lat
self.cursor.execute(sql)
sql = 'UPDATE astrocfg SET value="%s" WHERE name="home_geolon"' % lon
self.cursor.execute(sql)
sql = 'UPDATE astrocfg SET value="%s" WHERE name="home_countrycode"' % cc
self.cursor.execute(sql)
sql = 'UPDATE astrocfg SET value="%s" WHERE name="home_timezonestr"' % tzstr
self.cursor.execute(sql)
self.link.commit()
self.close()
def updateHistory(self):
sql='SELECT * FROM history'
self.cursor.execute(sql)
self.history = self.cursor.fetchall()
#check if limit is exceeded
limit=10
if len(self.history) > limit:
sql = "DELETE FROM history WHERE id < '"+str(self.history[len(self.history)-limit][0])+"'"
self.cursor.execute(sql)
self.link.commit()
#update self.history
sql = 'SELECT * FROM history'
self.cursor.execute(sql)
self.history = self.cursor.fetchall()
return
"""
Function to import zet8 databases
"""
def importZet8(self, target_db, data):
target_con = sqlite3.connect(target_db)
target_con.row_factory = sqlite3.Row
target_cur = target_con.cursor()
#get target names
target_names={}
sql='SELECT name FROM event_natal'
target_cur.execute(sql)
for row in target_cur:
target_names[row['name']]=1
for k,v in target_names.items():
for i in range(1,10):
if '%s (#%s)' % (k,i) in target_names:
target_names[k] += 1
#read input write target
for row in data:
if row['name'] in target_names:
name_suffix = ' (#%s)' % target_names[row['name']]
target_names[row['name']] += 1
else:
name_suffix = ''
gname = self.gnearest( float(row['latitude']),float(row['longitude']) )
sql = 'INSERT INTO event_natal (id,name,year,month,day,hour,geolon,geolat,altitude,\
location,timezone,notes,image,countrycode,geonameid,timezonestr,extra) VALUES \
(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'
tuple = (row['name']+name_suffix,row['year'],row['month'],row['day'],row['hour'],row['longitude'],
row['latitude'],25,row['location'],row['timezone'],"",
"",gname['geonameid'],gname['timezonestr'],"")
target_cur.execute(sql,tuple)
#Finished, close connection
target_con.commit()
target_cur.close()
target_con.close()
return
"""
Function to merge two databases containing entries for persons
databaseMerge(target_db,input_db)
database format:
'CREATE TABLE IF NOT EXISTS event_natal (id INTEGER PRIMARY KEY,name VARCHAR(50)\
,year VARCHAR(4),month VARCHAR(2), day VARCHAR(2), hour VARCHAR(50), geolon VARCHAR(50)\
,geolat VARCHAR(50), altitude VARCHAR(50), location VARCHAR(150), timezone VARCHAR(50)\
,notes VARCHAR(500), image VARCHAR(250), countrycode VARCHAR(2), geonameid INTEGER\
,timezonestr VARCHAR(100), extra VARCHAR(250))'