{"comment":{"url":"https://api.github.com/repos/downtiser/python-one/comments/29712824","html_url":"https://github.com/downtiser/python-one/commit/357df184ea7e59907ee15d6e40debb4d4b03c1d0#commitcomment-29712824","id":29712824,"node_id":"MDEzOkNvbW1pdENvbW1lbnQyOTcxMjgyNA==","user":{"login":"downtiser","id":40319754,"node_id":"MDQ6VXNlcjQwMzE5NzU0","avatar_url":"https://avatars1.githubusercontent.com/u/40319754?v=4","gravatar_id":"","url":"https://api.github.com/users/downtiser","html_url":"https://github.com/downtiser","followers_url":"https://api.github.com/users/downtiser/followers","following_url":"https://api.github.com/users/downtiser/following{/other_user}","gists_url":"https://api.github.com/users/downtiser/gists{/gist_id}","starred_url":"https://api.github.com/users/downtiser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/downtiser/subscriptions","organizations_url":"https://api.github.com/users/downtiser/orgs","repos_url":"https://api.github.com/users/downtiser/repos","events_url":"https://api.github.com/users/downtiser/events{/privacy}","received_events_url":"https://api.github.com/users/downtiser/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":null,"commit_id":"357df184ea7e59907ee15d6e40debb4d4b03c1d0","created_at":"2018-07-15T13:09:29Z","updated_at":"2018-07-15T13:09:29Z","author_association":"OWNER","body":"```\r\n#Downtiser\r\n\r\nopration=['search','add','delete']\r\n\r\n\r\n\r\ndef search(search_choice):\r\n    '''搜索文件中是否存在参数值，如果存在，返回具体信息，如果不存在，则报错'''\r\n    f_search=open('haproxy','r',encoding='utf-8')\r\n    res=f_search.read()\r\n    f_search.seek(0)\r\n    if search_choice in res:\r\n        for line in f_search:\r\n            if line.strip()=='bakend %s'%search_choice:\r\n                print(line.strip())\r\n                a=f_search.readline()\r\n                print(a.rstrip())\r\n    else:\r\n        print('record dose not exsit,please input again,or input b or q to leave:')\r\n\r\n    f_search.close()\r\n\r\n\r\ndef add(kwargs):\r\n    '''往文件中追加新内容，如果已经存在，则报错，'''\r\n    f_add=open('haproxy','a+',encoding='utf-8')\r\n    f_add.seek(0)\r\n    res=f_add.read()\r\n\r\n    if kwargs['bakend'] in res:\r\n        print('the record has existed,please input again:')\r\n    else:\r\n        print('successfully write in!')\r\n        f_add.write('\\nbakend %s'%kwargs['bakend'])\r\n        f_add.write('\\n\\t\\tserver: %s '%kwargs['record']['server'])\r\n        f_add.write('weight %s '%kwargs['record']['weight'])\r\n        f_add.write('maxconn %s'%kwargs['record']['maxconn'])\r\n    f_add.close()\r\ndef delete(delete_choice):\r\n    '''删除文件内容，如果内容不存在，则报错'''\r\n    f_old=open('haproxy','r',encoding='utf-8')\r\n    res=f_old.read()\r\n    f_old.seek(0)\r\n    if delete_choice['bakend'] not in res:\r\n        print('The record does not exist,needless to delete,input again!')\r\n        f_old.close()\r\n    else:\r\n        f_new=open('new','w+',encoding='utf-8')\r\n        for line_old in f_old:\r\n            if line_old.strip()=='bakend %s'%delete_choice['bakend']:\r\n                f_old.readline()\r\n                continue\r\n            f_new.write(line_old)\r\n        f_new.close()\r\n        f_old.close()\r\n        f_old2=open('haproxy','w+',encoding='utf-8')\r\n        f_new2=open('new','r',encoding='utf-8')\r\n        for line_new in f_new2:\r\n            f_old2.write(line_new)\r\n        f_old2.close()\r\n        f_new2.close()\r\n        print('delete successfully!')\r\n\r\nwhile True:\r\n    for i,item in enumerate(opration):\r\n        print(i+1,item)\r\n    user_choice=input('please input your option:')\r\n    if user_choice in opration:\r\n        if user_choice=='search':\r\n            user_search='None'\r\n            while user_search!='b' and user_search!='q':\r\n                user_search = input('please input a url(or b to back,q to quit):')\r\n                search(user_search)\r\n            else:\r\n                if user_search=='q':\r\n                    print('quit successfully!')\r\n                    exit()\r\n                else:\r\n                    continue\r\n        elif user_choice=='add':\r\n            user_add=eval(input('please input the addition:'))\r\n            add(user_add)\r\n\r\n\r\n        else:\r\n            user_delete=eval(input('please input what need to be deleted:'))\r\n            delete(user_delete)\r\n\r\n\r\n    elif user_choice=='q':\r\n        break\r\n    else:\r\n        print('wrong input!')\r\n        continue\r\n```"}}
{"actor":{"display_login":"downtiser"}}