Example #1
0
def index():
    ''' Our root/index route and corresponding templates. Notice the new codes here. 
    We are searching and getting all the entries from the DB and displaying them.
    One more thing to notice is that we are typecasting the default pymongo return to
    list before we pass it to the template.'''
    try:
        if session['name'] != '':
            user_name = session['name']
    except:
        user_name = 'default'
        session['name'] = 'default'
    entries = get_entries()
    if entries == None:
        entries = []
        flash("Opps! Somwthing went wrong!")
    init_entries = list(entries)
    final_entries = []
    for entry in init_entries:
        if entry['user'] == user_name: ## If it is our current user's entry
            final_entries.append(entry) ## The the entry whatever the private settings is
        else:
            if 'is_private' in entry and entry['is_private'] == False: ## Not our current user? Check for privacy settings
                final_entries.append(entry)
                
    return render_template('index.html',
                           entries=final_entries,
                           home_page=True) ## No need to typecast it again as a list. it is already a list
Example #2
0
def index():
    ''' Our root/index route and corresponding templates. Notice the new codes here. 
    We are searching and getting all the entries from the DB and displaying them.
    One more thing to notice is that we are typecasting the default pymongo return to
    list before we pass it to the template.'''
    entries = get_entries()
    if entries == None:
        entries = []
        flash("Opps! Somwthing went wrong!")
    return render_template('index.html',
                           entries=list(entries))
Example #3
0
def stats():
    '''
    Render stats page
    '''
    rows = db.get_entries()
    entries = []
    for row in rows:
        entries.append({
            'id': row[0],
            'date': row[1],
            'eye': row[2],
            'rates': row[3:]
        })

    return render_template('stats.html', entries=entries)
Example #4
0
def csv():
    start = None
    count = None
    try:
        start = int(request.form['start'])
    except:
        start = 0
    try:
        count = int(request.form['count'])
    except:
        count = 25
    conn = db.create_connection(config.DBFile())
    response = db.get_entries(conn, start=start, count=count)
    conn.close()
    csv = 'Tag, Checkin, Checkout\n'
    for row in response:
        csv += row[0] + ", " + str(time.ctime(row[1])) + ", " + str(
            time.ctime(row[2])) + '\n'
    response = Response(csv)
    response.headers['Content-Type'] = 'text/csv'
    return response
Example #5
0
def list_checkedin():
    conn = db.create_connection(config.DBFile())
    visits = db.get_entries(conn, start=0, count=200, checkedin=True)
    conn.close()
    return render_template('list.html', visits=visits, checkedin=True)
Example #6
0
def list():
    conn = db.create_connection(config.DBFile())
    visits = db.get_entries(conn, start=0, count=15)
    conn.close()
    return render_template('list.html', visits=visits)
Example #7
0
def leaderboard():
    entries = sorted(db.get_entries(), key=lambda s: s.score, reverse=True)[:10]
    return render_template("leaderboard.html", entries=entries)
Example #8
0
menu = """Please select one of the following options:

1) Add New Entry for today.
2) View Entries
3) Exit
=>  """


def prompt_new_entry():
    content = input("Subject studied today: ")
    entry_date = input("Date: ")
    add_entry(content, entry_date)


def view_entries(entries):
    for entry in entries:
        print(f"{entry[1]:<{12}}{entry[0]}")


# initialise the database
create_tables()

while (user_input := input(menu)) != "3":
    if user_input == "1":
        prompt_new_entry()

    elif user_input == "2":
        view_entries(get_entries())
    else:
        print("Invalid option. Please try again")
Example #9
0
 def get(self):
     start = self.get_argument("start", None)
     entries, extra = db.get_entries(start, config.POSTS_IN_FEED)
     self.set_header("Content-Type", "application/atom+xml")
     self.render("feed.xml", entries=entries)
Example #10
0
 def get(self, tag):
     start = self.get_argument("start", None)
     tag = tornado.escape.url_unescape(tag)
     entries, extra = db.get_entries(start, config.POSTS_PER_PAGE, tag=tag)
     if not entries: raise tornado.web.HTTPError(404)
     self.render("home.html", entries=entries, extra=extra)
Example #11
0
 def get(self):
     start = self.get_argument("start", None)
     entries, extra = db.get_entries(start, config.POSTS_PER_ARCHIVE)
     self.render("archive.html", entries=entries, extra=extra)
Example #12
0
 def get(self):
     start = self.get_argument("start", None)
     entries, extra = db.get_entries(start, config.POSTS_IN_FEED)
     self.set_header("Content-Type", "application/atom+xml")
     self.render("feed.xml", entries=entries)
Example #13
0
 def get(self, tag):
     start = self.get_argument("start", None)
     tag = tornado.escape.url_unescape(tag)
     entries, extra = db.get_entries(start, config.POSTS_PER_PAGE, tag=tag)
     if not entries: raise tornado.web.HTTPError(404)
     self.render("home.html", entries=entries, extra=extra)
Example #14
0
 def get(self):
     start = self.get_argument("start", None)
     entries, extra = db.get_entries(start, config.POSTS_PER_ARCHIVE)
     self.render("archive.html", entries=entries, extra=extra)
Example #15
0
 def GET(self):
     return render.dict(db.get_entries(), db.get_total_entries())
Example #16
0
def get_documents():
	texts = db.get_entries('', -1000, -1000, 10000, 10000, '')

	return [{"text": text['txt'], "tokens": text['txt'].split()}
			 for i, text in enumerate(texts)]