Flask

基于Dijkstra算法的武汉地铁路径规划!(附下载)

馋奶兔 提交于 2020-12-22 10:25:23
来源:Datawhale 本文 约3300字 ,建议阅读 10 分钟 本文为你详解路径规划项目,附源码链接。 前言 最近爬取了武汉地铁线路的信息,通过调用高德地图的api 获得各个站点的进度和纬度信息,使用Dijkstra算法对路径进行规划。 公众号(DatapiTHU)后台回复 “20201218” 获取项目源码下载 一、数据爬取 首先是需要获得武汉各个地铁的地铁站信息,通过爬虫爬取武汉各个地铁站点的信息,并存储到xlsx文件中。 武汉地铁线路图,2021最新武汉地铁线路图,武汉地铁地图-武汉本地宝wh.bendibao.com 方法:requests、BeautifulSoup、pandas import requests from bs4 import BeautifulSoup import pandas as pd def spyder(): #获得武汉的地铁信息 url='http://wh.bendibao.com/ditie/linemap.shtml' user_agent='Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50' headers = {'User-Agent'

5个python爬虫教材,让小白也有爬虫可写,含视频教程!

时光总嘲笑我的痴心妄想 提交于 2020-12-22 07:26:23
认识爬虫   网络爬虫,如果互联网是一张蜘蛛网,网络爬虫既是一个在此网上爬行的蜘蛛,爬了多少路程即获取到多少数据。 python写爬虫的优势   其实以上功能很多语言和工具都能做,但是用python爬取的速度更快,代码最简单,总而言之就是高效!与其它的编程语言作比较,python爬去网站的文档的接口更清晰明了,python的各种包提供给开发者访问网页文档的API。请先静下心看案例介绍。再进入里面寻找视频教程   由认识爬虫可知,在互联网上爬去内容,必然会有访问浏览器这个过程。程序员爬取网站内容必须模拟浏览器的行为,各个网站都有反爬措施,对于那些有问题的爬虫,很容易被封禁。Python丰富又优秀的库就起到非常重要的作用了,第三方库可以快速帮助开发者实现模拟user agent的行为编造能适合该网页的请求。 为什么学习Python,要从爬虫入门     爬虫是最简单的,比起web开发、人工智能,爬虫不需要你有多大的基础知识和你积累的爬虫以外的知识储备。基本所有学习Python的程序员都是学完基础知识后,自己的第一个项目一定是爬虫。有趣而又简单,当然要选择它。    分享项目之前,我先分享一下我的学习群 五个零基础都可以学习的Python爬虫教程 ####一、利用Scrapy爬虫框架爬取天气数据 非常容易实操,特别简单!稍微有点Python语法基础就可以跟着敲代码了。 二

Flask中session实现原理

时光毁灭记忆、已成空白 提交于 2020-12-17 23:21:52
前言 flask_session是flask框架实现session功能的一个插件,用来替代flask自带的session实现机制,flask默认的session信息保存在cookie中,不够安全和灵活。 flask的session机制 session是用来干什么的呢?由于http协议是一个无状态的协议,也就是说同一个用户第一次请求和第二次请求是完全没有关系的,但是现在的网站基本上有登录使用的功能,这就要求必须实现有状态,而session机制实现的就是这个功能。 实现的原理: 用户第一次请求后,将产生的状态信息保存在session中,这时可以把session当做一个容器,它保存了正在使用的所有用户的状态信息;这段状态信息分配了一个唯一的标识符用来标识用户的身份,将其保存在响应对象的cookie中;当第二次请求时,解析cookie中的标识符,拿到标识符后去session找到对应的用户的信息。 简单使用 from flask import Flask,session app = Flask(__name__) @app.route('/test1/') def test () : session.setdefault( 'name' , 'xiaoming' ) return 'OK' if __name__ == '__main__' : app.run(host= '127.0.0

用 20 行 python 代码实现人脸识别!

谁说胖子不能爱 提交于 2020-12-15 08:15:01
点击上方“ Python编程与实战 ”,选择“置顶公众号” 第一时间获取 Python 技术干货! 阅读文本大概需要 11分钟。 今天给大家介绍一个世界上最简洁的人脸识别库 face_recognition,你可以使用 Python 和命令行工具进行提取、识别、操作人脸。 基于业内领先的 C++ 开源库 dlib 中的深度学习模型,用 Labeled Faces in the Wild 人脸数据集进行测试,有高达99.38%的准确率。 1.安装 最好是使用 Linux 或 Mac 环境来安装,Windows 下安装会有很多问题。在安装 face_recognition 之前你需要先安装以下几个库,注意顺序! 1.1 先安装 cmake 和 boost pip install cmake pip install boost 1.2 安装 dlib pip install dlib 此处安装可能要几分钟。如安装出错,建议使用 whl 文件来安装 下载地址:https://pypi.org/simple/dlib/ 1.3 安装 face_recognition face_recongnition 一般要配合 opencv 一起使用 pip install face_recognition pip install opencv-python 2. 人脸识别 比如这里总共有三张图片

Can we track currently active sessions in Python Flask

感情迁移 提交于 2020-12-15 07:01:33
问题 In my Flask Web-app, a new session is created whenever a new user logs in. At the server-end, is there a way to track the currently active sessions ? 回答1: If you are using Flask-Login for your user session management then is_authenticated property of Flask-login tells you if the user is logged in or not: if not current_user.is_authenticated: return current_app.login_manager.unauthorized() If you want to protect your views you can use @login_required decorator. By default, when a user attempts

Flask pass string to jinja?

百般思念 提交于 2020-12-15 06:09:16
问题 Is it possible to pass an f string? I think would this be using jinja? Sorry still learning... I am also experimenting with XML format.. But if I run this from flask import Flask, Response class MyResponse(Response): default_mimetype = 'application/xml' class MyFlask(Flask): response_class = MyResponse app = MyFlask(__name__) num = 55 name = Jon Smith string = f'{name} Employee ID {num}' @app.route('/') def get_data(): return '''<?xml version="1.0" encoding="UTF-8"?> <person> <name> {string}

Auto Refresh div with DataFrame every N seconds

China☆狼群 提交于 2020-12-15 05:19:30
问题 I have seen a lot of solutions for this around the net but can't find the easiest solution for this .... simple flask page that loads a df into the html table. All I want to do is reload just the df in the html table every N seconds and not the whole page. app.py from flask import Flask, render_template from app import app import pandas as pd import sqlalchemy as sa cn = sa.create_engine('<my connection string>') @app.route("/") def home(): sql = "select * from <myTable>" df = pd.read_sql(sql

Flask-Socketio not emitting from external RQ process

房东的猫 提交于 2020-12-13 18:51:03
问题 I'm running a flask server that connects to an iOS client with Flask-Socketio. The server has to process some complicated data, and since that takes a while to solve, I do it in a background job using Redis Queue. Communication works fine normally, but I need to emit to the client, and write to database once the job finishes, and I am trying to do that from the job function (if there is a way to let the app know when the job is finished, the app could handle all communication in one place).

Flask-Socketio not emitting from external RQ process

时间秒杀一切 提交于 2020-12-13 18:50:46
问题 I'm running a flask server that connects to an iOS client with Flask-Socketio. The server has to process some complicated data, and since that takes a while to solve, I do it in a background job using Redis Queue. Communication works fine normally, but I need to emit to the client, and write to database once the job finishes, and I am trying to do that from the job function (if there is a way to let the app know when the job is finished, the app could handle all communication in one place).

Flask-Socketio not emitting from external RQ process

给你一囗甜甜゛ 提交于 2020-12-13 18:50:29
问题 I'm running a flask server that connects to an iOS client with Flask-Socketio. The server has to process some complicated data, and since that takes a while to solve, I do it in a background job using Redis Queue. Communication works fine normally, but I need to emit to the client, and write to database once the job finishes, and I am trying to do that from the job function (if there is a way to let the app know when the job is finished, the app could handle all communication in one place).