Exemplo n.º 1
0
def get_code():
    lst = []
    db = database.Db("dbs/profit.db")
    data = db.execu("select distinct code from profit")
    for code in data:
        lst.append(code[0])
    db.close()
    return lst
Exemplo n.º 2
0
def save_article(article_id):
    user_id = login_user()
    if user_id < 0:
        return {'status':False}
    else:
        db = database.Db(cfg.db_file)
        db.add_article_to_lib(user_id,article_id)
        return {'status':True}
Exemplo n.º 3
0
def get_profit(code):
    rst = {}
    db = database.Db("dbs/profit.db")
    data = db.execu("select * from profit where code='%s'" % (code))
    for ele in data:
        rst[ele[2]] = ele
    db.close()
    return rst
Exemplo n.º 4
0
def remove_article(article_id):
    user_id = login_user()
    if user_id < 0:
        #should never hit this
        return {'status':False}
    else:
        db = database.Db(cfg.db_file)
        db.remove_article_from_lib(user_id,article_id)
        return {'status':True}
Exemplo n.º 5
0
def search_articles():
    user_id = login_user()
    token = request.args['search_token']
    db = database.Db(cfg.db_file)
    ids  = srch.search_articles(token)
    rows = db.get_articles_by_id(user_id,ids) 
    data = fill_data(rows,user_id)
    return render_template('articles.html',data=data,
                user_id=user_id,msg=None,page_type="search")
Exemplo n.º 6
0
 def __init__(self):
     self.db = database.Db()
     self.db.connect()
     self.rss_feeds = {}
     self.rss_users = {}
     self._update_rss_feeds()
     self._update_rss_users()
     self.lookup_window = int(os.environ.get("RSS_LOOKUP_WINDOW",
                                             60))  # in sec
Exemplo n.º 7
0
def home():
    # landing page
    user_id = login_user()
    db = database.Db(cfg.db_file)
    num_articles = cfg.num_articles_home
    rows = db.get_articles_by_time(user_id,num_articles)
    data = fill_data(rows,user_id)
    return render_template('articles.html',data=data,
                user_id=user_id,msg=None,page_type="home")
Exemplo n.º 8
0
def login_user():
    # gets the user id if we've previously stored it
    # give an un-logged-in user a user_id of -1
    user_id = session.get('user_id')
    db = database.Db(cfg.db_file)
    if user_id:
        user = db.get_user(user_id)
        return user_id if user else -1
    else:
        return -1
Exemplo n.º 9
0
def library():
    user_id = login_user()
    msg = None
    data = None
    if user_id < 0:
        msg = "Please login or create an account to add articles to the library"
    else:
        db = database.Db(cfg.db_file)
        rows = db.get_user_articles(user_id)
        data = fill_data(rows,user_id)

    return render_template('articles.html',data=data,
                user_id=user_id,msg=msg,page_type="library")
Exemplo n.º 10
0
def recs():
    user_id = login_user()
    msg = None
    data = None
    if user_id < 0:
        msg = "Please login or create an accout to access recommendations"
    else:
        db = database.Db(cfg.db_file)
        rec  = recommend.Rec(db,cfg.xfile,cfg.num_recs)
        ids = rec.get_user_recs(user_id)
        if ids:
            rows = db.get_articles_by_id(user_id,ids)
            data = fill_data(rows,user_id)
        else:
            msg = "Please add articles to your library in order to access recommendations"
    
    return render_template('articles.html',data=data,
                user_id=user_id,msg=msg,page_type="recommended")
Exemplo n.º 11
0
    def __init__(self):
        parser = argparse.ArgumentParser(
            description='TheMoviePredictor by Baptiste Rogeon',
            usage='''app.py <context> <action> [<args>]

The context and action choices are:
    -  contexts : movies, people
    -  actions : find, list, insert, import
''')
        parser.add_argument(
            'context',
            choices=['movies', 'people'],
            help="Context in which we will apply the next action")
        parser.add_argument('action',
                            choices=['find', 'list', 'insert', 'import'],
                            help="Action to perform in the given context")
        args = parser.parse_args(sys.argv[1:3])
        self.action = args.action
        self.context = args.context
        self.db = database.Db()
        getattr(self, '_' + args.action)()
Exemplo n.º 12
0
def new_user():
    uname = request.form['username']
    pwd   = request.form['password']
    cpwd  = request.form['confirm_password']
    db = database.Db(cfg.db_file)
    if not uname: 
        flash('Enter a valid username')
        return redirect(url_for('signup'))
    elif not pwd:
        flash('Enter a valid password')
        return redirect(url_for('signup'))
    elif pwd != cpwd:
        flash('Passwords must match')
        return redirect(url_for('signup'))
    else:
        pw_hash = generate_password_hash(pwd)
        user_id = db.add_user(uname,pw_hash)
        if user_id < 0:
            flash('An account already exists with that username')
            return redirect(url_for('signup'))
        else:
            session['user_id'] = user_id
            return redirect(url_for('home'))
Exemplo n.º 13
0
def user_login():
    uname = request.form['username']
    pwd   = request.form['password']

    if not uname:
        flash('Enter username')
        return redirect(url_for('login'))
    if not pwd:
        flash('Enter password')
        return redicrect(url_for('login'))

    db = database.Db(cfg.db_file)
    pw_hash = generate_password_hash(pwd)
    user_info = db.get_user_info(uname)
    if not user_info:
        flash('Username does not exist')
        return redirect(url_for('login'))
    if not check_password_hash(user_info[0]['pw_hash'],pwd):
        flash('Invalid password')
        return redirect(url_for('login'))

    else:
        session['user_id'] = user_info[0]['user_id']
        return redirect(url_for('home'))
Exemplo n.º 14
0
def get_db():
    if not hasattr(g, 'db'):
        g.db = database.Db(app.config['DATABASE'])
    return g.db
Exemplo n.º 15
0
 def init_chat(self, all_items="bool"):
     db = database.Db(c.connect_db)
     res = db.get_chat_from_chat_id(self.target_id, all_items)
     return res
Exemplo n.º 16
0
 def delete_chat(self, chat_id):
     del_chat = [(chat_id)]
     db = database.Db(c.connect_db)
     db.delete_chat_on_db(del_chat)
Exemplo n.º 17
0
 def update_chat(self, chat_id, chat_name, alert_work="No", bot_work="No"):
     up_chat = [(chat_name, alert_work, bot_work, chat_id)]
     db = database.Db(c.connect_db)
     db.update_chat_on_db(up_chat)
Exemplo n.º 18
0
 def create_chat(self, message):
     new_chat = [(message.chat.id, message.chat.title, "No", "No")]
     db = database.Db(c.connect_db)
     db.create_chat_on_db(new_chat)