def load_local(filename=local_frab_feed): if os.path.exists(filename): with open(filename, 'r') as f: try: content = f.read().decode('utf-8') result = json.loads(content, strict=False) except (ValueError, Exception) as e: logger.error('could not parse json file ~ %s' %(e)) else: return result else: logger.info('json file %s not found' %(filename))
def load_remote(): content = web_scrape(remote_frab_feed) if content is not None: try: with open(local_frab_feed, 'w') as f: f.write(content) except Exception as e: logger.error('could not save json ~ %s' %(e)) else: logger.info('json file sucessfully written') else: logger.error('json scrape failed ~ %s' %(remote_frab_feed))
def internal_error(error): logger.error('Request Error: %s' %(error)) flash('Panic!!1!') return render_template('error.html', message = 'An unexpected error has occurred'), 500
def web_scrape(url): try: response = urlopen(url) return response.read() except (HTTPError, URLError, HTTPException, Exception) as e: logger.error('could not download %s ~ %s' %(url, e))
def internal_error(error): logger.error('Request Error: %s' %(error)) flash('I checked twice!') return render_template('error.html', message = 'File not found'), 404