{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from ipywidgets import widgets\n", "from IPython.display import display\n", "import pandas as pd\n", "import numpy as np\n", "from ipywidgets import interact\n", "import codecs\n", "import os" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pickle\n", "def save(object_to_save, path):\n", " '''\n", " 保存对象\n", " @Arugs:\n", " object_to_save: 需要保存的对象\n", "\n", " @Return:\n", " 保存的路径\n", " '''\n", " with open(path, 'wb') as f:\n", " pickle.dump(object_to_save, f)\n", "def load(path):\n", " '''\n", " 读取对象\n", " @Arugs:\n", " path: 读取的路径\n", "\n", " @Return:\n", " 读取的对象\n", " '''\n", " with open(path, 'rb') as f:\n", " object = pickle.load(f)\n", " return object\n", "def saveIndex(file,index):\n", " with codecs.open(file,\"w\") as f:\n", " f.write(str(index))\n", " f.flush()\n", " f.close()\n", " \n", "def getIndex(file):\n", " with codecs.open(file,\"r\") as f:\n", " i = f.readline().strip()\n", " return i" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n" ] }, { "data": { "text/plain": [ "500" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "home = \"/home/python/luojiehua/\"\n", "filename = \"projectlabel9.xls\"\n", "\n", "\n", "if os.path.exists(home+filename+\".pk\"):\n", " print(1)\n", " df = load(home+filename+\".pk\")\n", " index = int(getIndex(home+filename+\".txt\"))\n", "else:\n", " df = pd.read_excel(home+filename)\n", " df['projectcode'] = ''\n", " df['projectname'] = ''\n", " index = 0\n", "len(df)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "type(index)\n", "index=0" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "scrolled": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c9a682b3fdd34a649d2edec49a3a9337", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HTML(value='
\\r\\r\\n
\\r\\r\\n 招标公告编号: \\r\\r\\n 088852 \\r\\r\\n
\\r\\r\\n 发布时间: 2018-08…" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5c1e02cf223747999e2524fd7c4d5887", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Text(value='', description='项目编号')" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "954e4c7ad2304ad49c71d252eb5f61e4", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Text(value='', description='项目名称')" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "24f3cd10b7224d9d8d11f5925787f44b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Button(description='此篇完成', style=ButtonStyle())" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "448424f9e5204cd28001dcb6ad8e078a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Button(description='返回上篇', style=ButtonStyle())" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "58e5a44b10eb4462b88ad49f43a555e2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Button(description='保存', style=ButtonStyle())" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "def code_change(value_change):\n", " df.loc[index]['projectcode'] = value_change.new\n", " return\n", " \n", "def name_change(value_change):\n", " df.loc[index]['projectname'] = value_change.new\n", " return\n", "def ok_change(b):\n", " global index\n", " if index>=len(df):\n", " print(\"完成全部文章\")\n", " return\n", " index += 1\n", " if index%10==0:\n", " save(df, home+filename+\".pk\")\n", " saveIndex(home+filename+\".txt\",index)\n", " if index