-
Notifications
You must be signed in to change notification settings - Fork 0
/
tycho2.py
46 lines (41 loc) · 1.3 KB
/
tycho2.py
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
import pathlib
import re
import sqlite3
import typing
dirname = pathlib.Path(__file__).resolve().parent
class Database:
create_table_pattern = re.compile(r"CREATE TABLE (\w+) \((.+)\)")
tyc_pattern = re.compile(r"^TYC (\d{1,4})-(\d{1,5})-(\d)$")
tyc_identifier = 0
right_ascension = 1
declination = 2
right_ascension_dot = 3
declination_dot = 4
magnitude = 5
iau_name = 6
iau_designation = 7
iau_bayer_designation = 8
iau_system_position = 9
def __init__(self, path: pathlib.Path = dirname / "tycho2_m6.db"):
self.path = str(path)
def find(
self,
minimum_magnitude: float | None,
maximum_magnitude: float,
) -> list[tuple[typing.Any]]:
with sqlite3.connect(self.path) as connection:
cursor = connection.cursor()
cursor.execute(
" ".join(
(
"SELECT * FROM catalogue",
f"WHERE magnitude < {maximum_magnitude}",
*(
()
if minimum_magnitude is None
else (f"AND magnitude >= {minimum_magnitude}",)
),
)
)
)
return cursor.fetchall()