Пример #1
0
    def post(self, mid):
        is_shared = self.get_argument("is_shared", "off")
        is_shared = True if is_shared == "on" else False
        content = self.get_argument("content")
        source_mid = self.get_argument("source_mid")
        upper = Reply.getObjectByObjectId(mid)
        source = Topic.getObjectByObjectId(source_mid)
        if upper and source:
            reply = Reply.save_reply(source=source, content=content, owner=self.current_user, upper=upper)
            names_list = get_usernames(content)
            for username in names_list:
                send_mentions(sender=self.current_user, username=username, reply=reply)

            if is_shared:
                url = getattr(self.opts, "%s_update_url" %self.current_user.port)
                source_url = "%s/r/%s" %(self.prefix_url, reply.mid)
                status = "%s\n%s" %(content.replace("#%s" %self.current_user.port, ""), source_url)
                
                message_request(
                    url, 
                    self.current_user.port, 
                    self.current_user.access_token, 
                    status,
                    app_key=getattr(self.opts, "%s_key" %self.current_user.port),
                    openid=self.current_user.oauth_id,
                    client_ip=self.request.remote_ip)
      
            self.finishedMsg(status="success", info="post reply success", next=self.request.path)
        else:
            self.finishedMsg(status="error", info="topic not found")  
Пример #2
0
 def get(self, mid):
     topic = Topic.getObjectByObjectId(mid)
     if topic:
         topic.incr_views()
         self.render("page/topic.html", topic=topic)
     else:
         self.write_error(404)
Пример #3
0
 def post(self):
     page_start = int(self.get_argument("page_start"))
     page_step = int(self.get_argument("page_step"))
     topics = Topic.get_topics_to_json(page_start, page_step, is_enabled=True)
     collections =[coll.mid for coll in self.current_user.collections] if self.current_user else []
     logined = True if self.current_user else False
     self.finish(json.dumps({
         "status":"success", 
         "info":"request success", 
         "content":topics, 
         "collections":collections, 
         "logined":logined}))
Пример #4
0
    def post(self, mid):
        content = self.get_argument("content", None)
        is_shared = self.get_argument("is_shared", "off")
        is_shared = True if is_shared == "on" else False
        if content and mid:
            if 5 < len(content) < 280:
                topic = Topic.getObjectByObjectId(mid)
                if topic:
                    reply = Reply.save_reply(
                        source=topic,
                        content=content, 
                        owner=self.current_user,
                        topic=topic
                    )

                    # Update level if level=1
                    self.current_user.upgrade_level(xp=1)

                    # Send mention for @username format notification
                    names_list = get_usernames(content)
                    for username in names_list:
                        send_mentions(sender=self.current_user, username=username, reply=reply)
                    
                    if is_shared:
                        url = getattr(self.opts, "%s_update_url" %self.current_user.port)
                        source_url = "%s/t/%s" %(self.prefix_url, topic.mid)                        
                        status = "%s\n%s" %(content.replace("#%s" %self.current_user.port, ""), source_url)
                        attachments = self.dumpsJson(title="GitPub", 
                            href="%s/t/%s" %(self.prefix_url, topic.mid), description="From GitPub: ")
                        message_request(
                            url, 
                            self.current_user.port, 
                            self.current_user.access_token, 
                            status,
                            app_key=getattr(self.opts, "%s_key" %self.current_user.port),
                            openid=self.current_user.oauth_id,
                            client_ip=self.request.remote_ip,
                            attachments=attachments)
                                          
                    self.finishedMsg(status="success", info="post reply success", next=self.request.path)
                else:
                    self.finishedMsg(status="error", info="wrong topic shorted")
            else:
                self.finishedMsg(status="error", info="reply too long or too short")
        else:
            self.finishedMsg(status="error", info="incorrect arguments")
Пример #5
0
 def get(self):
     page_step = topics_per_page         
     topics = Topic.get_topics(0, page_step, is_enabled=True)
     self.render("index.html", topics=topics, page_step=page_step)
Пример #6
0
 def get(self, page_start=0):
     page_step  = self.get_argument("page_step", topics_per_page)
     page_step = int(page_step)
     page_start = int(page_start)
     topics = Topic.get_topics_all(page_start, page_step, is_enabled=True)
     self.render("topics.html", topics=topics, page_start=page_start, page_step=page_step)
Пример #7
0
    def post(self):
        content = self.get_argument("content").encode("utf-8")
        is_shared = self.get_argument("is_shared", "off")
        is_shared = True if is_shared == "on" else False

        topic = Topic.create(member=self.current_user, source_created=datetime.now(), 
            created=datetime.now(), content=content)
        self.current_user.upgrade_level(xp=1)

        #Send mention for @username format notification
        names_list = get_usernames(content)
        for username in names_list:
            send_mentions(sender=self.current_user, username=username, topic=topic)

        if is_shared:    
            identity = None
            request_url = self.oauth_update_url + "?" + urlencode({"access_token": self.current_user.access_token})
            header = HTTPHeaders({'Authorization': 'OAuth2 %s' % self.current_user.access_token})
            http_client = AsyncHTTPClient()

            if self.current_user.port == "weibo":                
                http_client.fetch(request_url, method="POST", body=urlencode({'status': content}), 
                    callback=(yield gen.Callback("resp")), headers=header)

                response = yield gen.Wait("resp")
                if response.code == 200:
                    body = json.loads(response.body)
                    identity = "%s#%s" %(body['id'], self.current_user.port)
                    topic.identity = identity
                    topic.save()                    
                    self.finishedMsg(status="success", info="Post topic success", next="/t/%s" %topic.mid)
                else:
                    self.finishedMsg(status="error", info="Post to weibo failed")

            elif self.current_user.port == "tencent":
                kwargs = {"access_token": self.current_user.access_token, 
                            "oauth_consumer_key": getattr(self.opts, "%s_key" %self.current_user.port),
                            "openid": self.current_user.oauth_id,
                            "client_ip": self.request.remote_ip,
                            "oauth_version": "2.a",
                            "scope":"all",
                            "format": "json",
                            "content": content}
                
                http_client.fetch(request_url, method="POST", body=urlencode(kwargs), 
                    callback=(yield gen.Callback("resp")), headers=header)

                response = yield gen.Wait("resp")
                if response.code == 200:
                    body = json.loads(response.body)
                    if body.get("errcode") == "ok":
                        identity = "%s#%s" %(body["data"]["id"], self.current_user.port)
                        topic.identity = identity
                        topic.save()
                        self.finishedMsg(status="success", info="Post topic success", next="/t/%s" %topic.mid)
                    else:
                        self.finishedMsg(status="error", info="Post to tencent failed")
                else:
                    self.finishedMsg(status="error", info="Post to tencent failed")
                

            elif self.current_user.port == "douban":
                header = HTTPHeaders({'Authorization': 'Bearer %s' % self.current_user.access_token})
                attachments = self.dumpsJson(title="GitPub", 
                    href="%s/t/%s" %(self.prefix_url, topic.mid), description="From GitPub: ")
                kwargs = {"access_token": self.current_user.access_token, 
                          "source": getattr(self.opts, "%s_key" %self.current_user.port),
                          "text": content,
                          "attachments": attachments}
                
                http_client.fetch(self.oauth_update_url, method="POST", body=urlencode(kwargs), 
                    callback=(yield gen.Callback("resp")), headers=header)

                response = yield gen.Wait("resp")
                if response.code == 200:
                    body = json.loads(response.body)
                    identity = "%s#%s" %(body["id"], self.current_user.port)
                    topic.identity = identity
                    topic.save()
                    self.finishedMsg(status="success", info="Post topic success", next="/t/%s" %topic.mid)
                else:
                    self.finishedMsg(status="error", info="Post to douban failed")
            else:
                raise HTTPError(500, "Port not supported")
        else:
            self.finishedMsg(status="success", info="Post topic success", next="/t/%s" %topic.mid)
Пример #8
0
def save_weibo_content(member, content):
    content = json.loads(content)
    for t in content['statuses']:
        identity = "%s#weibo" %t['id']
        existed_topic = Topic.objects(identity=identity).first()
        if not existed_topic:
            topic = Topic()
            topic.member = member
            topic.content = t['text'].lstrip()
            topic.identity = identity
            topic.created = datetime.now()
            topic.source_created = getWeiboTime(t['created_at'])
            topic.bmiddle_pic_url = t.get('bmiddle_pic', None)
            topic.thumbnail_pic_url = t.get('thumbnail_pic', None)
            topic.original_pic_url = t.get('original_pic', None)
            if t.get("retweeted_status"):
                topic.origin_content = t["retweeted_status"]
            topic.save()
Пример #9
0
 def post(self):
     mid = self.get_argument("mid")
     Topic.accept_topic_by_mid(mid, self.current_user)
     self.finishedMsg(status="success", info="accept topic")