def root(): data = apod.get_apod(date.today()) while data is None: data = apod.get_apod(date.today() - timedelta(1)) return render_template('main.html', title=data['title'], img_url=data['image_url'], credits=data['credits'], summary=data['summary'])
def root_pdf(): data = apod.get_apod(date.today()) while data is None: data = apod.get_apod(date.today() - timedelta(1)) file = p.pdf(data) file_data = BytesIO() with open(file, 'rb') as f: file_data.write(f.read()) file_data.seek(0) os.remove(file) return send_file(file_data, mimetype='application/pdf')
def api(year, month, day): try: d = date(int(year), int(month), int(day)) except ValueError: return jsonify({'status': 'INVALID DATE'}) data = apod.get_apod(d) if data is None: return jsonify({'status': 'APOD NOT FOUND'}) data.update({'status': 'ok'}) return jsonify(data)
def api_pdf(year, month, day): try: d = date(int(year), int(month), int(day)) except ValueError: return jsonify({'status': 'INVALID DATE'}) data = apod.get_apod(d) if data is None: return jsonify({'status': 'APOD NOT FOUND'}) file = p.pdf(data) file_data = BytesIO() with open(file, 'rb') as f: file_data.write(f.read()) file_data.seek(0) os.remove(file) return send_file(file_data, mimetype='application/pdf')
def pdf(year, month, day): try: d = date(int(year), int(month), int(day)) except ValueError: return render_template('invalid.html', date=f'{year}-{month}-{day}'), 404 data = apod.get_apod(d) if data is None: if d > date.today(): return render_template('future.html', date=str(d)), 404 elif d < date(1995, 6, 20): return render_template('past.html'), 404 else: return render_template('dunno.html'), 404 return redirect(f'/api/pdf/{year}/{month}/{day}')
def image(year, month, day): try: d = date(int(year), int(month), int(day)) except ValueError: return render_template('invalid.html', date=f'{year}-{month}-{day}'), 404 data = apod.get_apod(d) if data is None: if d > date.today(): return render_template('future.html', date=str(d)), 404 elif d < date(1995, 6, 20): return render_template('past.html'), 404 else: return render_template('dunno.html'), 404 return render_template('image.html', title=data['title'], img_url=data['image_url'], credits=data['credits'], summary=data['summary'], date=data['date'])
def launches(): return render_template('launches.html', launches = get_launches(), apod_pic = get_apod())
def news(): return render_template('news.html', apod_pic = get_apod())
def home(): return render_template('index.html', string = in_space(), apod_pic = get_apod())