コード例 #1
0
def receiveInput(request):
    if request.method == 'POST':
        try:
            this_request = Request(request.POST["bkinput"])
            this_request.perform()
            if request.POST["source"] == "app":
                return HttpResponse(json.dumps({"response": "OK"}),
                    content_type="application/json")
            else:
                return render(request, 'unfinished.html', {})
        except BadThing, message:
            if request.POST["source"] == "twitter":
                t = TwitterHelper()
                t.send_response(message)
                return HttpResponse("OK")
            elif request.POST["source"] == "app":
                error_message = "{0}".format(message)
                return HttpResponse(json.dumps({
                    "response": "error", "message": error_message}),
                    content_type="application/json")
            else:
                return render(request, 'home.html', {'error': message})
コード例 #2
0
    def _tweet(self):
        message = self._get_DOTD()

        if message is None:
            # エラーを出力
            logging.error(u'Cannot Get DOTD')
            self._send_error_mail(self._errorContents)
            return


        # すでにツイート済の場合、ログに残して、ツイートせずに終了
        if self._has_tweeted(message):
            logging.info(u'Already posted')
            return


        # tweetする
        twitter = TwitterHelper()
        twitter.tweet(message)


        # 重複ツイートを避けるため、datastoreにツイート内容を保存
        self._save_tweet_message(message)