Created
March 20, 2011 11:51
-
-
Save r-plus/878292 to your computer and use it in GitHub Desktop.
freeappnow.jpのアプリ名に変化があればメールを送信するGoogleAppEngine用スクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cron: | |
- description: check freeappnow site | |
url: / | |
schedule: every 5 minutes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import wsgiref.handlers | |
from google.appengine.ext import webapp | |
from google.appengine.ext import db | |
from google.appengine.api import mail | |
from google.appengine.api import urlfetch | |
from BeautifulSoup import BeautifulSoup | |
Config = { | |
'Sender' : 'XXXXXXXX@gmail.com', #sender mail address | |
'ToAddr' : 'XXXXXXXX@domain', #destination mail address | |
} | |
class Appdb(db.Model): | |
appname = db.StringProperty() | |
applimit = db.StringProperty() | |
class MainPage(webapp.RequestHandler): | |
def get(self): | |
self.response.headers['Content-Type'] = 'text/plain;charset=UTF-8' | |
#load and delete prev data | |
datas = Appdb.all().fetch(1,0) | |
if datas: | |
prevName = datas[0].appname | |
prevLimit = datas[0].applimit | |
datas[0].delete() | |
else: | |
prevName = "NULL" | |
prevLimit = "NULL" | |
url = 'http://freeappnow.jp/' | |
html = urlfetch.fetch(url).content | |
soup = BeautifulSoup(html) | |
for s in soup('p', {'class':'present_info_appName'}): | |
nowName = s.renderContents() | |
for l in soup('p', {'class':'present_info_limit'}): | |
for ls in soup('font', {'size':'36px'}): | |
nowLimit = ls.renderContents() | |
obj = Appdb(appname=nowName.decode('utf-8'),applimit=nowLimit.decode('utf-8')) | |
obj.put() | |
if prevName == nowName.decode('utf-8'): | |
self.response.out.write('AppName:'+nowName.decode('utf-8')) | |
self.response.out.write(""" | |
"""+'Limit:'+nowLimit.decode('utf-8')) | |
#send mail | |
if prevName != nowName.decode('utf-8'): | |
subject_text = '[FreeAppNow Notify] %s' % nowName.decode('utf-8') | |
body_text = 'App:%s Limit:%s' % (nowName.decode('utf-8'), nowLimit.decode('utf-8')) | |
mail.send_mail(sender = Config['Sender'], | |
to = Config['ToAddr'], | |
subject = subject_text, | |
body = body_text, | |
) | |
def main(): | |
application = webapp.WSGIApplication([('/', MainPage)], | |
debug=True) | |
wsgiref.handlers.CGIHandler().run(application) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment