您的位置:首页 > 其它

贴码了 第一次弄了点有用的东西 可惜在墙外

2013-03-25 01:19 281 查看
这是第一次用gae做东西。可惜的是只能在 使用。

app.yaml

application: xdupes
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /.*
script: main.app

libraries:
- name: webapp2
version: "2.5.2"
index.html

<!DOCTYPE html>
<html>
<head>
<title>{{ titles }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
</head>
<body>
<div data-role="header" data-position="fixed">
<h1>{{ titles }}</h1>
<!-- <a href="#" data-icon="gear" class="ui-btn-right">推荐给好友</a> -->
</div>
{% if index %}
{% if records %}
<div data-role="collapsible-set" data-theme="c" data-content-theme="c" data-iconpos="right">
{% for msg in records %}
<div data-role="collapsible">
<h3>{{ msg.date }}        {{ msg.iphone }} </h3>
<p>{% if msg.content %} <textarea style="overflow-y:hide" disabled="disabled" data-mini="true">{{ msg.content }}</textarea>
{% else %} 该记录无信息内容 {% endif %}</p>
</div>
{% endfor %}
</div>
{% else %}
<div data-role="content">
<h1>暂时无记录</h1>
</div>
{% endif %}
{% endif %}
{% if query %}
<form action="/dowork" method="post">
<input type="hidden" name="who" id="who" value="query">
<input type="search" data-clear-btn="true" name="iphone"
id="iphone" placeholder="输入要查询的号码" value="">
<input type="submit" id="submit" value="搜索">
<div data-role="popup" id="popupBasic" data-theme="e"><p>请输入号码</p></div>
</form>
{% endif %}
{% if report %}
<form action="/dowork" method="post">
<input type="hidden" name="who" id="who" value="report">
<input type="tel" data-clear-btn="true" name="iphone"
id="iphone" placeholder="输入要记录的号码" value="">
<textarea data-mini="true"  name="report" id="report"
placeholder="输入记录的内容"></textarea>
<input type="submit" id="submit" value="记录">
<div  data-role="popup" id="popupBasic" data-theme="e"><p>请输入号码</p></div>
</form>
{% endif %}
{% if about %}
<div data-role="content">
<h1>防骗档案 1.0</h1>
<p>这是一个专门记录骗子号码信息的工具,共享这些信息,让更多的人可以远离骗子的伤害。<br/>当你收到那些骗子的电话或者信息时,一
定很想让其它人也知道这是骗子,不想其它人上当受骗。现在就可以
记录在这里。方便其它朋友可以查询到这条信息。谢谢你的支持。
<br/><h4>声明:此工具只负责记录信息,无法对信息的真实性进行判断,请谨慎对待。</h4></p></div>
{% endif %}
<div data-role="footer" data-position="fixed" >
<div data-role="navbar">
<ul>
<li><a href="/" {% if index %}class="ui-btn-active
ui-state-persist"{% endif %} data-icon="grid"
data-theme="a">最新</a></li>
<li><a href="/query" {% if query %} class="ui-btn-active ui-state-persist"{% endif %} data-icon="star" data-theme="a">搜索</a></li>
<li><a href="/report" {% if report %}class="ui-btn-active ui-state-persist"
{% endif %} data-icon="gear" data-theme="a">记录</a></li>
<li><a href="/about" {% if about %}class="ui-btn-active ui-state-persist"
{% endif %} data-icon="arrow-l" data-theme="a">关于</a></li>
</ul>
</div>
</div>
</body>
</html>


msg.html

<!DOCTYPE html>
<html>
<head>
<title>{{ titles }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
</head>
<body>

<div data-role="dialog" data-close-btn="none">

<div data-role="header" data-theme="d">
<h1>{{ titles }}</h1>

</div>

<div data-role="content">
{% ifequal error "" %}
<h3>号码:{{ iphone }}</h3>
{% ifequal who "report" %}
<p>已经记录成功,感谢你的支持.</p>
{% else %}

{% if record %}

<div data-role="collapsible-set" data-theme="c" data-content-theme="c" data-iconpos="right">
{% for msg in record %}
<div data-role="collapsible">
<h3>{{ msg.date }} </h3>
<p>{% if msg.content %}<textarea data-mini="true" disabled="disabled">{{ msg.content|escape }}</textarea>{% else %} 该记录无信息内容 {% endif %}</p>
</div>
{% endfor %}
</div>
{% else %}
<p>未查询到结果</p>
{% endif %}
{% endifequal %}</p>
{% else %}
<p>{{ error }}</p>
{% endifequal %}
<a href="" data-role="button"
data-rel="back" data-theme="a">返回</a>
</div>
</div>
</body>
</html>


main.py

#!/usr/bin/env python
# coding=utf-8
import cgi
import webapp2
import os
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import users
from google.appengine.ext.webapp import template
from google.appengine.ext import db
from datetime import datetime, timedelta

class Record(db.Model):
iphone = db.StringProperty()
content = db.StringProperty(multiline=True)
date = db.StringProperty()

class Report(webapp2.RequestHandler):
def get(self):
template_values = {'titles':"举报",'report':1,}
path = os.path.join(os.path.dirname(__file__),"index.html")
self.response.out.write(template.render(path,template_values))

class MainHandler(webapp2.RequestHandler):
def get(self):
path=os.path.join(os.path.dirname(__file__),"index.html")
records = Record.all().order('-date')
record = records.fetch(10)
if records.count(10) == 0:
record = None
template_values = {'titles' :"消息",'index':1,'records':record,}
self.response.clear()
self.response.out.write(template.render(path,template_values))

class About(webapp2.RequestHandler):
def get(self):
path=os.path.join(os.path.dirname(__file__),"index.html")
template_values = {'titles' :"关于",'about':1,}
self.response.out.write(template.render(path,template_values))

class Query(webapp2.RequestHandler):
def get(self):
path = os.path.join(os.path.dirname(__file__),"index.html")
template_values = {'titles':"搜索",'query':1,}
self.response.out.write(template.render(path,template_values))

class Dwork(webapp2.RequestHandler):
def post(self):
path = os.path.join(os.path.dirname(__file__),"msg.html")
who = self.request.get('who')
records = None
error = ""
if who == "report":
record = Record()
record.iphone = self.request.get('iphone')
record.content = self.request.get('report')
try:
tmp = float(record.iphone)
mydate = datetime.utcnow() + timedelta(hours=+8)#北京时间是+8个时区
record.date = mydate.strftime("%Y-%m-%d %H:%M:%S")
record.put()
except:
error = "记录号码不正确,请输入正确号码"
else:
record = None
try:
tmp = float(self.request.get('iphone'))
records = Record.all().order("date")
records.filter("iphone =",self.request.get('iphone'))
record = records.fetch(10)
except:
error = "查询号码不正确,请重新搜索"
template_values = {'titles':"信息",'who':self.request.get('who'),'error':error,'iphone':self.request.get('iphone'),'record':record,}

self.response.out.write(template.render(path,template_values))

app = webapp2.WSGIApplication([
('/main',MainHandler),
('/report',Report),
('/query',Query),
('/dowork',Dwork),
('/about',About),
('/',MainHandler)
])

def main():
run_wsgi_app(app)

FPATH = ""

if __name__ == "__main__":
main()


这就是全部的代码了。

地址需xx:http://xdupes.appspot.com

https://xdupes.appspot.com

有时候会出现js无法加载的问题。有时间把它更新成服务器上的js.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: