-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStellar.py
More file actions
108 lines (81 loc) · 3.14 KB
/
Stellar.py
File metadata and controls
108 lines (81 loc) · 3.14 KB
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
# -*- coding: utf-8 -*-
"""
Some stuff to query the database
"""
# System imports
import base64
import configparser
import os
import sys
# peewee imports
from peewee import Model, MySQLDatabase
from peewee import FloatField, CharField, PrimaryKeyField, IntegerField, ForeignKeyField, DecimalField
# Reading the configuration file
Config = configparser.ConfigParser()
configfile = os.path.expanduser("~") + '/.Astro/config'
if os.path.isfile(configfile):
Config.read(configfile)
else:
print('A MySQL configuration file is required. The file should be located be ~/Astro/config . For safety reasons, it should have as little permissions as possible. The file should be in the INI format, with a MySQL section that contains the username and password of the user that will connect to the database')
sys.exit(0)
user = Config.get('MySQL', 'user')
password = base64.encodebytes(bytes(Config.get('MySQL', 'passwd'), "utf-8"))
database = MySQLDatabase('Stellar', **{'password': base64.decodebytes(password).decode(), 'user': user})
# deleting the password.
del password
class UnknownField(object):
pass
class BaseModel(Model):
class Meta:
database = database
class Star(BaseModel):
declination = FloatField(null=True)
epoch = CharField(null=True)
idstar = PrimaryKeyField(db_column='idStar')
name = CharField(unique=True)
pmdec = FloatField(db_column='pmDEC', null=True)
pmra = FloatField(db_column='pmRA', null=True)
rightascension = FloatField(null=True)
class Meta:
db_table = 'Star'
class Abundance(BaseModel):
carbon = FloatField(db_column='Carbon', null=True)
oxygen = FloatField(db_column='Oxygen', null=True)
titanium = FloatField(db_column='Titanium', null=True)
idabundance = PrimaryKeyField(db_column='idAbundance')
starid = ForeignKeyField(db_column='starid', rel_model=Star, to_field='idstar')
class Meta:
db_table = 'Abundance'
class Gravity(BaseModel):
gravity = FloatField(index=True)
idgravity = PrimaryKeyField(db_column='idGravity')
starid = ForeignKeyField(db_column='starid', rel_model=Star, to_field='idstar')
class Meta:
db_table = 'Gravity'
class Magnitude(BaseModel):
bmag = DecimalField()
hmag = DecimalField()
idmagnitude = PrimaryKeyField(db_column='idMagnitude')
imag = DecimalField()
jmag = DecimalField()
kmag = DecimalField()
rmag = DecimalField()
starid = ForeignKeyField(db_column='starid', rel_model=Star, to_field='idstar')
umag = DecimalField()
vmag = DecimalField(max_digits=10, decimal_places=3)
class Meta:
db_table = 'Magnitude'
class Name(BaseModel):
alternatename = CharField(index=True)
idname = PrimaryKeyField(db_column='idName')
starid = ForeignKeyField(db_column='starid', rel_model=Star, to_field='idstar')
class Meta:
db_table = 'Name'
class Temperature(BaseModel):
idtemperature = PrimaryKeyField(db_column='idTemperature')
starid = ForeignKeyField(db_column='starid', rel_model=Star, to_field='idstar')
temperature = IntegerField()
class Meta:
db_table = 'Temperature'
if __name__ == '__main__':
print("Not to be run")