전체 글 621

[33-2 파이썬] API 실습하기(Kanye.rest, 명언 가져오기)

Kanye 명언 API 칸예 사이트에서 무료로 제공하는 API를 활용해보자. https://kanye.rest/ 여러 가지 명언을 제공한다. 우리는 이것을 requests하고, 칸예 사이트에서 response하면 이를 저장하여 사용한다. - URL 주소 - 요청하기 requests.get(url=) - 예외잡기 raise_for_status() - 제이슨 파일로 변환하기 json() - 원하는 속성 가져오기 [ ] import requests response= requests.get(url="https://api.kanye.rest") response.raise_for_status() data = response.json() quote = data['quote']

[33-1 파이썬] API, JSON, Request, Response code, status_code, raise_for_status, endpoint, url, JSON viewer Awesome

Application Programming Interface API란? 명령, 함수, 프로토컬, 객체로 이루어져있다. 프로그래머들은 API를 이용해 소프트웨어를 생성하거나, 다양한 웹사이트에서 그들이 제공하는 데이터를 요청(request)하고, 받는(response)다. An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software.(위키피디아) My Program 나의 프로그램 Request >>>> Exter..

[32-5 파이썬] 업무 자동화, 파이썬 코드 자동으로 실행하도록 스케줄하기

업무 자동화를 실현시켜 줄 기능을 배운다. 수작업으로 코드를 실행시키는 것이 아니라, 코드를 클라우드에 넣고 매일 코드를 실행하도록 만든다. 이용할 사이트는 pythonanywhere 파이썬애니웨어이다. 무료이다. https://www.pythonanywhere.com/ Host, run, and code Python in the cloud: PythonAnywhere Batteries included With Python versions 2.7, 3.6, 3.7, 3.8, 3.9 and 3.10, and all the goodies you normally find in a Python installation, PythonAnywhere is also preconfigured with loads of u..

[32-4 파이썬] 파이썬으로 생일 축하 메일 보내기

1. datetime 모듈 불러오기 from datetime import datetime today = datetime.now() today_tuple = (today.month, today.day) 2. pandas.read_csv(파일경로) import pandas data = pandas.read_csv("birthdays.csv") 3. iterrows() 한 줄씩 가져오기 new_dict = {(data_row['month'], data_row['day']): data_row for (index, data_row) in data.iterrows()} 4. if 조건문, random.randint(a, b)-> a~b 중 하나의 정수 import random if today_tuple in new..

[32-3 파이썬] 파이썬으로 긍정 명언 이메일 보내기

1. 요일 확인하기 weekday는 0~6까지의 숫자, integer타입으로 출력된다. import datetime now = datetime.datetime.now() weekday= now.weekday() print(type(weekday)) 2. 파일 생성하기 명언이 담겨있는 quotes.txt파일을 읽기 모드로 readlines로 불러와 리스트 타입으로 저장하고, random모듈을 이용하여 하나의 문장만 선택한다. import random with open(file="quotes.txt") as f: data = f.readlines() pick_one_quotes = random.choice(data) quotes.txt "There is no traffic jam along the extra..