본문 바로가기

Python

(52)
[Slack API] Slack Bot 만들고 Slack 메세지 보내기 / Scopes / slacker 기존에 Bot user을 추가하는 방식은 deprecated되었고, token scope을 지정하는 방식으로 바뀌었다. 그런데 공식 api tutorial도 업데이트가 잘 안되있어서 직접 정리해보았다. Slack 회원가입 후 새로운 workspace 만들기 https://slack.com/intl/en-kr/ Where work happens Slack is where work flows. It's where the people you need, the information you share, and the tools you use come together to get things done. slack.com Slack API에서 새로운 app만들기 https://api.slack.com/ Where w..
[Spotify Web API] 특정 artist의 top 10 playlist 가져오기 / 파이썬 spotipy 라이브러리 사용 Spotify란 전세계 최대의 음원 스트리밍 서비스 그리고 spotify의 web api를 통해서 artists, tracks, playlists 등 유용한 여러 정보를 받을 수 있다. 단, 한국에선 막혀있기 때문에 브라우저의 VPN 우회기능으로 회원가입을 한 후 사용할 수 있다. api를 이용하기 위해서는 로그인 후 dashboard에서 새로운 app을 생성한 후 client id와 client secret을 발급받아야 한다. https://developer.spotify.com/documentation/web-api/ Web API | Spotify for Developers Simply put, your app receives Spotify content through the Spotify Web ..
[YTS YIFY movie API] 영화 다운로드 횟수 TOP 10 / 파이썬 www.yts.mx/api API Documentation - YTS YIFY Official YTS YIFY API documentation. YTS offers free API - an easy way to access the YIFY movies details. yts.mx 코드 # 파이썬 import requests import json api_url = 'https://yts.mx/api/v2/list_movies.json?sort_by=download_count&limit=10' data = requests.get(api_url) json_data = json.loads(data.text) for d in json_data['data']['movies']: print(d['title_long'..
[웹크롤링] 교보문고 베스트셀러 Top20 크롤링하기 requests, beautifulsoup4 설치 $ pip install requests beautifulsoup4 코드 from urllib.request import urlopen from bs4 import BeautifulSoup as bs html = urlopen("http://www.kyobobook.co.kr/bestSellerNew/bestseller.laf") # 교보문고 베스트셀러 bsObject = bs(html, "html.parser") week_standard = bsObject.find('h4', {'class':'title_best_basic'}).find('small').text # 집계기준 날짜 bestseller_contents = bsObject.find('ul',..
[Docker+Django] Dockerfile로 Docker Django 이미지 만들기 / django 2.0 버전 이상 실습 저장소 https://github.com/JisunParkRea/dockerdjango-sample django 공식 이미지의 문제점 Django의 official docker image는 Docker hub에 올려져있다. https://hub.docker.com/_/django 그러나, 문제는 2016-12-31 이후로 지원이 끊겼다는 것이다. 즉, django의 1.x버전까지만 지원을 하고, django 2.0 버전 이상을 사용하기 위해서는 직접 이미지를 만들어야할 필요성이 생겼다. Docker Django 이미지 만들기 나의 실습 환경 Windows 10 Home Docker Toolbox Docker Quickstart Terminal 기본 Django 프로젝트 만들기 $ mkdir djan..
[Django ORM] QuerySet 수정을 통해 성능 향상시키기 / SQL Queries 중복 줄이기 / select_related, prefetch_related 들어가며 처음 video list 페이지를 들어갈 때마다, video의 개수가 늘어나면서 로딩시간이 눈이띄게 길어진 것을 느낄 수 있었다. 그래서 찾게된 QuerySet 효율적으로 사용하기! 초보몽키의 개발공부로그를 통해 웹 성능을 향상시킬 수 있었다. 기존의 문제점 기존의 video list view를 보면 다음과 같은 방법으로 모든 video를 불러오고 이를 template로 넘긴다. video_list = Video.objects.all() # 모든 video 불러오기 return render(request, 'video/video_list.html', {'video_list':video_list}) # template에 넘기기 그리고 django-debug-toolbar을 통해 queries를 확..
[Django Test] Django Unit Test (업데이트 중...2020/04/28) 참고 Django Documentation: Testing in Django Django Tutorial Part 10: Testing a Django web application 실습 저장소 https://github.com/JisunParkRea/my_djangotube JisunParkRea/my_djangotube Simple video service which can upload youtube videos using django - JisunParkRea/my_djangotube github.com models.py 테스트 from django.test import TestCase from django.contrib.auth.models import User from video.models im..
[Error Solved][Django url] django 프로젝트 앱에 <str:category> url을 추가했을 때 모든 url이 해당 url로 라우팅 되는 문제 문제 발생 # video/urls.py from django.urls import path from . import views urlpatterns = [ path('', views.video_list, name='video_list'), path('/', views.video_category, name='video_category'), # url 추가 path('/', views.video_detail, name='video_detail'), path('new/', views.video_new, name='video_new'), path('/delete', views.video_delete, name='video_delete'), path('signup/', views.signup, name='user..