Commits

li yudong committed 4e6b35c

sms and douban

Comments (0)

Files changed (8)

     def GET(self,item_id):
         user = get_user()
         channel = Channel.get(item_id)
-        channel_info = ChannelInfo.get(user_id = user.id, channel_id = channel.id)
+        channel_info = ChannelInfo.get(user_id = user and user.id or None, channel_id = channel.id)
         if channel:
             return render.channel_item(channel = channel,channel_info = channel_info)
         else:

apps/reactive/__init__.py

 __author__ = 'liyudong'
 from weather import Weather
 from sina import Sina
+from sms import Sms
+from douban import Douban
 
 
 REACTIVE_APP_MAP = {
     'gmail':'Gmail',
     'weather':'Weather',
     'sina':'Sina',
+    'douban':'Douban',
+    'sms':'Sms'
 }

apps/reactive/douban.py

+#!/usr/bin/env python
+#coding:utf-8
+__author__ = 'liyudong'
+#!/usr/bin/env python
+#coding:utf-8
+__author__ = 'liyudong'
+
+import init_env
+from configure import render
+from model.channel import Channel
+from library.auth import login_required, get_user
+from model.channel_info import ChannelInfo
+from library.oauth.weibo import APIClient
+from settings import DOMAIN_NAME
+import web
+import json
+
+
+
+class Douban:
+    @login_required
+    def GET(self):
+        user = get_user()
+        sina_channel = Channel.get(name='sina')
+        client = APIClient(app_key=sina_channel.key,app_secret=sina_channel.secret,redirect_uri='http://'+DOMAIN_NAME+'/reactive/sina')
+        user_data = web.input()
+        if not user_data.has_key('code'):
+            web.seeother(client.get_authorize_url())
+        else:
+            client = APIClient(app_key=sina_channel.key,app_secret=sina_channel.secret,redirect_uri='http://'+DOMAIN_NAME+'/reactive/sina')
+            code = user_data.get('code')
+            r = client.request_access_token(code)
+            access_token = r.access_token
+            expires_in = r.expires_in
+            channel_info = ChannelInfo(channel_id = sina_channel.id, user_id = user.id, info = access_token+':'+str(expires_in))
+            channel_info.save()
+            return render.sina(result = channel_info, channel = sina_channel)
+
+    @login_required
+    def POST(self):
+        pass

apps/reactive/sms.py

+#!/usr/bin/env python
+#coding:utf-8
+__author__ = 'liyudong'
+import init_env
+from configure import render
+from model.channel import Channel
+from library.auth import login_required, get_user
+from model.channel_info import ChannelInfo
+import web
+import urllib2, urllib
+from BeautifulSoup import BeautifulSoup
+
+
+class Sms:
+    @login_required
+    def GET(self):
+        sms_channel = Channel.get(name='sms')
+        real_user = get_user()
+        result = ChannelInfo.get(channel_id = sms_channel.id, user_id = real_user.id)
+        return render.sms(channel = sms_channel, result = result)
+
+    @login_required
+    def POST(self):
+        sms_channel = Channel.get(name='sms')
+        real_user = get_user()
+        result = ChannelInfo.get(channel_id = sms_channel.id, user_id = real_user.id)
+        data = web.input()
+        sms_number = data.get("sms_number")
+        if result:
+            result.info = sms_number
+            result.save()
+        else:
+            result = ChannelInfo(channel_id = sms_channel.id, user_id = real_user.id, info = sms_number)
+            result.save()
+        return render.weather(channel = sms_channel, result = result)

static/pic/channels/douban_off110.png

Added
New image

static/pic/channels/douban_on110.png

Added
New image

static/pic/channels/douban_on310.png

Added
New image

template/reactive/sms.html

+<%inherit file="base.html"/>
+<%def name="content_body()">
+<div class="main_content">
+    <div class="my_channel">
+        <a><img  src="${channel.pic_url(size = 310)}"/></a>
+    </div>
+    <div class="my_channel_desc">
+        <div class="my_channel_desc_title"></div>
+        <div class="my_channel_desc_content_outer">
+            <div class="my_channel_desc_content">
+            <pre>
+                输入您的手机号码(仅支持中国移动)
+            </pre>
+                <form method="post">
+                    <span>请输入手机号码</span>
+                    %if result:
+                    已激活手机号码,请重新输入以进行更改<br>
+                    <input type="text" name="sms_number" value="${result.info}">
+                    %else:
+                    未进行手机号码设置请输入以激活<br>
+                    <input type="text" name="sms_number" value="">
+                    %endif
+                    <br>
+                    <input class="button" type="submit">
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+</%def>