MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / profiler_collect_optional

Function profiler_collect_optional

Scripts/ButSystem.py:15109–15165  ·  view source on GitHub ↗

profiler_collect_optional. Internal helper function. This docstring was added automatically to improve maintainability. Args: form: Parameter. Returns: Varies.

(form)

Source from the content-addressed store, hash-verified

15107 acc = None
15108 sharing = 1 if bool(data.get("sharing")) else 0
15109 if not (-90.0 <= lat <= 90.0 and -180.0 <= lon <= 180.0):
15110 return jsonify({"ok": False, "error": "Invalid coordinates"}), 400
15111
15112 conn = db_connect()
15113 conn.execute("""
15114 INSERT INTO user_locations(username, lat, lon, accuracy, sharing, updated_at)
15115 VALUES(?,?,?,?,?,?)
15116 ON CONFLICT(username) DO UPDATE SET
15117 lat=excluded.lat, lon=excluded.lon, accuracy=excluded.accuracy,
15118 sharing=excluded.sharing, updated_at=excluded.updated_at
15119 """, (me, lat, lon, acc, sharing, now_z()))
15120 conn.commit()
15121 conn.close()
15122 return jsonify({"ok": True})
15123
15124@app.route("/api/location/stop", methods=["POST"])
15125@login_required
15126def api_location_stop():
15127 """api_location_stop.
15128
15129Route handler or application helper.
15130
15131This docstring was expanded to make future maintenance easier.
15132
15133Returns:
15134 Varies.
15135"""
15136 me = current_user()
15137 conn = db_connect()
15138 conn.execute("UPDATE user_locations SET sharing=0, updated_at=? WHERE username=?", (now_z(), me))
15139 conn.commit()
15140 conn.close()
15141 return jsonify({"ok": True})
15142
15143@app.route("/api/locations")
15144@login_required
15145def api_locations():
15146 """api_locations.
15147
15148Route handler or application helper.
15149
15150This docstring was expanded to make future maintenance easier.
15151
15152Returns:
15153 Varies.
15154"""
15155 conn = db_connect()
15156 rows = conn.execute("""
15157 SELECT l.username, l.lat, l.lon, l.accuracy, l.updated_at, p.nickname_enc
15158 FROM user_locations l
15159 LEFT JOIN profiles p ON p.username=l.username
15160 WHERE l.sharing=1 AND l.lat IS NOT NULL AND l.lon IS NOT NULL
15161 ORDER BY l.updated_at DESC
15162 LIMIT 200
15163 """).fetchall()
15164 items = []
15165 for r in rows:
15166 nick = r["username"]

Callers 2

profiler_createFunction · 0.70
profiler_updateFunction · 0.70

Calls 1

cleanFunction · 0.70

Tested by

no test coverage detected