def main() -> None: for filename in sys.argv[1:]: with open(filename, "r") as f: content = f.read() formatted_contents = align_beancount(content) if formatted_contents != content: with open(filename, "w") as f: f.write(formatted_contents)
def format_transactions(self, backup=True, **kwargs): from beancount.scripts.format import align_beancount original = self.transactions_file.read_text() new = align_beancount(original, **kwargs) if backup: self.transaction_backup_file.write_text(original) self.transactions_file.write_text(new)
def test_api_format_source(app, test_client): with app.test_request_context(): app.preprocess_request() url = flask.url_for('json_api.format_source') path = app.config['BEANCOUNT_FILES'][0] payload = open(path).read() result = test_client.post(url, data=flask.json.dumps({'source': payload}), content_type='application/json') data = flask.json.loads(result.get_data(True)) assert data == {'payload': align_beancount(payload), 'success': True}
def test_api_format_source(app, test_client): with app.test_request_context(): app.preprocess_request() url = flask.url_for('api_format_source') path = app.config['BEANCOUNT_FILES'][0] payload = open(path).read() result = test_client.post(url, data=flask.json.dumps({'source': payload}), content_type='application/json') data = flask.json.loads(result.get_data(True)) assert data == {'payload': align_beancount(payload), 'success': True} # test bad request response = test_client.post(url) assert response.status_code == 400
def format_source(): """Format beancount file.""" if request.get_json() is None: abort(400) return _api_success(payload=align_beancount(request.get_json()['source']))
def format_source(): """Format beancount file.""" request_data = request.get_json() if request_data is None: raise FavaAPIException('Invalid JSON request.') return _api_success(payload=align_beancount(request_data['source']))
def format_source(request_data): """Format beancount file.""" return {'payload': align_beancount(request_data['source'])}
def api_format_source(): """Format beancount file.""" request.get_json() if request.get_json() is None: abort(400) return _api_success(payload=align_beancount(request.get_json()['source']))
def format(self, file_contents): return align_beancount(file_contents)
def api_format_source(): return jsonify({'success': True, 'payload': align_beancount(request.form['source'])})
def api_format_source(): request.get_json() if request.json is None: abort(400) return api_success(payload=align_beancount(request.json['source']))