def get(self): try: t = time.strftime("%Y%m%d%H%M%S") date, tm = t[:8], t[8:] count = 0 posts = self.getPosts('http://zhihudaily.ahorn.me') for postdate in posts.keys(): for item in posts[postdate]: sql = "select * from zhihuribao where href = '%s'" % (item['href']) query = GqlQuery(sql) new = True for q in query: new = False if new: zhihu = models.zhihuribao(date=postdate, img=item['image'], href=item['href'], title=item['title'], insdate=date) zhihu.put() count += 1 if count >= 0: taskq = taskqueue.Queue('queue1') task = taskqueue.Task(url='/service/batchsendmail', params={'insdate': date, 'kind': 'zhihuribao'}) taskq.add(task) self.response.out.write("Succ") except Exception as e: logging.error(traceback.format_exc())
def GetJson(citycode): try: url = "http://m.weather.com.cn/data/%s.html" %(citycode,) data = urllib2.urlopen(url).read() return json.loads(data)['weatherinfo'] except: logging.error(format_exc()) return ''
def get(self): try: today = time.strftime('%Y%m%d') citycode = igaelib.GetGaeCfg('weather', 'city') mail.send_mail(sender='*****@*****.**', to='*****@*****.**', subject='%s' % '天气', body=weather(citycode)) except Exception as e: logging.error(format_exc()) raise e
def get(self, table): try: clazz = getattr(models, table) fields = getattr(clazz, '_field') rspdict = {} rspdict['fieldsdef'] = fields rspdict['table'] = table template = templateenv.get_template("app/datastore.get.html") self.response.out.write(template.render(rspdict)) except: logging.error(format_exc())
def weather(citycode): try: jsn = GetJson(citycode) if not jsn: return '' jsn = parseJson(jsn) info = "天气:%s\n温度:%s\n风力:%s\n紫外线:%s\n穿衣:%s" \ %(jsn['weather'], jsn['temp'], jsn['wind'], jsn['zwx'], jsn['cloth']) return info.decode('gbk').encode('utf8') except Exception as e : logging.error(format_exc()) return ""
def post(self): try: kind = self.request.get("kind") logging.debug(kind) if kind == "zhihuribao": insdate = self.request.get("insdate") result = GqlQuery("select * from zhihuribao where insdate = '%s'" % (insdate,)) ribao = u"\n\n".join([u"%s\n%s" % (r.title, r.href) for r in result]) subscribeusrs = GqlQuery("select * from subscription where rssid = 'zhihuribao'") for user in subscribeusrs: if user.email != "": logging.debug(user.email) mail.send_mail(sender='*****@*****.**', to=user.email, subject='知乎日报-%s' % insdate, body=ribao) else: logging.debug("something wrong") self.response.out.write("Ok") except: logging.error(format_exc())
def post(self, table): try: operateflag = self.request.get('operateflag') clazz = getattr(models, table) fields = getattr(clazz, '_field') if operateflag == 'I': d = dict([(field, self.request.get(field)) for field in fields]) q = clazz.all() for key in d.keys(): q = q.filter('%s =' % key, d[key]) e = None for i in q: e = i if not e: e = apply(clazz, [], d) e.put() else: for key in d.keys(): setattr(e, key, d[key]) e.put() except Exception as e: logging.error(format_exc()) finally: self.redirect("/datastore/%s" % table)
def post(self): try: return self.response.set_status(301) except: logging.error(traceback.format_exc())