{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from jinja2 import Environment, PackageLoader, select_autoescape\n", "\n", "\n", "with open('./app/core/airflow/templates/data_transfer/data_transfer_basic.py') as f:\n", " script = f.read()\n" ] }, { "cell_type": "code", "execution_count": 2, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2022-10-16 01:09:43,455| \"/Users/luoyulong/PycharmProjects/ai2/datax-admin/app/models/database.py\", line 26,\n", " INFO: connect to mysql success: mysql+mysqlconnector://root:happylay@192.168.199.107:10086/datax_web_dev?charset=utf8&auth_plugin=mysql_native_password\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "get config of None\n", "192.168.199.107\n" ] } ], "source": [ "env = Environment(\n", " loader=PackageLoader('app.core.airflow'),\n", " autoescape=select_autoescape()\n", ")\n", "template = env.get_template(\"data_transfer/data_transfer.py\")\n", "temp_str = template.render( {\"env\": {\"SCRIPT\":script}} )" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 3, "outputs": [], "source": [ "with open('./app/core/airflow/templates/data_transfer/data_transfer_task.py','w') as f:\n", " f.write(temp_str)\n", " f.close()" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [], "metadata": { "collapsed": false } } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }