Beispiel #1
0
def signup():
    if request.method == 'POST':
        data = {}
        data['email'] = request.form.get('email', '').strip()
        with kvdbwrap.KVDB() as kv:
            if kv.get("user#%s" % data['email']):
                ret = {'code': '-1', 'msg': '此邮箱已经被注册'}
                return json.dumps(ret)
        with kvdbwrap.KVDB() as kv:
            if kv.get("verify#%s" % data['email']):
                ret = {'code': '-1', 'msg': '此邮箱正在激活中!'}
                return json.dumps(ret)

        data['nick'] = request.form.get('nick', '').strip()
        data['qq'] = request.form.get('qq', '').strip()
        data['password'] = request.form.get('password', '')
        cid = hashlib.md5(os.urandom(32)).hexdigest()
        url = 'http://3gqq67.sinaapp.com/email_verify?cid=%s&email=%s' % (
            urllib.quote(cid), urllib.quote(data['email']))
        with kvdbwrap.KVDB() as kv:
            data['cid'] = cid
            data['init_time'] = int(time.time())
            kv.add('verify#%s' % data['email'], json.dumps(data))
        content = '''
      请在浏览器中打开此链接完成注册:
      <a href="%s">%s</a>
    ''' % (url, url)
        mail.send_email(content=content, to_email=data.get('email'))
        ret = {
            'code': '0',
            'msg': '注册成功!请前往你的邮件箱激活账号'
        }
        return json.dumps(ret)
    return render_template('signup.html')
Beispiel #2
0
 def setex(self, key, val, expire):
     with kvdbwrap.KVDB() as kv:
         ret = {}
         ret['val'] = val
         ret['init_time'] = int(time.time())
         ret['expire'] = str(expire)
         kv.add(key, json.dumps(ret))
Beispiel #3
0
def kvdb_del():
    #kv = sae.kvdb.KVClient()
    with kvdbwrap.KVDB() as kv:
        key = request.form.get('key') or request.args.get('key', '')
        ret = str(kv.delete(key))
        key = "%s#" % key
    return redirect("/kvdbmanage/%s" % key.split('#')[0])
Beispiel #4
0
def kvdbmanage(key=None):
    if not key:
        return render_template("database.html")
    else:
        if key == "all": key = ''
        with kvdbwrap.KVDB() as kv:
            key_values = kv.get_by_prefix(key)
        return render_template("kvdbmanage.html", values=key_values, name=key)
Beispiel #5
0
def dianzan_qq():
    data = {}
    if 'qq' in session:
        with kvdbwrap.KVDB() as kv:
            try:
                data = json.loads(kv.get('qq#%s' % session['qq']))
            except:
                pass
    return render_template('dianzan_qq.html', data=data)
Beispiel #6
0
def kvdbmanage_row(key=None):
    if not key:
        return 'n/a'
    else:
        if key == "all": key = ''
        with kvdbwrap.KVDB() as kv:
            key_values = kv.get_by_prefix(key)
            key_values = list(key_values)
        return json.dumps(key_values)
Beispiel #7
0
def email_verify():
    cid = request.args.get('cid')
    email = request.args.get('email')
    ret = {}
    with kvdbwrap.KVDB() as kv:
        try:
            ret = json.loads(kv.get('verify#%s' % email))
        except:
            pass
    if ret.get('cid') == cid:
        ret.pop('cid')
        ret.pop('init_time')
        with kvdbwrap.KVDB() as kv:
            kv.add('user#%s' % email, json.dumps(ret))
        with kvdbwrap.KVDB() as kv:
            kv.delete('verify#%s' % email)
        return redirect(url_for('login'))
    else:
        return '激活失败!'
Beispiel #8
0
def kvdb_set():
    with kvdbwrap.KVDB() as kv:
        key = request.form.get('key') or request.args.get('key')
        value = request.form.get('value') or request.args.get('value')
        try:
            kv.set(key, value)
        except Exception as e:
            return "error"
            print e
    return 'kvdb_set'
Beispiel #9
0
def kvdb_add():
    with kvdbwrap.KVDB() as kv:
        key = request.form['key']
        value = request.form['value']
        try:
            kv.add(key, value)
        except Exception as e:
            return "error"
            print e
    return 'kvdb_add'
Beispiel #10
0
def login():
    if request.method == 'POST':
        email = request.form.get('email')
        password = request.form.get('password')
        with kvdbwrap.KVDB() as kv:
            ret = json.loads(kv.get('user#admin'))
            if email.split('@')[0] == 'admin' and password == ret.get(
                    'password'):
                session.permanent = True  # make the session permanent after closing the  brower
                session['user'] = '******'

        try:
            with kvdbwrap.KVDB() as kv:
                ret = json.loads(kv.get('user#%s' % email))
                if password == ret.get('password'):
                    session['user'] = ret.get('nick')
        except:
            pass

        if request.args.get('next'):
            return redirect(request.args.get('next'))
    return render_template('login.html')
Beispiel #11
0
def kvdb_trash():
    with kvdbwrap.KVDB() as kv:
        key = request.form.get('key') or request.args.get('key', '')
        value = kv.get(key)
        try:
            ret = str(kv.delete(key))
            kv.set("delete#" + key, value)
        except Exception as e:
            return "error:" + ret
            print e
    if request.referrer:
        return redirect(request.referrer)
    return redirect("/kvdbmanage/%s" % key.split('#')[0])
Beispiel #12
0
 def get(self, key):
     try:
         with kvdbwrap.KVDB() as kv:
             ret = json.loads(kv.get(key))
             if int(time.time()) - int(ret.get('init_time')) > int(
                     ret.get('expire')):
                 return self.delete(key)
             return ret.get('val')
     except TypeError:
         pass
     except Exception as e:
         print e
         import traceback, sys
         traceback.print_exc(file=sys.stdout)
         return None
Beispiel #13
0
def kvdb_update():
    try:
        key = request.form.get('key') or request.args.get('key')
        item = request.form.get('value') or request.args.get('value')
        item = json.loads(item)
        #val = request.form.get('val') or request.args.get('val')
        with kvdbwrap.KVDB() as kv:
            items = kv.get(key)
            if items:
                items = json.loads(items)
                items.update(item)
                #if items.has_key(item.encode('utf-8')) or items.has_key(item.decode('utf-8')):
                #  items[item.encode('utf-8')] = val
                #  kv.set(key, json.dumps(items))
                kv.set(key, json.dumps(items))
                return 'success'
            return "no such items:" + key
    except Exception as e:
        return json.dumps({'ret': str(e)})
Beispiel #14
0
    def dianzan(self, cnt = 5, op = '1', url_from_db = None):
        '''
        下面这中方法返回的地址是转义了的。。
        '''
        #patter = r'''<a href="([^>]*?)">赞'''
        #content = self.session.get(self.url).content
        #urls = re.findall(patter, content)

        try:
          if self.verify:
              return self.verify
        except:
          pass

        if not url_from_db:feed_url = self.url
        else: feed_url = url_from_db
        #url = self._parse(feed_url, '/wml/card/@ontimer') #不知道为什么换了一个qq号的时候这里会多加一个跳转
        #if url:
        #    feed_url = url[0].content

        #self.url = feed_url

        pos = [ _.strip() for _ in self.pos.split('#') ]
        neg = [ _.strip() for _ in self.neg.split('#') ]
        print pos, neg
        is_filter = self.pos or self.neg
        try:
          cnt = int(self.cnt)
        except Exception as e:
          print str(e)
          import traceback, sys
          traceback.print_exc(file=sys.stdout)

        zan_success = False

        for i in xrange(cnt):
            print "feed_url:" + feed_url
            content = self.session.get(feed_url).content

            if is_filter:
              for zan_url, zan_content, zan_user in self.get_zan_datail(content):
                print zan_content
                if any( [ (_ and _ in zan_content.decode('utf-8')) for _ in pos] ) and not any( [ (_ and _ in zan_content.decode('utf-8')) for _ in neg ] ):
                #if zan_content.decode('utf-8') in pos and zan_content not in neg:
                  print zan_content, pos, neg
                  self.session.get(zan_url)
                  print '赞成功'
                  zan_success = True

            urls = self._parse(None, '//*/@href', content = content)
            #import json
            #return json.dumps( self.get_friend() )


            if not is_filter:
              for url in urls:
                if url.content.find('like_action') != -1 and url.content[-1] == op:
                    if self.repeat_set.issuperset({url.content}):
                        continue
                    ret = self.session.get(url.content).content
                    if ret.find('成功') != -1:
                        print '赞成功'
                        zan_success = True
                    self.repeat_set.add(url.content)

            urls = self._parse(None, '//*[text()="更多好友动态>>" or text()="下页"]/@href', content = content)
            for url in urls:
                #if url.content.find('feeds_friends') != -1 or url.content.find('dayval=1') != -1:
                feed_url = url.content

        if self.remember == 'on':
          session.permanent = True  # make the session permanent after closing brower
          session['qq'] = self.qq
        #  记住登陆信息
        if zan_success:
          with kvdbwrap.KVDB() as kv:
            val = {
                'qq': self.qq,
                'url': self.url,
                'cnt': self.cnt,
                'feq': self.feq,
                'inc': self.inc,
                'frr': self.frr,
                'pos': self.pos,
                'neg': self.neg,
                }
            key = 'qq#%s' % self.qq
            from pprint import pprint as printf
            printf(val)
            kv.add(key, json.dumps(val))
        return 'success'
Beispiel #15
0
 def delete(self, key):
     with kvdbwrap.KVDB() as kv:
         kv.delete(key)
     return None