Пример #1
0
def is_signup_data_valid():
    if request.form['username'] not in get_db().smembers("subrss/users"):
        if len(request.form['username']) in xrange(3, 30):
            if request.form['mail'] not in get_db().smembers("subrss/emails"):
                if len(request.form['password']) >= 8 and validate_email(request.form['mail']):
                    return True
    return False
Пример #2
0
def get_rss(name):
    try:
        db = store.get_db()
        rss = db.get('subrss/user/%s/rss' % name)
        if db.exists('subrss/user/%s/rss_lastcheck' % name):
            rss_lastcheck = dateparser.parse(db.get('subrss/user/%s/rss_lastcheck' % name))
        else:
            rss_lastcheck = None
        content = urllib2.urlopen(rss).read()
        p = minidom.parseString(content)
        rss_elements = []
        torrent_urls = []
        i = 0
        for elem in p.getElementsByTagName('rss')[0].getElementsByTagName('channel')[0].getElementsByTagName('item'):
            elem_time = dateparser.parse(elem.getElementsByTagName('pubDate')[0].firstChild.nodeValue)
            if rss_lastcheck != None and rss_lastcheck > elem_time:
                break
            rss_elem = {}
            rss_elem['title'] = elem.getElementsByTagName('title')[0].firstChild.nodeValue
            torrent_urls.append((str(i), elem.getElementsByTagName('enclosure')[0].attributes['url'].value))
            rss_elem['time'] = unicode(since(elem_time))
            rss_elem['sub_url'] = subs.get_sub_url(rss_elem['title'])
            rss_elements.append(rss_elem)
            i += 1
        torrents = run_parallel(torrent_urls)
        for i, torrent in torrents:
            rss_elements[int(i)]['filename'] = torrent
        return rss, rss_lastcheck, rss_elements
    except Exception, e:
        print str(e)
        return False, False, False
Пример #3
0
def logged_in():
    try:
        if session['username'] and session['username'] in get_db().smembers("subrss/users"):
            return True
    except:
        return False
    return False
Пример #4
0
def home():
    if user.logged_in():
        try:
            db = store.get_db()
            rss = db.exists('subrss/user/%s/rss' % session['username'])
            return render_template('home_logged.html',  rss = rss,
                                                        uname = session['username'],
                                                        logged_in = user.logged_in())
        except Exception, e:
            return redirect(url_for('home'))
Пример #5
0
def login():
    db = get_db()
    email = request.forms["email"]
    password = request.forms["password"]
    r = db.session.query(User).filter(User.email==email,User.password==password)
    if r.count()>0:
        print r[0]
        response.set_cookie("name", r[0].name, secret="123456")
        response.set_cookie("email",email,secret="123456")
        redirect("/xiongdihui")
    else:
        return dict(err="用户名或密码错误!")
Пример #6
0
def download_all():
    try:
        db = store.get_db()
        rss_items = json.loads(db.get('subrss/users/%s/json_cache' % session['username']))
        if rss_items:
            items = []
            for i in range(0, 10):
                item = rss_items[i]
                _item = {}
                _item['filename'] = item['filename']
                _item['content'] = subs.get_sub(item['filename'], urllib2.urlopen(item['sub_url']).read(), item['sub_url'], True if "720p" in item['title'] else False)
                items.append(_item)
            return subs.get_all_subs(items)
    except Exception, e:
        return '<script type="text/javascript">alert("Ha ocurrido un error mientras se descargaban los subtítulos.");</script>' % str(e)
Пример #7
0
def reg_action():
    db = get_db()
    email = request.forms["email"]
    name = request.forms["name"]
    w = db.session.query(User).filter(User.email==email)
    if w.count()>0:
        return dict(err="邮箱已被占用")
    p = re.compile("\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")
    email_style =  p.match(request.forms["email"])
    if email_style:
        if request.forms["password"] == request.forms["re_password"]: 
            insert_user(request.forms["email"], request.forms["name"], request.forms["password"])
            response.set_cookie("email",email,secret="123456")
            response.set_cookie("name",name,secret="123456")
            redirect("/xiongdihui") 
        else: 
            return dict(err="密码错误")
    else:
        return dict(err="email格式错误")
Пример #8
0
def settings():
    try:
        if not user.logged_in():
            return redirect(url_for('login'))
        _user = store.get_user(session['username'])
        db = store.get_db()
        errors = []
        feed_rss = db.get('subrss/user/%s/rss' % session['username']) if db.exists('subrss/user/%s/rss' % session['username']) else ""
        if request.method == 'GET':
            return render_template('settings_form.html',    success = False,
                                                            username = _user['username'],
                                                            email = _user['mail'],
                                                            feed_rss = feed_rss,
                                                            errors = errors,
                                                            logged_in = user.logged_in())
        else:
            if user.validate_email(request.form['mail']) and not request.form['mail'] in db.smembers('subrss/emails'):
                db.srem('subrss/mails', _user['mail'])
                db.sadd('subrss/mails', request.form['mail'])
                db.set('subrss/user/%s/mail' % session['username'], request.form['mail'])
            else:
                errors.append("El email introducido no es válido o ya está en uso.")
            if request.form['password']:
                if len(request.form['password']) >= 8 and _user['password'] == store.crypt_password(request.form['password_repeat']):
                    db.set('subrss/user/%s/password' % session['username'], store.crypt_password(request.form['password']))
                else:
                    errors.append("La clave introducida no es correcta.")
            if request.form['feed']:
                db.set('subrss/user/%s/rss' % session['username'], request.form['feed'])
            return render_template('settings_form.html',    success = True if not errors else False,
                                                            username = _user['username'],
                                                            email = _user['mail'],
                                                            feed_rss = feed_rss,
                                                            errors = errors,
                                                            logged_in = user.logged_in())
    except Exception, e:
        return redirect(url_for('home'))
Пример #9
0
def retrieve_subs():
    is_cache = False
    db = store.get_db()
    try:
        rss = db.exists('subrss/user/%s/rss' % session['username'])
        if rss:
            if db.exists('subrss/users/%s/json_cache_time' % session['username']):
                last_time = int(db.get('subrss/users/%s/json_cache_time' % session['username']))
                if last_time + 3600 >= _rss.to_unix_timestamp(datetime.now()):
                    rss_items = json.loads(db.get('subrss/users/%s/json_cache' % session['username']))
                    is_cache = True
                    rss_lastcheck = datetime.now()
                    rss_error = False
            if not is_cache:
                (rss_url, rss_lastcheck, rss_items) = _rss.get_rss(session['username'])
                rss_error = True if not rss_url and not rss_lastcheck and not rss_items else False
        else:
            (rss_url, rss_lastcheck, rss_items) = (None, False, [])
            rss_error = True
    except Exception, e:
        return str(e)
        rss_error = True
        rss_lastcheck = None
        rss_items = None
Пример #10
0
def set_rss():
    if not user.logged_in():
        return redirect(url_for('home'))
    name = session['username']
    db = store.get_db()
    db.set()
Пример #11
0
                    rss_lastcheck = datetime.now()
                    rss_error = False
            if not is_cache:
                (rss_url, rss_lastcheck, rss_items) = _rss.get_rss(session['username'])
                rss_error = True if not rss_url and not rss_lastcheck and not rss_items else False
        else:
            (rss_url, rss_lastcheck, rss_items) = (None, False, [])
            rss_error = True
    except Exception, e:
        return str(e)
        rss_error = True
        rss_lastcheck = None
        rss_items = None
    try:
        if rss_items and not is_cache:
            db = store.get_db()
            db.set('subrss/users/%s/json_cache' % session['username'], json.dumps(rss_items))
            db.set('subrss/users/%s/json_cache_time' % session['username'], _rss.to_unix_timestamp(datetime.now()))
    except:
        pass
    return render_template('subs_list.html',    rss_last = rss_lastcheck,
                                                rss_items = rss_items,
                                                rss_error = rss_error,
                                                logged_in = user.logged_in())
                                                
@app.route('/download_sub', methods=['POST'])
def download_single():
    try:
        srt_file = subs.get_sub(request.form['file'], urllib2.urlopen(request.form['sub']).read(), request.form['sub'], True if "720p" in request.form['title'] else False)
        return subs.download_sub(srt_file, request.form['file'])
    except:
Пример #12
0
def drop():
    store.get_db()[COLLECTION_NAME].drop()
Пример #13
0
def information():
    db = get_db()
    email = request.get_cookie("email",secret="123456")
    n = db.session.query(User).filter(User.email==email)
    return dict(email=email,n=n)
Пример #14
0
def get_fans():
    db = get_db()
    fans = db.session.query(User).filter() 
    f_content = db.session.query(Feed).filter()
    return dict(users=fans,f_content=f_content)   
Пример #15
0
def xiongdihui():
    db = get_db()
    email = request.get_cookie("email",secret="123456")
    name = request.get_cookie("name",secret="123456")
    feeds = db.session.query(Feed).filter(Feed.email==email)
    return dict(weibo_action=feeds, name=name)
Пример #16
0
def insert_weibo(email, content, f_time):
    db = get_db()
    db.create_tables()
    feed = Feed(email=email, content=content, f_time=f_time)
    db.session.add_then_commit(feed)