Permalink
Browse files

Add anti-server cache Model.

  • Loading branch information...
toomore committed Dec 14, 2010
1 parent a7b320c commit acfd6eaaa2e6623063d826cfacbb8bee26f58418
Showing with 29 additions and 1 deletion.
  1. +4 −0 cron.yaml
  2. +1 −1 goristock.py
  3. +24 −0 main.py
View
@@ -7,6 +7,10 @@ cron:
url: /ad/cron_mail
schedule: every mon,tue,wed,thu,fri 14:45
timezone: Asia/Taipei
- description: stantisercache
url: /ad/stantisercache
schedule: every 2 hours synchronized
timezone: Asia/Taipei
- description: PreMemcache stock
url: /ad/stpremem
schedule: every 6 hours synchronized
View
@@ -169,7 +169,7 @@ def fetch_data(self, stock_no, nowdatetime, firsttime = 1):
# set memcache expire
now = datetime.today() + timedelta(hours = TIMEZONE)
if now >= datetime(now.year, now.month, now.day, 14, 30):
if now >= datetime(now.year, now.month, now.day, 14, 45):
addday = 1
else:
addday = 0
View
24 main.py
@@ -309,8 +309,30 @@ def get(self):
class premem(webapp.RequestHandler):
def post(self):
nowdatetime = datetime.today()
url = "http://www.twse.com.tw/ch/trading/exchange/STOCK_DAY/STOCK_DAY.php?myear=%(year)d&mmon=%(mon)02d&STK_NO=%(stock)s" % {'year': nowdatetime.year, 'mon': nowdatetime.month, 'stock': self.request.get('no')}
urllib2.urlopen(url)
goristock.goristock(self.request.get('no'))
############## anti-server cache Models ##############
class stantisercache(webapp.RequestHandler):
def get(self):
for i in twseno().allstock:
Task(
url='/ad/antisercah',
method='POST',
params={
'log': 'antisercah',
'no': i,
}
).add(queue_name='premem')
class antisercah(webapp.RequestHandler):
def post(self):
nowdatetime = datetime.today()
url = "http://www.twse.com.tw/ch/trading/exchange/STOCK_DAY/STOCK_DAY.php?myear=%(year)d&mmon=%(mon)02d&STK_NO=%(stock)s" % {'year': nowdatetime.year, 'mon': nowdatetime.month, 'stock': self.request.get('no')}
urllib2.urlopen(url)
############## Mails Models ##############
class cron_mail(webapp.RequestHandler):
def get(self):
@@ -406,6 +428,8 @@ def main():
('/ad/cron_mail_test', cron_mail_test),
('/ad/stpremem', stpremem),
('/ad/premem', premem),
('/ad/stantisercache', stantisercache),
('/ad/antisercah', antisercah),
('/ad/flu', flush),
('/ad/fluls', flush_lsdata),
('/.*', rewrite)

0 comments on commit acfd6ea

Please sign in to comment.