# Python期末项目 **Repository Path**: zhongli_07/python-final-project ## Basic Information - **Project Name**: Python期末项目 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-01-12 - **Last Updated**: 2021-01-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README **[出行小助手pythonanywhere](http://ally007.pythonanywhere.com/)** # Python 语言基础项目技术文档 ## 一、项目标题与简介 ### 出行小助手---致力为每位用户打造“我的出行生活圈”。 #### 项目意义 - 出行小助手,致力为每位用户打造“我的出行生活圈”,“懂”天气,“识”附近,“熟”路线,解决短距离需求。 - 不出远门时,在家里查天气、搜索附近,路径规划后再出门,解决你的短距离需求。 - 目前出行小助手调用高德开放平台API,主要包括天气查询、搜索POI、路径规划。 - 共同服务大众生活,关注生活圈,从这里开始。 #### 功能框架图  ## 二、问题表述 #### 主要功能 - 实现用户登录、注册功能 - 帮助用户充分了解天气情况,带好雨具或其他必需品出门 - 帮助用户查询附近景点、美食餐厅、酒店等场所 - 帮助用户路径规划,筛选出最合适的出行方案 #### 用户痛点、解决方案 | 序号 | 用户痛点 | 解决方案 | |---|---|---| | 1 | 用户没有充分了解天气情况就出门,出门逛街因太阳太猛/突下暴雨玩的不尽兴 | 使用高德天气查询API得出城市 | | 2 | 用户想在广州附近找冰雪乐园却不知道在哪 | 使用高德搜索POI搜索关键词可快速查看 | | 3 | 用户有时在导航时容易走错,对于方向感不好的来说太难了 | 在出门前提前查看路径规划 | #### 用户画像、使用场景  #### 价值主张画布  ## 三、解决方案表述 | 序号 | 用处 | 基本的Python基础知识点 | |---|---|---| | 1 | API功能的加入 | jupyter notebook的使用,阅读相关API文档,python基础语言嵌套字典的取值、列表元素的添加 | | 2 | HTML界面的美化 | bootstrap样式模板、相关CSS样式 | | 3 | 项目的部署 | pythonanywhere云端部署 | ## 四、编程功能的基本描述 1. 准备工作 调用模块 ``` from flask import Flask, render_template,request,escape import api from api import geocode ``` 2. 调用日志记录函数 ``` def log_request(req:'flask_request',res:str)->None: with open('./static/log/vsearch.log','a') as log: print(req.form,req.remote_addr,req.user_agent,res,file=log,sep='|') ``` 3. 进入网页的首页,数据返回index.html ``` @app.route('/') def main(): return render_template('./MainPage/index.html') ``` 4. 进入天气查询页面,填写城市提交 ``` @app.route('/weather') def weather(): return render_template('./WetherPage/index.html') ``` 5. 进入路径规划页面,填写起始点提交 ``` @app.route('/walking') def walking() -> 'html': return render_template('./MainPage/walking.html', the_title='智能步行导航') ``` 6.高德调用api数据准备 ``` import requests import json key = "7bdac67270c803349259a1845da5cdf6" ``` 7.高德调用地理编码 ``` def geocode(key, address, city=None, batch=None) -> str: url = "https://restapi.amap.com/v3/geocode/geo?parameters" params = { "key": key, "address": address, "city": city, "batch": batch } response = requests.get(url, params=params) results = response.json()['geocodes'][0]['location'] # 返回值 return results ``` 8. 调用路径规划-步行 ``` def walking(key, origin, destination, sig=None, output=None, callback=None): url = "https://restapi.amap.com/v3/direction/walking?parameters" params = {'key': key, 'origin': origin, 'destination': destination, 'sig': sig, 'output': output, 'callback': callback } r = requests.get(url, params=params) results = r.json() return results ``` 所有代码中涉及到的知识主要包括python和html两大部分,占比如下: | | PYTHON | HTML5 | |---|---|---| | 代码量 | 30% | 70% | | 实现项目的功能 | 80% | 20% | | 所占用的学习时间 | 70% | 30% | | 逻辑难度(理解难度) | 3星 | 2星 | | 操作难度 | 3星 | 2星 | 本项目总计10个页面。 ### 五、云端项目部署的基本描述 [首页](http://ally007.pythonanywhere.com/) 左右滑动可以出现三个界面噢!    [登录页](http://ally007.pythonanywhere.com/login)  [注册页](http://ally007.pythonanywhere.com/register)  [天气查询页](http://ally007.pythonanywhere.com/weather)  填写城市后点击查询,出现下面的查询结果页面  [路径规划页](http://ally007.pythonanywhere.com/walking)  填入起始点和终点,出现下面的查询结果页面  [日志系统页](http://ally007.pythonanywhere.com/viewlog)  ### 学习/实践心得总结 在学习Python Flask Web的过程中,说实话很奔溃,无数次失败,一直不成功,有时成功有时不成功,很搞我心态。最后还是因为朋友同学的鼓励和支持,多次开腾讯会议互相帮忙解决问题。果然合作的力量是伟大的,最后成功了。也感谢游鸽老师一个学期以来的认真教导,游鸽老师认真负责的态度我超爱。总的来说,编程思维教会了我合作、坚持不懈,就一定能成功。 ### 感谢 - 感谢相关API应用官网所提供的文档: - 感谢CSDN技术社区中的博客们以及相关官网所提供的技术和bug解决方案: 1. [高德路径规划API文档](https://developer.amap.com/api/webservice/guide/api/direction) 1. [高德搜索POI API文档](https://developer.amap.com/api/webservice/guide/api/search) 1. [高德天气查询 API文档](https://developer.amap.com/api/webservice/guide/api/weatherinfo) 1. [bootstrap模板](https://v3.bootcss.com/getting-started/) 1. [jquery框架模板](https://code.jquery.com/jquery-3.5.1.min.js) 1. [Python编码规范(PEP8)](https://blog.csdn.net/ratsniper/article/details/78954852) 1. [知乎上一些开源项目介绍](https://www.zhihu.com/question/40746923?sort=created) 1. [python开发实战项【flask小项目】天气预报](https://www.bilibili.com/video/BV1jJ41147gP?from=search&seid=1599403821353781618) 1. [Python和Flask搭建的博客、论坛等开源项目推荐](https://www.zhihu.com/question/40746923?sort=created) 1. [HTML表格(HTML 表格的使用,收藏这一篇就够了)](https://blog.csdn.net/weixin_47139649/article/details/109099704?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_v2~rank_aggregation-3-109099704.pc_agg_rank_aggregation&utm_term=html5%E8%AE%BE%E7%BD%AE%E8%A1%A8%E6%A0%BC%E8%83%8C%E6%99%AF%E8%89%B2&spm=1000.2123.3001.4430#522__217) 1. [div居中和div内容居中](https://blog.csdn.net/shenzixincaiji/article/details/82120936) 1. [HTML