def get_results(area_code=None, n=None): '''Get results according to <area_code> and <n> values given in reporting instructions and format them for displaying. ''' # separate all entries for just one area code,if requested if area_code: es = data.get_entries(None) entries = [entry for entry in es if entry[0][:3] == area_code] # Pick only n first entries, if n is provided if n != None: entries_length = len(entries) # Log a warning, if there is less entries available than requested if n > entries_length: warn_msg = 'Asking to display %d results, ' +\ 'but only %d results with %s area code were found.' logging.warning(warn_msg % (n, entries_length, area_code)) entries = entries[:n] else: # obtain n or all entries (when n=None) # created by scraping 800notes.com and saved in numbers.db entries = data.get_entries(n) #pdb.set_trace() output = ('Showing a total of %d results.<br>' % len(entries)) # combine all results in one string to be displayed for entry in entries: output += '[' + u', '.join(entry) + ']<br>' return output
def new_link(): link = request.form["link"] short = int(get_entries()[-1]["short"]) + 1 add_entry({ "link": link, "short": short }) return render_template("new_link.html", short=short)
def diary(): """ Displays the journey diary entries. These are supplied to the diary template in the following format: diary_entries = [ { "id":"1", "date": "Friday 7th June 2013", "time": "09:00", "destination": "home", "duration":"90", "legs": [ { "rating": "1", "mode": "bus", "no": "1", "duration": "50" }, { "rating": "5", "mode": "bke", "no": "2", "duration": "30" } ], "notes": "the quick", "origin": "away", "overall_rating": "5" }, { "id": "2", "date": "Saturday 8th June 2013", "time": "16:00", "destination": "away", "duration":"45", "legs": [ { "rating": "2", "mode": "m", "no": "1", "duration": "45" } ], "notes": "brown fox", "origin": "home", "overall_rating": "3" } ] """ diary_entries = data.get_entries(datadb, session['uuid']) return render_template('diary.html', diary_entries=diary_entries, diary=json.dumps(diary_entries))
def get_results(n=None): if n is not None: if not isinstance(n, int): return None entries = data.get_entries(n) if entries is None: return None return u'[' + u', '.join(map(unicode, entries)) + u']'
def diary(): """ Displays the journey diary entries. These are supplied to the diary template in the following format: diary_entries = [ { "id":"1", "date": "Friday 7th June 2013", "time": "09:00", "destination": "home", "duration":"90", "legs": [ { "rating": "1", "mode": "bus", "no": "1", "duration": "50" }, { "rating": "5", "mode": "bke", "no": "2", "duration": "30" } ], "notes": "the quick", "origin": "away", "overall_rating": "5" }, { "id": "2", "date": "Saturday 8th June 2013", "time": "16:00", "destination": "away", "duration":"45", "legs": [ { "rating": "2", "mode": "m", "no": "1", "duration": "45" } ], "notes": "brown fox", "origin": "home", "overall_rating": "3" } ] """ diary_entries = data.get_entries(datadb, session['uuid']) return render_template('diary.html', diary_entries = diary_entries, diary = json.dumps(diary_entries))
def get_results(count=None, area_code=None): entries = data.get_entries(count, area_code) if len(entries) == 0: raise RestfulException('No results found', status_code=404) return u'[' + u', '.join(map(unicode, data.get_entries(count, area_code))) + u']'
def post(post_id): entry = get_entries()[post_id - 1] return render_template('post.html', entry=entry, login=request.cookies.get('login', None))
def home(): return render_template('home.html', entries=get_entries(), login=request.cookies.get('login', None))
def home(): return render_template('home.html', entries=get_entries())
def post(post_id): entry = get_entries()[post_id - 1] return render_template('post.html', entry=entry)
def get_results(n=None): return u'[' + u', '.join(map(unicode, data.get_entries(n))) + u']'
def home(): return render_template( 'home.html', entries=get_entries(), login=request.cookies.get('login', None))
def short(short): if short < len(get_entries()): return redirect(get_entries()[short]["link"], code=302) else: return redirect("/not_found")