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
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}
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
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}
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")
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
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")
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
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")
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")
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)()
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'))
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'))
def get_db(): if not hasattr(g, 'db'): g.db = database.Db(app.config['DATABASE']) return g.db
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
def delete_chat(self, chat_id): del_chat = [(chat_id)] db = database.Db(c.connect_db) db.delete_chat_on_db(del_chat)
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)
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)