私はGAEを使用してプロジェクトを作成しており、ひどい問題があります。GAE(python)の静的ファイルをapp.yamlでアップロードするにはどうすればよいですか?
私はツイッターボットを作りたかったので、ツイートを投稿して最初のステップを開始しました。私は 'dailybasic.py'と同じフォルダに 'tweets.txt'を作成しました。
ここにコードの一部があります。
#app.yaml
application: mathgirlna
version: 1
runtime: python
api_version: 1
handlers:
# - url: /static
# static_dir: static
- url: /dailybasic
script: dailybasic/dailybasic.py
- url: /.*
script: main.py
main.py(それが動作する、エラーなし)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
import wsgiref.handlers
class MainPage(webapp.RequestHandler):
def get(self):
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, None))
application = webapp.WSGIApplication([('/', MainPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
dailybasic.py(5分ごとに実行)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp.util import run_wsgi_app
import tweepy
import wsgiref.handlers
import time
def tweetit(tweet):
if len(tweet)<140:
api.update_status(tweet)
else:
diaryentries.append(tweet)
consumer_key = '******************'
consumer_secret = '*******************************************'
access_token = '**************************************************'
access_token_secret = '****************************************'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
class dailybasic(webapp.RequestHandler):
def get(self):
now = time.localtime()
path = os.path.join(os.path.dirname(__file__), 'tweets.txt')
f_db = open(path, 'r')
db = f_db.readline()
while db != '':
todaynow = []
wday = now.tm_wday
if db[(wday+1)%7]=='1' and now.tm_hour * 60 + now.tm_min <= int(db[8:10]) * 60 + int(db[11:13]) and now.tm_hour * 60 + now.tm_min + 5 > int(db[8:10]) * 60 + int(db[11:13]) :
todaynow.append(db[14:])
if(len(todaynow) != 0):
import random
tweetit(todaynow[random.randrange(0,len(todaynow)-1)])
application = webapp.WSGIApplication([('/dailybasic', dailybasic)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
cron.yaml
cron:
- description: day process
url: /dailybasic
schedule: every 5 minutes from 06:00 to 01:30
timezone: Asia/Seoul
私はこの問題について尋ね、私が '##' 'app.yaml'の一部ですが、動作しませんでした(デプロイできましたが、GAEは「ハンドラが見つからないファイル:dailybasic.py」として警告しました)。
ここでファイルツリーです:
- ルート
- dailybasic
- dailybasic.py
tweets.txt main.py
- app.yamlをは、 cron.yaml、index.yaml
- index.htmlを
- dailybasic
私はすべてのスクリプトなしで、唯一のHTMLコードが含まれている 'index.htmlを' 維持したいです。
ファイルを配置してapp.yamlを書き込む方法を教えてください。 「tweets.txt」のアップロードまたは間違ったディレクトリにされていないため
*
(そして、下手な英語のため申し訳ありませんが)、
問題があり、()しないオープンな作品を追加しました。
私はまだ同じ問題を抱えていますが、それらを書くことは有益なことです。ありがとう。 –
よろしいですか?私は明確にする必要があります - 私は 'tweets.txt'をアップロードし、Pythonスクリプトを読むようにします。 –
@Sidus_smg:正確に何をしたときに、どんなエラーメッセージが表示されますか? –