{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import time\n",
    "import random\n",
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "ip = \"http://139.159.182.121:8090\"\n",
    "# param = {\n",
    "#     \"username\": \"zhongwei\",\n",
    "#     \"password\": \"123456a\",\n",
    "#     \"client_id\": \"client\",\n",
    "#     \"grant_type\": \"password\",\n",
    "#     \"client_secret\": \"123456\",\n",
    "# }\n",
    "# data = requests.get(url=f\"{ip}/oauth/token\", params=param).json()\n",
    "# token = data[\"access_token\"]\n",
    "# header = {\n",
    "#     \"content-type\": \"application/json\",\n",
    "#     \"authorization\": f\"Bearer {token}\",\n",
    "# }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "bandNos = ['0985704955','0890497621','2631768263']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "int(datetime.datetime.now().timestamp()*1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2024-10-22 17:38:19'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1729553899000.0"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.datetime.strptime('2024-10-22 07:38:19', '%Y-%m-%d %H:%M:%S').timestamp()*1000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "requests.get(url=f\"{ip}/schoolBus/crad\",params={\"bandNo\": '0976835307',\"serialNo\":'865860043867069',\"time\":1729553899000}).text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "103, 30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "733 米\n",
      "587 米\n"
     ]
    }
   ],
   "source": [
    "from geopy.distance import geodesic\n",
    "# 定义两个地点的经纬度坐标\n",
    "location1 = (30.70125, 103.99548 )#起点\n",
    "location2 = (30.70423, 103.98864)#黄\n",
    "location3 = (30.70260, 103.99447)#泡\n",
    "# 计算地理距离\n",
    "distance = geodesic(location1, location2).m\n",
    "distance2 = geodesic(location2, location3).m\n",
    "# 输出地理距离\n",
    "print(f\"{int(distance)} 米\")\n",
    "print(f\"{int(distance2)} 米\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for index,pos in enumerate(positions):\n",
    "    x,y=pos\n",
    "    response = requests.get(url=f\"{ip}/schoolBus/gps\",params={\"serialNo\":'868626047777357',\"time\":int(datetime.datetime.now().timestamp()*1000),\"coodx\":x,\"coody\":y}).text\n",
    "    print(response)\n",
    "    time.sleep(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "while True:\n",
    "    data = requests.get(url=f\"{ip}/schoolBus/location\",params={\"serialNo\":'865860043833053'}).text\n",
    "    print(data)\n",
    "    time.sleep(30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "requests.get(url=f\"{ip}/schoolBus/crad\",params={\"bandNo\": bandNos[0],\"serialNo\":'868626047775245',\"time\":int(datetime.datetime.now().timestamp()*1000)}).text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "response = requests.get(url=f\"{ip}/schoolBus/gps\",params={\"serialNo\":'868626047775245',\"time\":int(datetime.datetime.now().timestamp()*1000),\"coodx\":10399440, \"coody\":3070043}).text\n",
    "print(response)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
