def get (self, symbol): self.response.headers['Content-Type'] = 'text/plain' d_from = utils.parseIsoDate (self.request.get ("from")) d_to = utils.parseIsoDate (self.request.get ("to")) mc_key = "cot_%s_from_%s_to_%s" % (symbol, self.request.get ("from"), self.request.get ("to")) res = memcache.get (mc_key); if res is not None: self.response.out.write (res) else: cond = "" if d_from and d_to: q = db.GqlQuery ("select * from COT_Record where symbol = :1 and date >= :2 and date <= :3 order by date asc", symbol, d_from, d_to) elif d_from: q = db.GqlQuery ("select * from COT_Record where symbol = :1 and date >= :2 order by date asc", symbol, d_from) elif d_to: q = db.GqlQuery ("select * from COT_Record where symbol = :1 and date <= :2 order by date asc", symbol, d_to) else: q = db.GqlQuery ("select * from COT_Record where symbol = :1 order by date asc", symbol) res = 'Date,OpenInterest,PositionNonCommercialLong,PositionNonCommercialShort,PositionNonCommercialSpread,PositionCommercialLong,PositionCommercialShort,PositionNonRepresentativeLong,PositionNonRepresentativeShort,CountNonCommercialLong,CountNonCommercialShort,CountNonCommercialSpread,CountCommercialLong,CountCommercialShort\n' for rec in q: res += '%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n' % (rec.date.isoformat (), rec.oi, rec.pos_non_comm_long, rec.pos_non_comm_short, rec.pos_non_comm_spread, rec.pos_comm_long, rec.pos_comm_short, rec.pos_non_rep_long, rec.pos_non_rep_short, rec.count_non_comm_long, rec.count_non_comm_short, rec.count_non_comm_spread, rec.count_comm_long, rec.count_comm_short) self.response.out.write (res) memcache.add (mc_key, res, 60*60)
def get(self): d_from = utils.parseIsoDate(self.request.get("from")) if d_from == None: d_from = datetime.date.today() d_to = utils.parseIsoDate(self.request.get("to")) if d_to == None: d_to = d_from + datetime.timedelta(days=7) q = db.GqlQuery( "select * from News_Record_v2 where when > :1 and when < :2 order by when", d_from, d_to) if self.request.get("csv"): self.response.headers[ 'Content-Type'] = 'text/plain; charset=cp1251' self.response.out.write( "timestamp,importance,title,curr,prev,fore\n") for ev in q: self.response.out.write( ("%d,%s,%s,%s,%s,%s\n" % (time.mktime(ev.when.timetuple()), ev.importance, norm_str(ev.title), norm_str(ev.curr), norm_str( ev.pred), norm_str(ev.fore)))) else: res = [] index = 1 for ev in q: ev.index = index ev.imp = news.val2imp(ev.importance) ev.date = ev.when.date().isoformat() ev.time = ev.when.time().isoformat() ev.title = norm_str(ev.title, 1) ev.pred = norm_str(ev.pred, 1) ev.fore = norm_str(ev.fore, 1) ev.curr = norm_str(ev.curr, 1) index = index + 1 res.append(ev) path = os.path.join(os.path.dirname(__file__), "tmpl/news-list.html") ub_day = (d_from - datetime.timedelta(days=7)).isoformat() lb_day = (d_from - datetime.timedelta(days=1)).isoformat() back_url = "/news?from=%s&to=%s" % (ub_day, lb_day) ub_day = (d_to + datetime.timedelta(days=1)).isoformat() lb_day = (d_to + datetime.timedelta(days=7)).isoformat() forward_url = "/news?from=%s&to=%s" % (ub_day, lb_day) self.response.out.write( template.render(path, { "news": res, "back": back_url, "forward": forward_url }))
def get (self): d_from = utils.parseIsoDate (self.request.get ("from")) if d_from == None: d_from = datetime.date.today () d_to = utils.parseIsoDate (self.request.get ("to")) if d_to == None: d_to = d_from + datetime.timedelta (days = 7) q = db.GqlQuery ("select * from News_Record_v2 where when > :1 and when < :2 order by when", d_from, d_to) if self.request.get ("csv"): self.response.headers['Content-Type'] = 'text/plain; charset=cp1251' self.response.out.write ("timestamp,importance,title,curr,prev,fore\n") for ev in q: self.response.out.write (("%d,%s,%s,%s,%s,%s\n" % (time.mktime (ev.when.timetuple ()), ev.importance, norm_str (ev.title), norm_str (ev.curr), norm_str (ev.pred), norm_str (ev.fore)))) else: res = [] index = 1 for ev in q: ev.index = index ev.imp = news.val2imp (ev.importance) ev.date = ev.when.date ().isoformat () ev.time = ev.when.time ().isoformat () ev.title = norm_str (ev.title, 1) ev.pred = norm_str (ev.pred, 1) ev.fore = norm_str (ev.fore, 1) ev.curr = norm_str (ev.curr, 1) index = index + 1 res.append (ev) path = os.path.join (os.path.dirname (__file__), "tmpl/news-list.html") ub_day = (d_from - datetime.timedelta (days = 7)).isoformat () lb_day = (d_from - datetime.timedelta (days = 1)).isoformat () back_url = "/news?from=%s&to=%s" % (ub_day, lb_day) ub_day = (d_to + datetime.timedelta (days = 1)).isoformat () lb_day = (d_to + datetime.timedelta (days = 7)).isoformat () forward_url = "/news?from=%s&to=%s" % (ub_day, lb_day) self.response.out.write (template.render (path, { "news" : res, "back" : back_url, "forward" : forward_url}))
def get(self, symbol): self.response.headers['Content-Type'] = 'text/plain' d_from = utils.parseIsoDate(self.request.get("from")) d_to = utils.parseIsoDate(self.request.get("to")) mc_key = "cot_%s_from_%s_to_%s" % (symbol, self.request.get("from"), self.request.get("to")) res = memcache.get(mc_key) if res is not None: self.response.out.write(res) else: cond = "" if d_from and d_to: q = db.GqlQuery( "select * from COT_Record where symbol = :1 and date >= :2 and date <= :3 order by date asc", symbol, d_from, d_to) elif d_from: q = db.GqlQuery( "select * from COT_Record where symbol = :1 and date >= :2 order by date asc", symbol, d_from) elif d_to: q = db.GqlQuery( "select * from COT_Record where symbol = :1 and date <= :2 order by date asc", symbol, d_to) else: q = db.GqlQuery( "select * from COT_Record where symbol = :1 order by date asc", symbol) res = 'Date,OpenInterest,PositionNonCommercialLong,PositionNonCommercialShort,PositionNonCommercialSpread,PositionCommercialLong,PositionCommercialShort,PositionNonRepresentativeLong,PositionNonRepresentativeShort,CountNonCommercialLong,CountNonCommercialShort,CountNonCommercialSpread,CountCommercialLong,CountCommercialShort\n' for rec in q: res += '%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n' % ( rec.date.isoformat(), rec.oi, rec.pos_non_comm_long, rec.pos_non_comm_short, rec.pos_non_comm_spread, rec.pos_comm_long, rec.pos_comm_short, rec.pos_non_rep_long, rec.pos_non_rep_short, rec.count_non_comm_long, rec.count_non_comm_short, rec.count_non_comm_spread, rec.count_comm_long, rec.count_comm_short) self.response.out.write(res) memcache.add(mc_key, res, 60 * 60)