一个用于紧急救援的网站

Muxxs
Muxxs 2018年10月16日
  • 在其它设备中阅读本文章
#coding=utf-8
import uniout
CSRF_ENABLED = True
SECRET_KEY = 'zhiyouwozhidao'
import yagmail
import time,os,sys

#导入 Form 类
from flask_wtf import Form

from flask import Flask,render_template,request
app = Flask(__name__)
#app.config['SERVER_NAME'] = 'localhost' 此处不咋会调,求教绑定域名,对应端口对应指定域名
reload(sys)
sys.setdefaultencoding('utf8')
# !/usr/bin/env python3
# coding: utf-8
def email(title,content):
    #content="你好"
    print title,content
    import smtplib
    import smtplib
    import email.mime.multipart
    import email.mime.text
    from email.mime.text import MIMEText
    from email.header import Header
    sender = '747306970@qq.com'
    receiver = "747306970@qq.com"
    subject = str(title)
    smtpserver = 'smtp.qq.com'
    username = '747306970@qq.com'
    password = ''
    msg = MIMEText(content, 'plain', 'utf-8')  # 中文需参数‘utf-8',单字节字符不需要
    msg['From'] = sender
    msg['To'] = receiver
    print "get users"
    msg['Subject'] = Header(subject, 'utf-8')
    smtp = smtplib.SMTP_SSL('smtp.qq.com',465)
    print "connected"
    smtp.login(username,password)
    print "login finished"
    smtp.sendmail(sender, receiver, msg.as_string())
    print "send finished"
    smtp.quit()


@app.route('/')
def main():
    return render_template("emergency.html")
@app.route('/em/<text>',subdomain='jinji')
def em(text):
    ip = str(request.remote_addr)
    import time
    time = time.localtime(time.time())
    time = str(time.tm_mday) + "日" + str(time.tm_hour) + "时" + str(time.tm_min) + "分"
    text=str(text)
    text=text.replace("%20","").replace("%22",'"').replace("%7D","").replace(" ","")
    print type(text)
    content=text.replace(",","n").replace("{","").replace("}","")
    #content = text.split('addr":')[-1].replace(",","n")
    print content,ip
    try:
        email(title='紧急紧急紧急!!!!!',
             content=content+"nip:"+str(ip))
        return "OK"
    except:
        print "Failed"

@app.route('/call/<text>',subdomain='jinji')
def call(text):
    ip = str(request.remote_addr)
    import time
    time = time.localtime(time.time())
    time = str(time.tm_mday) + "日" + str(time.tm_hour) + "时" + str(time.tm_min) + "分"
    text = str(text)
    text = text.replace("%20", "").replace("%22", '"').replace("%7D", "").replace(" ", "")
    print type(text)
    content = text.replace(",", "n").replace("{", "").replace("}", "")
    # content = text.split('addr":')[-1].replace(",","n")
    email(title='一般紧急紧急紧急!!!!!',
          content=content + "nip:" + str(ip))
    return "OK"
if name == '__main__':
    app.run(host="0.0.0.0",port=3000)

 

 

HTML 部分:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>紧急页面</title> 
</head>
<body>
<center>
<p id="demo">点击按钮获取您当前坐标,并直接发送位置及IP和求救信息到指定邮箱、手机之中</p>
<button onClick="geolocation.getLocation(showPosition, showErr, options)" >点我</button></center>
<script type="text/javascript" src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"></script>
<script>
    var geolocation = new qq.maps.Geolocation("自己申请", "jinji");

    document.getElementById("pos-area").style.height = (document.body.clientHeight - 110) + 'px';

    var positionNum = 0;
    var options = {timeout: 8000};
    function showPosition(position) {

        positionNum ++;
        document.getElementById("demo").innerHTML += "序号:" + positionNum;
        var text=JSON.stringify(position, null, 4);
        window.location.href="http://jinji.tecplaces.com/em/"+text
        document.getElementById("demo").appendChild(document.createElement('pre')).innerHTML = text;
        document.getElementById("pos-area").scrollTop = document.getElementById("pos-area").scrollHeight;

    };

    function showErr() {
        positionNum ++;
        document.getElementById("demo").innerHTML += "序号:" + positionNum;
        document.getElementById("demo").appendChild(document.createElement('p')).innerHTML = "定位失败!";
        document.getElementById("pos-area").scrollTop = document.getElementById("pos-area").scrollHeight;
    };

    function showWatchPosition() {
        document.getElementById("demo").innerHTML += "开始监听位置!<br /><br />";
        geolocation.watchPosition(showPosition);
        document.getElementById("pos-area").scrollTop = document.getElementById("pos-area").scrollHeight;
    };

    function showClearWatch() {
        geolocation.clearWatch();
        document.getElementById("demo").innerHTML += "停止监听位置!<br /><br />";
        document.getElementById("pos-area").scrollTop = document.getElementById("pos-area").scrollHeight;
    };
</script>


</body>
</html>

 

这个可以用来发送位置和 IP

可娱乐,可关键时救命 - -