- Google App Engine - 1.9.18
- Python-2.7
# -*- coding: utf-8 -*-
#!/usr/bin/env python2.7
import webapp2
import urllib2
import json
from google.appengine.api import memcache
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
r = urllib2.urlopen('http://mis.twse.com.tw/stock/api/getIndustry.jsp')
j = json.loads(r.read())
for n in range(0,len(j['tse'])):
memcache.add(key=j['tse'][n]['code'], value=j['tse'][n]['name'], namespace='tse')
for n in range(0,len(j['otc'])):
memcache.add(key=j['otc'][n]['code'], value=j['otc'][n]['name'], namespace='otc')
self.response.out.write(memcache.get(key='01', namespace='tse'))
self.response.out.write(memcache.get(key='01', namespace='otc'))