diff --git "a/python/askdjango-work-automation/.ipynb_checkpoints/01 - \354\235\264\353\251\224\354\235\274 \353\263\264\353\202\264\352\270\260-checkpoint.ipynb" "b/python/askdjango-work-automation/.ipynb_checkpoints/01 - \354\235\264\353\251\224\354\235\274 \353\263\264\353\202\264\352\270\260-checkpoint.ipynb" new file mode 100644 index 0000000000..23e21959d6 --- /dev/null +++ "b/python/askdjango-work-automation/.ipynb_checkpoints/01 - \354\235\264\353\251\224\354\235\274 \353\263\264\353\202\264\352\270\260-checkpoint.ipynb" @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import smptlib\n", + "from email.message import EmailMessage\n", + "\n", + "import getpass\n", + "password = getpass.getpass('Password : ')\n", + "\n", + "message = EmailMessage()\n", + "message['Subject'] = '이메일 제목'\n", + "message['From'] = 'hasblue@naver.com'\n", + "message['To'] = 'neverlish@gmail.com' # 수신자 이메일 다수 (구분자: 콤마)\n", + "\n", + "message.set_content('''이메일내용\n", + "\n", + "안녕하세요. AskDjango입니다.\n", + "\n", + "이 부분에는 이메일의 내용을 쓰실 수 있으며, HTML은 불가합니다.\n", + "HTML을 쓰시면 태그가 그대로 노출됩니다.\n", + "\n", + "여러분의 파이썬/장고 페이스메이커가 되겠습니다. 감사합니다;)''')\n", + "\n", + "with smptlib.SMTP_SSL('smtp.naver.com', 465) as server:\n", + " server.ehlo()\n", + " server.login('hasblue', password)\n", + " server.send_message(message)\n", + "\n", + "print('이메일을 발송했습니다.')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/python/askdjango-work-automation/.ipynb_checkpoints/02 - SMS \353\263\264\353\202\264\352\270\260 (\354\271\264\355\216\23024)-checkpoint.ipynb" "b/python/askdjango-work-automation/.ipynb_checkpoints/02 - SMS \353\263\264\353\202\264\352\270\260 (\354\271\264\355\216\23024)-checkpoint.ipynb" new file mode 100644 index 0000000000..2fd64429bf --- /dev/null +++ "b/python/askdjango-work-automation/.ipynb_checkpoints/02 - SMS \353\263\264\353\202\264\352\270\260 (\354\271\264\355\216\23024)-checkpoint.ipynb" @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/python/askdjango-work-automation/.ipynb_checkpoints/03 - CSV,\354\227\221\354\205\200 \355\214\214\354\235\274 \353\247\214\353\223\244\352\270\260-checkpoint.ipynb" "b/python/askdjango-work-automation/.ipynb_checkpoints/03 - CSV,\354\227\221\354\205\200 \355\214\214\354\235\274 \353\247\214\353\223\244\352\270\260-checkpoint.ipynb" new file mode 100644 index 0000000000..2fd64429bf --- /dev/null +++ "b/python/askdjango-work-automation/.ipynb_checkpoints/03 - CSV,\354\227\221\354\205\200 \355\214\214\354\235\274 \353\247\214\353\223\244\352\270\260-checkpoint.ipynb" @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/python/askdjango-work-automation/.ipynb_checkpoints/04 - Selenium\354\235\204 \355\206\265\355\225\264 \354\271\264\355\216\230\354\227\220 \355\214\214\354\235\264\354\215\254\354\234\274\353\241\234 \352\270\200 \354\223\260\352\270\260-checkpoint.ipynb" "b/python/askdjango-work-automation/.ipynb_checkpoints/04 - Selenium\354\235\204 \355\206\265\355\225\264 \354\271\264\355\216\230\354\227\220 \355\214\214\354\235\264\354\215\254\354\234\274\353\241\234 \352\270\200 \354\223\260\352\270\260-checkpoint.ipynb" new file mode 100644 index 0000000000..2fd64429bf --- /dev/null +++ "b/python/askdjango-work-automation/.ipynb_checkpoints/04 - Selenium\354\235\204 \355\206\265\355\225\264 \354\271\264\355\216\230\354\227\220 \355\214\214\354\235\264\354\215\254\354\234\274\353\241\234 \352\270\200 \354\223\260\352\270\260-checkpoint.ipynb" @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/python/askdjango-work-automation/.ipynb_checkpoints/05 - \354\212\254\353\236\231 \353\251\224\354\204\270\354\247\200 \353\263\264\353\202\264\352\270\260-checkpoint.ipynb" "b/python/askdjango-work-automation/.ipynb_checkpoints/05 - \354\212\254\353\236\231 \353\251\224\354\204\270\354\247\200 \353\263\264\353\202\264\352\270\260-checkpoint.ipynb" new file mode 100644 index 0000000000..2fd64429bf --- /dev/null +++ "b/python/askdjango-work-automation/.ipynb_checkpoints/05 - \354\212\254\353\236\231 \353\251\224\354\204\270\354\247\200 \353\263\264\353\202\264\352\270\260-checkpoint.ipynb" @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/python/askdjango-work-automation/01 - \354\235\264\353\251\224\354\235\274 \353\263\264\353\202\264\352\270\260.ipynb" "b/python/askdjango-work-automation/01 - \354\235\264\353\251\224\354\235\274 \353\263\264\353\202\264\352\270\260.ipynb" new file mode 100644 index 0000000000..3304ccd7d1 --- /dev/null +++ "b/python/askdjango-work-automation/01 - \354\235\264\353\251\224\354\235\274 \353\263\264\353\202\264\352\270\260.ipynb" @@ -0,0 +1,117 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 텍스트 메일 보내기" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Password : ········\n", + "이메일을 발송했습니다.\n" + ] + } + ], + "source": [ + "import os\n", + "import smtplib\n", + "from email.message import EmailMessage\n", + "from email.mime.application import MIMEApplication\n", + "\n", + "import getpass\n", + "password = getpass.getpass('Password : ')\n", + "\n", + "message = EmailMessage()\n", + "message['Subject'] = '이메일 제목'\n", + "message['From'] = 'hasblue@naver.com'\n", + "message['To'] = 'neverlish@gmail.com' # 수신자 이메일 다수 (구분자: 콤마)\n", + "\n", + "message.set_content('''이메일내용\n", + "\n", + "안녕하세요. AskDjango입니다.\n", + "\n", + "이 부분에는 이메일의 내용을 쓰실 수 있으며, HTML은 불가합니다.\n", + "HTML을 쓰시면 태그가 그대로 노출됩니다.\n", + "\n", + "여러분의 파이썬/장고 페이스메이커가 되겠습니다. 감사합니다;)''')\n", + "\n", + "message.add_alternative('''\n", + "

AskDjango VOD

\n", + " \n", + " \n", + " \n", + "

이 부분에는 이메일의 내용을 쓰실 수 있으며, HTML은 불가합니다.\n", + "HTML을 쓰시면 태그가 그대로 노출됩니다.\n", + "\n", + "여러분의 파이썬/장고 페이스메이커가 되겠습니다. 감사합니다;)

\n", + "''', subtype='html')\n", + "\n", + "# 이미지 첨부\n", + "filepath_list = ['./f1.jpg', './f2.jpg', './f3.jpg']\n", + "for filepath in filepath_list:\n", + " with open(filepath, 'rb') as f:\n", + " filename = os.path.basename(filepath)\n", + " cid = filename\n", + " image_data = f.read()\n", + " part = MIMEApplication(image_data, name=filepath)\n", + " part.add_header('Content-ID', '<' + cid + '>')\n", + " message.attach(part)\n", + "\n", + "with smtplib.SMTP_SSL('smtp.naver.com', 465) as server:\n", + " server.ehlo()\n", + " server.login('hasblue', password)\n", + " server.send_message(message)\n", + "\n", + "print('이메일을 발송했습니다.')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/python/askdjango-work-automation/02 - SMS \353\263\264\353\202\264\352\270\260 (\354\271\264\355\216\23024).ipynb" "b/python/askdjango-work-automation/02 - SMS \353\263\264\353\202\264\352\270\260 (\354\271\264\355\216\23024).ipynb" new file mode 100644 index 0000000000..c8029129ab --- /dev/null +++ "b/python/askdjango-work-automation/02 - SMS \353\263\264\353\202\264\352\270\260 (\354\271\264\355\216\23024).ipynb" @@ -0,0 +1,143 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## SMS 잔여건수" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from base64 import b64encode\n", + "import requests" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "url = \"http://sslsms.cafe24.com/sms_remain.php\"\n", + "user_id = b64encode(\"hadblue\".encode('euckr'))\n", + "secure = b64encode(\"9527f3f8c24a248eb3c992bae2db827b\".encode('euckr'))\n", + "mode = b64encode(\"1\".encode('euckr'))\n", + "\n", + "response = requests.post(url, data={\n", + " 'user_id': user_id,\n", + " 'secure': secure,\n", + " 'mode': mode,\n", + "})" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'300'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "response.text" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "def send_sms(user_id, secure, sender, receivers, message):\n", + " params = {\n", + " 'user_id': user_id,\n", + " 'secure': secure,\n", + " 'mode': '1',\n", + " 'sphone1': sender[:3],\n", + " 'sphone2': sender[3:-4],\n", + " 'sphone3': sender[-4:],\n", + " 'rphone': ','.join(receivers),\n", + " 'msg': message,\n", + " }\n", + "\n", + " data = {}\n", + " for key, value in params.items():\n", + " if isinstance(value, str):\n", + " value = value.encode('euckr')\n", + " if key == 'msg':\n", + " value = value[:90].decode('euckr','ignore').encode('euckr')\n", + " data[key] = value\n", + "\n", + " response = requests.post('https://sslsms.cafe24.com/sms_sender.php', data=data)\n", + " return response.text" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'success,298'" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "send_sms('hadblue', '9527f3f8c24a248eb3c992bae2db827b', '01087750467', ['01087750467'], '안녕하세요! SMS 보내기 테스트입니다.')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/python/askdjango-work-automation/03 - CSV,\354\227\221\354\205\200 \355\214\214\354\235\274 \353\247\214\353\223\244\352\270\260.ipynb" "b/python/askdjango-work-automation/03 - CSV,\354\227\221\354\205\200 \355\214\214\354\235\274 \353\247\214\353\223\244\352\270\260.ipynb" new file mode 100644 index 0000000000..6e72e196fb --- /dev/null +++ "b/python/askdjango-work-automation/03 - CSV,\354\227\221\354\205\200 \355\214\214\354\235\274 \353\247\214\353\223\244\352\270\260.ipynb" @@ -0,0 +1,375 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## CSV 라이브러리를 쓰세요." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import csv\n", + "\n", + "rows = [\n", + " ['월요웹툰', '화요웹툰', '수요웹툰', '목요웹툰', '금요웹툰', '토요웹툰', '일요웹툰'],\n", + " ['신의 탑', '마음의소리', '고수', '기기괴괴', '덴마', '호랑이형님', '열럽전사'],\n", + " ['귀전구담', '노블레스', '퍼미스미션', '하루 3컷', '테러맨', '부활남', '다이스'], \n", + " ['히어로메이커', '하이브', 'DEY 호러채널', '마술사', '오즈랜드', '유미의세포들', '조선왕조실톡'],\n", + "]\n", + "\n", + "with open('webtoon.csv', 'wt', encoding='utf8') as f:\n", + " writer = csv.writer(f)\n", + " writer.writerows(rows)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "월요웹툰,화요웹툰,수요웹툰,목요웹툰,금요웹툰,토요웹툰,일요웹툰\n", + "신의 탑,마음의소리,고수,기기괴괴,덴마,호랑이형님,열럽전사\n", + "귀전구담,노블레스,퍼미스미션,하루 3컷,테러맨,부활남,다이스\n", + "히어로메이커,하이브,DEY 호러채널,마술사,오즈랜드,유미의세포들,조선왕조실톡\n", + "\n" + ] + } + ], + "source": [ + "with open('webtoon.csv', 'rt', encoding='utf8') as f:\n", + " print(f.read())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## csv.DictWriter" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import csv\n", + "\n", + "with open('webtoon_dictwriter.csv', 'wt', encoding='utf8') as f:\n", + " fieldnames = ['last_name', 'first_name']\n", + " \n", + " writer = csv.DictWriter(f, fieldnames=fieldnames)\n", + " \n", + " writer.writeheader()\n", + " \n", + " # 1 Row를 쓸 때\n", + " writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'})\n", + " \n", + " # 다수 Row를 쓸 때\n", + " writer.writerows([\n", + " {'first_name': 'Lovely', 'last_name': 'Spam'},\n", + " {'first_name': 'Wonderful', 'last_name': 'Spam'},\n", + " ])" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "last_name,first_name\n", + "Beans,Baked\n", + "Spam,Lovely\n", + "Spam,Wonderful\n", + "\n" + ] + } + ], + "source": [ + "with open('webtoon_dictwriter.csv', 'rt', encoding='utf8') as f:\n", + " print(f.read())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## CSV 읽기" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['월요웹툰', '화요웹툰', '수요웹툰', '목요웹툰', '금요웹툰', '토요웹툰', '일요웹툰\\n']\n", + "['신의 탑', '마음의소리', '고수', '기기괴괴', '덴마', '호랑이형님', '열럽전사\\n']\n", + "['귀전구담', '노블레스', '퍼미스미션', '하루 3컷', '테러맨', '부활남', '다이스\\n']\n", + "['히어로메이커', '하이브', 'DEY 호러채널', '마술사', '오즈랜드', '유미의세포들', '조선왕조실톡\\n']\n" + ] + } + ], + "source": [ + "with open('webtoon.csv', 'rt', encoding='utf8') as f:\n", + " for line in f:\n", + " row = line.split(',')\n", + " print(row) # list type" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['월요웹툰', '화요웹툰', '수요웹툰', '목요웹툰', '금요웹툰', '토요웹툰', '일요웹툰']\n", + "['신의 탑', '마음의소리', '고수', '기기괴괴', '덴마', '호랑이형님', '열럽전사']\n", + "['귀전구담', '노블레스', '퍼미스미션', '하루 3컷', '테러맨', '부활남', '다이스']\n", + "['히어로메이커', '하이브', 'DEY 호러채널', '마술사', '오즈랜드', '유미의세포들', '조선왕조실톡']\n" + ] + } + ], + "source": [ + "import csv\n", + "with open('webtoon.csv', 'rt', encoding='utf8') as f:\n", + " reader = csv.reader(f)\n", + " for row in reader:\n", + " print(row) # list type" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "OrderedDict([('last_name', 'Beans'), ('first_name', 'Baked')])\n", + "OrderedDict([('last_name', 'Spam'), ('first_name', 'Lovely')])\n", + "OrderedDict([('last_name', 'Spam'), ('first_name', 'Wonderful')])\n" + ] + } + ], + "source": [ + "import csv\n", + "\n", + "with open('webtoon_dictwriter.csv', 'rt', encoding='utf8') as f:\n", + " # line = next(f)\n", + " # fieldnames = line.split(',')\n", + " reader = csv.DictReader(f) #, fieldnames=fieldnames)\n", + " for row in reader:\n", + " print(row) # list type" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## codecs.BOM_UTF8" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import codecs\n", + "codecs.BOM_UTF8" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import tablib" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## tablib" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "rows = [\n", + " ['월요웹툰', '화요웹툰', '수요웹툰', '목요웹툰', '금요웹툰', '토요웹툰', '일요웹툰'],\n", + " ['신의 탑', '마음의소리', '고수', '기기괴괴', '덴마', '호랑이형님', '열럽전사'],\n", + " ['귀전구담', '노블레스', '퍼미스미션', '하루 3컷', '테러맨', '부활남', '다이스'], \n", + " ['히어로메이커', '하이브', 'DEY 호러채널', '마술사', '오즈랜드', '유미의세포들', '조선왕조실톡'],\n", + "]\n", + "\n", + "import tablib\n", + "data = tablib.Dataset()\n", + "data.headers = rows[0]\n", + "for row in rows[1:]:\n", + " data.append(row)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{\"\\uc6d4\\uc694\\uc6f9\\ud230\": \"\\uc2e0\\uc758 \\ud0d1\", \"\\ud654\\uc694\\uc6f9\\ud230\": \"\\ub9c8\\uc74c\\uc758\\uc18c\\ub9ac\", \"\\uc218\\uc694\\uc6f9\\ud230\": \"\\uace0\\uc218\", \"\\ubaa9\\uc694\\uc6f9\\ud230\": \"\\uae30\\uae30\\uad34\\uad34\", \"\\uae08\\uc694\\uc6f9\\ud230\": \"\\ub374\\ub9c8\", \"\\ud1a0\\uc694\\uc6f9\\ud230\": \"\\ud638\\ub791\\uc774\\ud615\\ub2d8\", \"\\uc77c\\uc694\\uc6f9\\ud230\": \"\\uc5f4\\ub7fd\\uc804\\uc0ac\"}, {\"\\uc6d4\\uc694\\uc6f9\\ud230\": \"\\uadc0\\uc804\\uad6c\\ub2f4\", \"\\ud654\\uc694\\uc6f9\\ud230\": \"\\ub178\\ube14\\ub808\\uc2a4\", \"\\uc218\\uc694\\uc6f9\\ud230\": \"\\ud37c\\ubbf8\\uc2a4\\ubbf8\\uc158\", \"\\ubaa9\\uc694\\uc6f9\\ud230\": \"\\ud558\\ub8e8 3\\ucef7\", \"\\uae08\\uc694\\uc6f9\\ud230\": \"\\ud14c\\ub7ec\\ub9e8\", \"\\ud1a0\\uc694\\uc6f9\\ud230\": \"\\ubd80\\ud65c\\ub0a8\", \"\\uc77c\\uc694\\uc6f9\\ud230\": \"\\ub2e4\\uc774\\uc2a4\"}, {\"\\uc6d4\\uc694\\uc6f9\\ud230\": \"\\ud788\\uc5b4\\ub85c\\uba54\\uc774\\ucee4\", \"\\ud654\\uc694\\uc6f9\\ud230\": \"\\ud558\\uc774\\ube0c\", \"\\uc218\\uc694\\uc6f9\\ud230\": \"DEY \\ud638\\ub7ec\\ucc44\\ub110\", \"\\ubaa9\\uc694\\uc6f9\\ud230\": \"\\ub9c8\\uc220\\uc0ac\", \"\\uae08\\uc694\\uc6f9\\ud230\": \"\\uc624\\uc988\\ub79c\\ub4dc\", \"\\ud1a0\\uc694\\uc6f9\\ud230\": \"\\uc720\\ubbf8\\uc758\\uc138\\ud3ec\\ub4e4\", \"\\uc77c\\uc694\\uc6f9\\ud230\": \"\\uc870\\uc120\\uc655\\uc870\\uc2e4\\ud1a1\"}]\n" + ] + } + ], + "source": [ + "print(data.json)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "- {\"\\uAE08\\uC694\\uC6F9\\uD230\": \"\\uB374\\uB9C8\", \"\\uBAA9\\uC694\\uC6F9\\uD230\": \"\\uAE30\\uAE30\\\n", + " \\uAD34\\uAD34\", \"\\uC218\\uC694\\uC6F9\\uD230\": \"\\uACE0\\uC218\", \"\\uC6D4\\uC694\\uC6F9\\uD230\": \"\\uC2E0\\uC758\\\n", + " \\ \\uD0D1\", \"\\uC77C\\uC694\\uC6F9\\uD230\": \"\\uC5F4\\uB7FD\\uC804\\uC0AC\", \"\\uD1A0\\uC694\\uC6F9\\uD230\": \"\\uD638\\uB791\\\n", + " \\uC774\\uD615\\uB2D8\", \"\\uD654\\uC694\\uC6F9\\uD230\": \"\\uB9C8\\uC74C\\uC758\\uC18C\\uB9AC\"}\n", + "- {\"\\uAE08\\uC694\\uC6F9\\uD230\": \"\\uD14C\\uB7EC\\uB9E8\", \"\\uBAA9\\uC694\\uC6F9\\uD230\": \"\\uD558\\uB8E8\\\n", + " \\ 3\\uCEF7\", \"\\uC218\\uC694\\uC6F9\\uD230\": \"\\uD37C\\uBBF8\\uC2A4\\uBBF8\\uC158\", \"\\uC6D4\\uC694\\uC6F9\\uD230\": \"\\uADC0\\uC804\\\n", + " \\uAD6C\\uB2F4\", \"\\uC77C\\uC694\\uC6F9\\uD230\": \"\\uB2E4\\uC774\\uC2A4\", \"\\uD1A0\\uC694\\uC6F9\\uD230\": \"\\uBD80\\uD65C\\\n", + " \\uB0A8\", \"\\uD654\\uC694\\uC6F9\\uD230\": \"\\uB178\\uBE14\\uB808\\uC2A4\"}\n", + "- {\"\\uAE08\\uC694\\uC6F9\\uD230\": \"\\uC624\\uC988\\uB79C\\uB4DC\", \"\\uBAA9\\uC694\\uC6F9\\uD230\": \"\\uB9C8\\uC220\\\n", + " \\uC0AC\", \"\\uC218\\uC694\\uC6F9\\uD230\": \"DEY \\uD638\\uB7EC\\uCC44\\uB110\", \"\\uC6D4\\uC694\\uC6F9\\uD230\": \"\\uD788\\uC5B4\\\n", + " \\uB85C\\uBA54\\uC774\\uCEE4\", \"\\uC77C\\uC694\\uC6F9\\uD230\": \"\\uC870\\uC120\\uC655\\uC870\\\n", + " \\uC2E4\\uD1A1\", \"\\uD1A0\\uC694\\uC6F9\\uD230\": \"\\uC720\\uBBF8\\uC758\\uC138\\uD3EC\\uB4E4\",\n", + " \"\\uD654\\uC694\\uC6F9\\uD230\": \"\\uD558\\uC774\\uBE0C\"}\n", + "\n" + ] + } + ], + "source": [ + "print(data.yaml)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/jinhohyeon/anaconda/lib/python3.6/site-packages/openpyxl/worksheet/worksheet.py:303: UserWarning: Using a coordinate with ws.cell is deprecated. Use ws[coordinate] instead\n", + " warn(\"Using a coordinate with ws.cell is deprecated. Use ws[coordinate] instead\")\n" + ] + } + ], + "source": [ + "with open('data.xlsx', 'wb') as f:\n", + " f.write(data.xlsx) # excel 파일 내용" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/python/askdjango-work-automation/04 - Selenium\354\235\204 \355\206\265\355\225\264 \354\271\264\355\216\230\354\227\220 \355\214\214\354\235\264\354\215\254\354\234\274\353\241\234 \352\270\200 \354\223\260\352\270\260.ipynb" "b/python/askdjango-work-automation/04 - Selenium\354\235\204 \355\206\265\355\225\264 \354\271\264\355\216\230\354\227\220 \355\214\214\354\235\264\354\215\254\354\234\274\353\241\234 \352\270\200 \354\223\260\352\270\260.ipynb" new file mode 100644 index 0000000000..10dd890804 --- /dev/null +++ "b/python/askdjango-work-automation/04 - Selenium\354\235\204 \355\206\265\355\225\264 \354\271\264\355\216\230\354\227\220 \355\214\214\354\235\264\354\215\254\354\234\274\353\241\234 \352\270\200 \354\223\260\352\270\260.ipynb" @@ -0,0 +1,279 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 네이버 검색" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from selenium import webdriver" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "from bs4 import BeautifulSoup\n", + "\n", + "def naver_blog_search(q):\n", + " driver = webdriver.Chrome('./chromedriver')\n", + " driver.get('http://www.naver.com')\n", + " try:\n", + " tag_query = driver.find_element_by_id('query')\n", + " tag_query.click()\n", + " tag_query.send_keys('AskDjango')\n", + " tag_query.submit()\n", + "\n", + " # for tag in driver.find_elements_by_css_selector('.sh_blog_title'):\n", + " # for tag in driver.find_elements_by_class_name('sh_blog_title'):\n", + " # print(tag.text, tag.get_attribute('href'))\n", + "\n", + " html = driver.page_source\n", + " soup = BeautifulSoup(html, 'html.parser')\n", + "\n", + " for tag in soup.select('.sh_blog_title'):\n", + " print(tag.text, tag['href'])\n", + " finally:\n", + " drive.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Askdjango) 파이썬 기본문법 정리 18) 파이썬 클래스... http://myjorney.tistory.com/26\n", + "Askdjango) 파이썬 기본문법 정리3)python 파이썬 들여쓰기... http://myjorney.tistory.com/4\n", + "Askdjango) 파이썬 기본문법 정리1_파이썬의 코드 실행방법... http://myjorney.tistory.com/1\n", + "Askdjango) 파이썬 기본문법 정리)2.파이썬의 기본... http://myjorney.tistory.com/2\n", + "Askdjango) 파이썬 기본문법 정리 17) 파이썬 file... http://myjorney.tistory.com/23\n" + ] + } + ], + "source": [ + "naver_blog_search('장고')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 네이버 로그인 & 카페 글 쓰기" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Username : hasblue\n", + "Password : ········\n" + ] + } + ], + "source": [ + "from selenium import webdriver\n", + "from getpass import getpass\n", + "\n", + "username = input('Username : ')\n", + "password = getpass('Password : ')\n", + "\n", + "driver = webdriver.Chrome('./chromedriver')\n", + "try:\n", + " driver.get('https://nid.naver.com/nidlogin.login') # 웹페이지 방문\n", + " tag_id = driver.find_element_by_name('id') # 태그 name 속성으로 태그 찾기\n", + " tag_id.send_keys(username)\n", + " tag_pw = driver.find_element_by_name('pw') # 태그 name 속성으로 태그 찾기\n", + " tag_pw.send_keys(password)\n", + " tag_pw.submit()\n", + "finally:\n", + " driver.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "driver.get('https://m.cafe.naver.com/askdjango')" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "driver.find_element_by_css_selector('a[class*=WriteArticle]').click()" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from selenium.webdriver.support.ui import Select\n", + "select = Select(driver.find_element_by_name('menuid'))" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "select.select_by_visible_text('파이썬 자동화 연습 게시판')" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "driver.find_element_by_name('subject').clear()\n", + "driver.find_element_by_name('subject').send_keys('테스트 제목 by AskDjango')" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "iframe = driver.find_element_by_tag_name('iframe')\n", + "driver.switch_to_frame(iframe)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "tag_body = driver.find_element_by_tag_name('body')" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "tag_body.click()" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "tag_body.send_keys('''\n", + "마음의 소리 : http://comic.naver.com/webtoon/list.nhn?titleId=20853\n", + "노블레스 : http://comic.naver.com/webtoon/list.nhn?titleId=25455\n", + "신의 탑 : http://comic.naver.com/webtoon/list.nhn?titleId=183559\n", + "하이브 : http://comic.naver.com/webtoon/list.nhn?titleId=609480\n", + "''')" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "driver.switch_to_default_content()" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "driver.find_element_by_css_selector('[class*=Submit]').click()" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "driver.close()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git "a/python/askdjango-work-automation/05 - \354\212\254\353\236\231 \353\251\224\354\204\270\354\247\200 \353\263\264\353\202\264\352\270\260.ipynb" "b/python/askdjango-work-automation/05 - \354\212\254\353\236\231 \353\251\224\354\204\270\354\247\200 \353\263\264\353\202\264\352\270\260.ipynb" new file mode 100644 index 0000000000..2f8b30f9db --- /dev/null +++ "b/python/askdjango-work-automation/05 - \354\212\254\353\236\231 \353\251\224\354\204\270\354\247\200 \353\263\264\353\202\264\352\270\260.ipynb" @@ -0,0 +1,122 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "token = 'xoxb-206182536112-i1V1Kp0kKjj5ezH83I1o4IED'" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from slacker import Slacker" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "slack = Slacker(token)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "slack.chat.post_message('#webtoon', '호랑이형님 새 에피소드가 올라왔어요 !!!')" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "attachments = []\n", + "attachments.append({\n", + " \"fallback\": \"1위) 헤이즈 (HEIZE) - 비도 오고 그래서 (Feat. 신용재)\", # 알림 메세지에 보이는 텍스트 \n", + " \"title\": \"1위) 헤이즈 (HEIZE) - 비도 오고 그래서 (Feat. 신용재)\", # 제목 (볼드체로 보여짐) \n", + " \"title_link\": \"http://music.bugs.co.kr/track/30698526?wl_ref=list_tr_08_chart\", # 제목 링크 # 본문 텍스트\n", + " \"text\": \"\"\" 비도 오고 그래서\n", + "네 생각이 났어 \n", + "생각이 나서 \n", + "그래서 그랬던거지\n", + "별 의미 없지\n", + " \"\"\", # \n", + " # \"image_url\": \"\", # 이미지 URL\n", + " \"thumb_url\": \"http://image.bugsm.co.kr/album/images/50/201049/20104917.jpg?version=20170629164309\", # 썸네일 URL # \n", + " \"color\": \"#ff0000\", # 첨부별 왼쪽 Bar 색상\n", + "})\n", + "slack.chat.post_message('#webtoon', '2017년 벅스차트 TOP 3', attachments=attachments)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/python/askdjango-work-automation/chromedriver b/python/askdjango-work-automation/chromedriver new file mode 100755 index 0000000000..a5ba4acb8e Binary files /dev/null and b/python/askdjango-work-automation/chromedriver differ diff --git a/python/askdjango-work-automation/data.xlsx b/python/askdjango-work-automation/data.xlsx new file mode 100644 index 0000000000..42ed600749 Binary files /dev/null and b/python/askdjango-work-automation/data.xlsx differ diff --git a/python/askdjango-work-automation/f1.jpg b/python/askdjango-work-automation/f1.jpg new file mode 100644 index 0000000000..a1cf6320b6 Binary files /dev/null and b/python/askdjango-work-automation/f1.jpg differ diff --git a/python/askdjango-work-automation/f2.jpg b/python/askdjango-work-automation/f2.jpg new file mode 100644 index 0000000000..22a3f0f771 Binary files /dev/null and b/python/askdjango-work-automation/f2.jpg differ diff --git a/python/askdjango-work-automation/f3.jpg b/python/askdjango-work-automation/f3.jpg new file mode 100644 index 0000000000..ff3ff87175 Binary files /dev/null and b/python/askdjango-work-automation/f3.jpg differ diff --git a/python/askdjango-work-automation/webtoon.csv b/python/askdjango-work-automation/webtoon.csv new file mode 100644 index 0000000000..5ed5e58841 --- /dev/null +++ b/python/askdjango-work-automation/webtoon.csv @@ -0,0 +1,4 @@ +월요웹툰,화요웹툰,수요웹툰,목요웹툰,금요웹툰,토요웹툰,일요웹툰 +신의 탑,마음의소리,고수,기기괴괴,덴마,호랑이형님,열럽전사 +귀전구담,노블레스,퍼미스미션,하루 3컷,테러맨,부활남,다이스 +히어로메이커,하이브,DEY 호러채널,마술사,오즈랜드,유미의세포들,조선왕조실톡 diff --git a/python/askdjango-work-automation/webtoon_dictwriter.csv b/python/askdjango-work-automation/webtoon_dictwriter.csv new file mode 100644 index 0000000000..526a73f334 --- /dev/null +++ b/python/askdjango-work-automation/webtoon_dictwriter.csv @@ -0,0 +1,4 @@ +last_name,first_name +Beans,Baked +Spam,Lovely +Spam,Wonderful