-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
81 lines (72 loc) · 2.88 KB
/
app.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
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
import head
from datetime import datetime, timedelta
from flask import Flask, request, jsonify
from flask_cors import cross_origin
import ephem
import redis
import uuid
import dateutil
app = Flask(__name__)
r = redis.Redis(host='127.0.0.1', port=6379, db=0)
def local2utc(local_dtm, tz="Asia/Shanghai"):
# 本地时间转 UTC 时间( -8:00 )
return datetime.utcfromtimestamp(local_dtm.replace(tzinfo=dateutil.tz.gettz(tz)).timestamp())
@app.route("/lol", methods=['POST'])
@cross_origin()
def lol():
func = request.json.get('func', 0)
_uuid = request.json.get('uuid', str(uuid.uuid4()))
_cache = request.json.get('cache', '')
if func == 0:
r.set(_uuid, _cache, 600)
else:
if r.get(_uuid):
_cache = r.get(_uuid).decode("utf-8")
return jsonify({'code': 200, 'uuid': _uuid, 'cache': _cache})
@app.route("/pass", methods=['POST'])
@cross_origin()
def satpass():
sat = request.json.get('sat', '')
sat_line_1 = request.json.get('sat_line_1', '')
sat_line_2 = request.json.get('sat_line_2', '')
lat = request.json.get('lat', 0)
lng = request.json.get('lng', 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)
pass_times, departure_times = head.CAL_PASS_TIME(target_satellite,
float(lat), float(lng),
float(alt), tz)
return jsonify({
'code': 200,
'pass_times': pass_times,
'departure_times': departure_times
})
@app.route("/doppler", methods=['POST'])
@cross_origin()
def doppler():
sat = request.json.get('sat', '')
sat_line_1 = request.json.get('sat_line_1', '')
sat_line_2 = request.json.get('sat_line_2', '')
lat = request.json.get('lat', 0)
lng = request.json.get('lng', 0)
alt = request.json.get('alt', 0)
tx = request.json.get('tx', 0)
rx = request.json.get('rx', 0)
tz = request.json.get('tz', "Asia/Shanghai")
format = "%Y-%m-%d %H:%M:%S"
pass_time = datetime.strptime(request.json.get('pass_time', ''), format)
departure_time = datetime.strptime(request.json.get('departure_time', ''),
format)
satellite = ephem.readtle(sat, sat_line_1, sat_line_2)
# print(str(pass_time) + " " + str(local2utc(pass_time)))
shift_array = []
while pass_time < departure_time + timedelta(seconds=1):
AZ, EI, SHITF_UP, SHIFT_DOWN, DIS = head.CAL_DATA(
satellite, sat_line_1, sat_line_2, float(lng), float(lat),
float(alt), local2utc(pass_time, tz),
float(tx) * 1000000,
float(rx) * 1000000)
shift_array.append([SHITF_UP, SHIFT_DOWN])
pass_time = pass_time + timedelta(seconds=1)
return jsonify({'code': 200, 'shift_array': shift_array})