mirror of
https://github.com/silenty4ng/k5sat
synced 2025-01-15 15:02:12 +00:00
update support local time
This commit is contained in:
parent
748e7c4e90
commit
b2148f2df4
3 changed files with 18 additions and 13 deletions
11
app.py
11
app.py
|
@ -5,14 +5,15 @@ from flask_cors import cross_origin
|
||||||
import ephem
|
import ephem
|
||||||
import redis
|
import redis
|
||||||
import uuid
|
import uuid
|
||||||
|
import dateutil
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
r = redis.Redis(host='127.0.0.1', port=6379, db=0)
|
r = redis.Redis(host='127.0.0.1', port=6379, db=0)
|
||||||
|
|
||||||
|
|
||||||
def local2utc(local_dtm):
|
def local2utc(local_dtm, tz="Asia/Shanghai"):
|
||||||
# 本地时间转 UTC 时间( -8:00 )
|
# 本地时间转 UTC 时间( -8:00 )
|
||||||
return datetime.utcfromtimestamp(local_dtm.timestamp())
|
return datetime.utcfromtimestamp(local_dtm.replace(tzinfo=dateutil.tz.gettz(tz)).timestamp())
|
||||||
|
|
||||||
@app.route("/lol", methods=['POST'])
|
@app.route("/lol", methods=['POST'])
|
||||||
@cross_origin()
|
@cross_origin()
|
||||||
|
@ -36,11 +37,12 @@ def satpass():
|
||||||
lat = request.json.get('lat', 0)
|
lat = request.json.get('lat', 0)
|
||||||
lng = request.json.get('lng', 0)
|
lng = request.json.get('lng', 0)
|
||||||
alt = request.json.get('alt', 0)
|
alt = request.json.get('alt', 0)
|
||||||
|
tz = request.json.get('tz', "Asia/Shanghai")
|
||||||
|
|
||||||
target_satellite, find_flag = head.FIND_SATE(sat_line_1, sat_line_2, sat)
|
target_satellite, find_flag = head.FIND_SATE(sat_line_1, sat_line_2, sat)
|
||||||
pass_times, departure_times = head.CAL_PASS_TIME(target_satellite,
|
pass_times, departure_times = head.CAL_PASS_TIME(target_satellite,
|
||||||
float(lat), float(lng),
|
float(lat), float(lng),
|
||||||
float(alt))
|
float(alt), tz)
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'code': 200,
|
'code': 200,
|
||||||
|
@ -60,6 +62,7 @@ def doppler():
|
||||||
alt = request.json.get('alt', 0)
|
alt = request.json.get('alt', 0)
|
||||||
tx = request.json.get('tx', 0)
|
tx = request.json.get('tx', 0)
|
||||||
rx = request.json.get('rx', 0)
|
rx = request.json.get('rx', 0)
|
||||||
|
tz = request.json.get('tz', "Asia/Shanghai")
|
||||||
format = "%Y-%m-%d %H:%M:%S"
|
format = "%Y-%m-%d %H:%M:%S"
|
||||||
pass_time = datetime.strptime(request.json.get('pass_time', ''), format)
|
pass_time = datetime.strptime(request.json.get('pass_time', ''), format)
|
||||||
departure_time = datetime.strptime(request.json.get('departure_time', ''),
|
departure_time = datetime.strptime(request.json.get('departure_time', ''),
|
||||||
|
@ -70,7 +73,7 @@ def doppler():
|
||||||
while pass_time < departure_time + timedelta(seconds=1):
|
while pass_time < departure_time + timedelta(seconds=1):
|
||||||
AZ, EI, SHITF_UP, SHIFT_DOWN, DIS = head.CAL_DATA(
|
AZ, EI, SHITF_UP, SHIFT_DOWN, DIS = head.CAL_DATA(
|
||||||
satellite, sat_line_1, sat_line_2, float(lng), float(lat),
|
satellite, sat_line_1, sat_line_2, float(lng), float(lat),
|
||||||
float(alt), local2utc(pass_time),
|
float(alt), local2utc(pass_time, tz),
|
||||||
float(tx) * 1000000,
|
float(tx) * 1000000,
|
||||||
float(rx) * 1000000)
|
float(rx) * 1000000)
|
||||||
shift_array.append([SHITF_UP, SHIFT_DOWN])
|
shift_array.append([SHITF_UP, SHIFT_DOWN])
|
||||||
|
|
16
head.py
16
head.py
|
@ -26,7 +26,7 @@ def find_lines_after_string(filename, search_string):
|
||||||
line2 = lines[i+2].strip()
|
line2 = lines[i+2].strip()
|
||||||
break
|
break
|
||||||
return line1, line2
|
return line1, line2
|
||||||
def CAL_PASS_TIME(target_satellite, observer_lat, observer_lon, observer_elevation):
|
def CAL_PASS_TIME(target_satellite, observer_lat, observer_lon, observer_elevation, tz="Asia/Shanghai"):
|
||||||
topos = Topos(latitude_degrees=observer_lat, longitude_degrees=observer_lon,
|
topos = Topos(latitude_degrees=observer_lat, longitude_degrees=observer_lon,
|
||||||
elevation_m=observer_elevation)
|
elevation_m=observer_elevation)
|
||||||
# 获取当前时间并创建Skyfield的时间对象
|
# 获取当前时间并创建Skyfield的时间对象
|
||||||
|
@ -35,21 +35,21 @@ def CAL_PASS_TIME(target_satellite, observer_lat, observer_lon, observer_elevati
|
||||||
t0 = ts.utc(now)
|
t0 = ts.utc(now)
|
||||||
t1 = t0 + timedelta(days=2) # 查找2天内过境时间
|
t1 = t0 + timedelta(days=2) # 查找2天内过境时间
|
||||||
passes = target_satellite.find_events(topos, t0, t1)
|
passes = target_satellite.find_events(topos, t0, t1)
|
||||||
# 获取北京时区
|
# 获取当地时区
|
||||||
beijing_tz = pytz.timezone('Asia/Shanghai')
|
local_tz = pytz.timezone(tz)
|
||||||
|
|
||||||
pass_times = []
|
pass_times = []
|
||||||
departure_times = []
|
departure_times = []
|
||||||
if not passes[0]:
|
if not passes[0]:
|
||||||
return None, None
|
return None, None
|
||||||
# 打印下一次过境的北京时间和离境时间
|
# 打印下一次过境的当地时间和离境时间
|
||||||
for time, event in zip(passes[0], passes[1]):
|
for time, event in zip(passes[0], passes[1]):
|
||||||
if event == 0: # 0表示升,1表示降
|
if event == 0: # 0表示升,1表示降
|
||||||
# 将UTC时间转换为北京时间
|
# 将UTC时间转换为当地时间
|
||||||
beijing_time = time.utc_datetime().replace(tzinfo=pytz.utc).astimezone(beijing_tz)
|
local_time = time.utc_datetime().replace(tzinfo=pytz.utc).astimezone(local_tz)
|
||||||
pass_times.append(beijing_time.strftime('%Y-%m-%d %H:%M:%S'))
|
pass_times.append(local_time.strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
elif event == 2:
|
elif event == 2:
|
||||||
departure_time_utc = time.utc_datetime().replace(tzinfo=pytz.utc).astimezone(beijing_tz)
|
departure_time_utc = time.utc_datetime().replace(tzinfo=pytz.utc).astimezone(local_tz)
|
||||||
departure_times.append(departure_time_utc.strftime('%Y-%m-%d %H:%M:%S'))
|
departure_times.append(departure_time_utc.strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
|
|
||||||
return pass_times, departure_times
|
return pass_times, departure_times
|
||||||
|
|
2
req.txt
2
req.txt
|
@ -4,3 +4,5 @@ skyfield==1.47
|
||||||
Flask==3.0.2
|
Flask==3.0.2
|
||||||
Flask-Cors==4.0.0
|
Flask-Cors==4.0.0
|
||||||
redis==5.0.1
|
redis==5.0.1
|
||||||
|
py2wasm==2.6.2
|
||||||
|
python-dateutil==2.9.0.post0
|
Loading…
Reference in a new issue