728x90

python 7

Jenkins의 모든 프로젝트 disable 상태로 만들기

Jenkins의 모든 프로젝트 disable 상태로 만들기 Jenkins에서 제공하는 API를 이용하여 모든 프로젝트를 disable 상태로 수정하는 python 스크립트입니다. import sys import json import requests from requests.auth import HTTPBasicAuth JENKINS_HOST = 'https://jenkins.com' JENKINS_USER = 'user' JENKINS_PASSWORD = 'password' JOS_DISABLE_STATUS = 'disabled' crumb_req = requests.get(JENKINS_HOST+'/crumbIssuer/api/json', auth=HTTPBasicAuth(JENKINS_USER, JE..

Jenkins 2019.08.02

Django Rest Framework Excel Renderer 클래스

Django Rest Framework Excel Renderer 클래스 Django Rest Framework에서 엑셀다운로드 방법을 설명합니다. 우선 openpyxl 엑셀 핸들링할 수 있는 패키지를 설치해야합니다. $ pip install openpyxl 그리고 아래의 Renderer클래스를 작성해주세요. 아래의 코드는 스트리밍으로 엑셀을 다운로드 받는 형식입니다. Django Rest Framework에는 여러가지 개념이 있는데 아래의 코드는 Renderer를 이용한 예제입니다. from io import BytesIO from openpyxl import Workbook from rest_framework.renderers import BaseRenderer class ExcelRenderer(B..

Python/Django 2017.08.02

Django ORM기반 ERD 생성

Django ORM기반 ERD 생성 Django ORM기반으로 ERD를 자동으로 생성합니다. 사전에 graphviz를 설치하셔야합니다. // mac $ brew install graphviz // ubuntu $ apt-get install graphviz 패키지 설치 $ pip install pyparsing $ pip install pygraphviz $ pip install pydot3 $ pip install django-extensions 설정 파일추가 Django 설정파일에 아래와 같이 추가해주세요. INSTALLED_APPS += ( 'django_extensions', ) ERD 생성 아래의 명령어를 실행하시면 erd.png 파일로 Django model 기반으로 ERD가 생성됩니다. 단점..

Python/Django 2017.07.06

Python 네이버 블로그 글쓰기

Python 네이버 블로그 글쓰기 네이버 블로그 글쓰기API를 이용한 코드입니다. 아래의 코드를 사용하기 위해서 네이버 블로그 관리의 글쓰기API 설정을 하셔야합니다. import xmlrpc.client API_URL = 'https://api.blog.naver.com/xmlrpc' class NaverBlog(object): def __init__(self, user_id, api_key): self.__server = None self.__user_id = user_id self.__api_key = api_key self.__categories = [] try: self.__set_categories() except Exception as e: raise e def __client(self): ..

Python 2017.07.02

Python AES 암/복호화

Python AES 암/복호화 아래의 코드를 사용하기 위해서 먼저 pycrypto 를 설치하셔야 합니다 $ pip install pycrypto import base64 import hashlib from Crypto.Cipher import AES BS = 16 pad = (lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS).encode()) unpad = (lambda s: s[:-ord(s[len(s)-1:])]) class AESCipher(object): def __init__(self, key): self.key = hashlib.sha256(key.encode()).digest() def encrypt(self, message): messag..

Python 2017.07.02
728x90