# import requests # # # 클라이언트 ID와 시크릿 # client_id = "a15ea42332764b68a95ee5eb4f251269" # client_secret = "29d52a9e9af8484da1fea849eb8efcac" # # # 액세스 토큰 얻기 # auth_response = requests.post( # "https://accounts.spotify.com/api/token", # headers={ # "Content-Type": "application/x-www-form-urlencoded" # }, # data={ # "grant_type": "client_credentials", # "client_id": client_id, # "client_secret": client_secret # } # ) # # # # 응답에서 액세스 토큰 추출 # access_token = auth_response.json().get('access_token') # access_token_type = auth_response.json().get('token_type') # access_expires_in = auth_response.json().get('expires_in') # print("Access Token:", access_token) # print("Access Token type:", access_token_type) # print("Access Token expires:", access_expires_in) # # # 액세스 토큰 얻기 # auth_response = requests.post( # "https://api.spotify.com/v1/artists/4Z8W4fKeB5YxbusRsdQVPb", # headers={ # "Content-Type": "application/x-www-form-urlencoded" # }, # data={ # f"Authorization: {access_token_type} {access_token}", # } # ) # # # 응답에서 액세스 토큰 추출 # response = auth_response.json() # print("result:", response) # # curl "https://api.spotify.com/v1/artists/4Z8W4fKeB5YxbusRsdQVPb" \ # -H "Authorization: Bearer BQDBKJ5eo5jxbtpWjVOj7ryS84khybFpP_lTqzV7uV-T_m0cTfwvdn5BnBSKPxKgEb11 # # # Access Token: BQDxR71s2Ds9QAWm0hi7M6wfdmVVL21qqYFj8xGMP-loas-UyKmWJwGfbMSvZp28kdY1qqpSjKoglk_tYNfd4SfJPFz7F89AIYCN4R58tJwEd2VPvyg # Access Token type: Bearer # Access Token expires: 3600 import spotipy from spotipy.oauth2 import SpotifyClientCredentials client_id = 'YOUR_CLIENT_ID' # Spotify에서 받은 클라이언트 ID client_secret = 'YOUR_CLIENT_SECRET' # Spotify에서 받은 클라이언트 Secret credentials = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret) sp = spotipy.Spotify(client_credentials_manager=credentials) track_name = "TRACK_NAME" # 검색할 트랙 이름 results = sp.search(q='track:' + track_name, type='track') # 검색된 트랙의 상세 정보 출력 for idx, track in enumerate(results['tracks']['items']): print(idx, track['name'], '-', track['artists'][0]['name']) # import spotipy # from spotipy.oauth2 import SpotifyOAuth # # # Spotify API 인증 # sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="a15ea42332764b68a95ee5eb4f251269", # client_secret="29d52a9e9af8484da1fea849eb8efcac", # redirect_uri="http://localhost", # scope="user-library-read")) # # # 사용자의 저장된 트랙 가져오기 # results = sp.current_user_saved_tracks() # for idx, item in enumerate(results['items']): # track = item['track'] # print(idx, track['artists'][0]['name'], " – ", track['name']) # import speech_recognition as sr # import time # import re # # def start_timer(minutes): # end_time = time.time() + minutes * 60 # while True: # remaining_time = end_time - time.time() # if remaining_time <= 0: # break # # mins, secs = divmod(remaining_time, 60) # tenths = int((remaining_time - int(remaining_time)) * 10) # timer = f"{int(mins):02d}:{int(secs):02d}.{tenths}" # print(timer, end="\r") # time.sleep(0.1) # 0.1초(십분의 일초) 간격으로 대기 # # print("타이머 종료! ") # # def recognize_speech(): # recognizer = sr.Recognizer() # with sr.Microphone() as source: # print("말을 하세요...") # audio = recognizer.listen(source) # # try: # text = recognizer.recognize_google(audio, language='ko-KR') # print("인식된 텍스트:", text) # return text # except sr.UnknownValueError: # print("음성을 인식할 수 없습니다.") # return None # except sr.RequestError: # print("요청에 실패했습니다; 구글 음성 인식 서비스에 연결할 수 없습니다.") # return None # # # 음성 인식으로 타이머 시간 받기 # speech_text = recognize_speech() # if speech_text: # match = re.search(r'(\d+)분 타이머', speech_text) # if match: # duration = int(match.group(1)) # start_timer(duration) # else: # print("타이머 시간을 인식하지 못했습니다.") # import json # import urllib.request # from datetime import datetime # from bs4 import BeautifulSoup # client_id = "jiKFzOxsmYc1WxD4l85I" # 애플리케이션 클라이언트 아이디값 # client_secret = "yv7nTH6bsq" # 애플리케이션 클라이언트 시크릿값 # # encText = urllib.parse.quote("mbc오늘뉴스") # url = "https://openapi.naver.com/v1/search/news?query=" + encText # JSON 결과 # request = urllib.request.Request(url) # request.add_header("X-Naver-Client-Id",client_id) # request.add_header("X-Naver-Client-Secret",client_secret) # response = urllib.request.urlopen(request) # rescode = response.getcode() # # def remove_html_tags(text): # soup = BeautifulSoup(text, "html.parser") # return soup.get_text() # # def remove_datetime(original_datetime_str): # datetime_object = datetime.strptime(original_datetime_str, '%a, %d %b %Y %H:%M:%S %z') # formatted_datetime_str = datetime_object.strftime('%Y-%m-%d %H:%M') # return formatted_datetime_str # # if(rescode==200): # response_body = response.read() # json_data = json.loads(response_body.decode('utf-8')) # # # JSON 데이터에서 title과 description 추출 및 HTML 태그 제거 # for item in json_data['items']: # title = remove_html_tags(item['title']) # description = remove_html_tags(item['description']) # pubDate = remove_datetime(item['pubDate']) # # print(f"Title: {title}") # print(f"Description: {description}") # print(f"pubDate: {pubDate}") # print("\n") # 각 뉴스 아이템 사이에 빈 줄 추가 # else: # print("Error Code:" + rescode) # import requests # import json # from bs4 import BeautifulSoup # from urllib.parse import quote # # # 네이버 API에 요청할 검색어 # query = quote("mbc주요뉴스") # # # # API 요청 URL # # url = f"https://openapi.naver.com/v1/search/news.json?query={query}&display=10&start=1&sort=sim" # # # # # 클라이언트 아이디와 클라이언트 시크릿 (발급받은 값을 사용하세요) # # client_id = "jiKFzOxsmYc1WxD4l85I" # 애플리케이션 클라이언트 아이디값 # # client_secret = "yv7nTH6bsq" # 애플리케이션 클라이언트 시크릿값 # # # # # 요청 헤더 # # headers = { # # "X-Naver-Client-Id": client_id, # # "X-Naver-Client-Secret": client_secret # # } # # # # # API 요청 및 응답 # # response = requests.get(url, headers=headers) # # # # # 응답 출력 (XML 형식) # # print(response.text) # # data = { # "lastBuildDate":"Thu, 16 Nov 2023 11:15:00 +0900", # "total":16246, # "start":1, # "display":10, # "items":[ # { # "title":"MBC<\/b> 제3노조 "안형준 사장님! MBC<\/b>는 공산당 기관지 아닙니다, 민주당 기관지 ...", # "originallink":"https:\/\/www.dailian.co.kr\/news\/view\/1294904\/?sc=Naver", # "link":"https:\/\/n.news.naver.com\/mnews\/article\/119\/0002768937?sid=102", # "description":"KBS와 SBS 등 다른 언론사들은 주요 뉴스<\/b>로 다룬 사안인데 MBC<\/b>만 무시했다. 안 사장님, 왜 그럴까요? 어제 한국시리즈 중계로 뉴스<\/b>가 14꼭지로 축소돼서 그랬을까요? MBC<\/b>는 그 짧은 뉴스<\/b> 와중에 이종석 헌재소장 후보자... ", # "pubDate":"Tue, 14 Nov 2023 15:22:00 +0900" # }, # { # "title":"광주MBC<\/b> 뉴스<\/b>투데이 2023.11.16", # "originallink":"https:\/\/kjmbc.co.kr\/article\/4KcdyZM_LB46Q3JKDZ", # "link":"https:\/\/kjmbc.co.kr\/article\/4KcdyZM_LB46Q3JKDZ", # "description":"먼저 오늘의 주요뉴스<\/b>입니다.------------2024 대학수학능력시험이 잠시 후 시작합니다. 올해 광주는 1만 6천 명이 전남은 1만 3천여 명이 응시합니다.----------------------광주 민간공항과 군공항의 무안으로 동시이전을 확실히... ", # "pubDate":"Thu, 16 Nov 2023 08:00:00 +0900" # }, # { # "title":"박민 KBS 사장 취임 첫날…주요뉴스<\/b> 앵커 교체", # "originallink":"https:\/\/www.ichannela.com\/news\/main\/news_detailPage.do?publishId=000000377340", # "link":"https:\/\/n.news.naver.com\/mnews\/article\/449\/0000261635?sid=115", # "description":"■ 방송 : 채널A 뉴스<\/b>A 라이브 (12시~13시 20분) ■ 방송일 : 2023년 11월 14일 (화요일) ■ 진행 : 이용환 앵커... 어제 하차 한 날 MBC<\/b> 라디오에 주진우 씨가 출연을 해서는 이렇게 이야기했습니다. KBS 위기 원인은 박민 사장이다.... ", # "pubDate":"Tue, 14 Nov 2023 13:23:00 +0900" # }, # { # "title":"[펜앤인터뷰] "MBC<\/b> 정치,경제,사회분야 기자 62명 가운데 우리 편은 1명도 없...", # "originallink":"http:\/\/www.pennmike.com\/news\/articleView.html?idxno=72754", # "link":"http:\/\/www.pennmike.com\/news\/articleView.html?idxno=72754", # "description":"정치,경제,사회,법조팀은 주요 뉴스<\/b>를 쏟아내는 핵심 부서들이다. 오 위원장에 따르면 MBC<\/b>보도국의 정치팀 기자는 17명,경제팀은 16명,사회팀은 22명,법조팀은 7명이다. 오위원장은 "MBC<\/b>제3노조의 인원 비율로 보자면... ", # "pubDate":"Tue, 14 Nov 2023 10:40:00 +0900" # }, # { # "title":"광주MBC<\/b> 뉴스<\/b>투데이 2023.11.15", # "originallink":"https:\/\/kjmbc.co.kr\/article\/9hWXzrkj2jjNpex", # "link":"https:\/\/kjmbc.co.kr\/article\/9hWXzrkj2jjNpex", # "description":"먼저 오늘의 주요뉴스<\/b>입니다.------------광주시가 빛그린산단 어린이집 내년도 예산을 전액 삭감했다는 광주MBC<\/b> 보도와 관련해 강기정 광주시장이 '사회적 임금' 약속 파기가 아니라며 학부모들도 동의했다고 말했습니다.... ", # "pubDate":"Wed, 15 Nov 2023 08:00:00 +0900" # }, # { # "title":"광주MBC<\/b> 뉴스<\/b>투데이 2023.11.14", # "originallink":"https:\/\/kjmbc.co.kr\/article\/M6op04eluDu2AByX2UuMlf", # "link":"https:\/\/kjmbc.co.kr\/article\/M6op04eluDu2AByX2UuMlf", # "description":"먼저 오늘의 주요뉴스<\/b>입니다.--------------역대 최대 규모로 지원되는 정부의 대학 지원 사업에서 전남대가 탈락하고 순천대는 선정됐습니다.전남대는 글로컬 대학에 예비 지정됐던 국립대학 중 유일하게 최종 관문을... ", # "pubDate":"Tue, 14 Nov 2023 08:00:00 +0900" # }, # { # "title":"광주MBC<\/b> 뉴스<\/b>투데이 2023.11.08", # "originallink":"https:\/\/kjmbc.co.kr\/article\/4lIl0mYlzOzG2F9oSfWX8", # "link":"https:\/\/kjmbc.co.kr\/article\/4lIl0mYlzOzG2F9oSfWX8", # "description":"먼저 오늘의 주요뉴스<\/b>입니다. ----------------- 국민의힘이 김포시 서울편입안이 국가균형발전에 역행한다는 비판을 받자 이걸 광주와 부산에서도 해보자고 제안했습니다 하지만 진정성을 보이려면 서울보다는 지역 먼저... ", # "pubDate":"Wed, 08 Nov 2023 08:00:00 +0900" # }, # { # "title":"광주MBC<\/b> 뉴스<\/b>투데이 2023.11.10", # "originallink":"https:\/\/kjmbc.co.kr\/article\/kfkK4ZtYXzEbdvtnM", # "link":"https:\/\/kjmbc.co.kr\/article\/kfkK4ZtYXzEbdvtnM", # "description":"먼저 오늘의 주요뉴스<\/b>입니다.-------------협력업체에서 일어난 노동자 사망사고로 가동이 전면 중단됐던 기아 오토랜드 광주공장이 사흘 만에 생산을 재개했습니다.----------------광주시가 인상논란이 있었던 도시가스 소매... ", # "pubDate":"Fri, 10 Nov 2023 08:00:00 +0900" # }, # { # "title":"광주MBC<\/b> 뉴스<\/b>투데이 2023.11.07", # "originallink":"https:\/\/kjmbc.co.kr\/article\/2olXvAX4_ZMRHldS_PT-", # "link":"https:\/\/kjmbc.co.kr\/article\/2olXvAX4_ZMRHldS_PT-", # "description":"먼저 오늘의 주요뉴스<\/b>입니다. -------------- 국민의힘이 쏘아올린 김포시 서울 편입을 두고 국가균형발전에 역행하는 것이라는 지역의 반발이 잇따르고 있습니다. ----------------- 지난 봄, 국민의힘이 일제강제동원 시민모임이... ", # "pubDate":"Tue, 07 Nov 2023 08:00:00 +0900" # }, # { # "title":"광주MBC<\/b> 뉴스<\/b>투데이 2023.11.09", # "originallink":"https:\/\/kjmbc.co.kr\/article\/8De3oDZcH4f0xDtYOMOEsR", # "link":"https:\/\/kjmbc.co.kr\/article\/8De3oDZcH4f0xDtYOMOEsR", # "description":"먼저 오늘의 주요뉴스<\/b>입니다.---------------광주 상무역과 나주역을 잇는 광역철도노선변경 여부를 두고 광주시와 전라남도의갈등이 커지고 있습니다. 효천역을 거치도록 노선변경을 하지 않으면차라리 사업을 하지... ", # "pubDate":"Thu, 09 Nov 2023 08:00:00 +0900" # } # ] # } # # # json_data = data # # HTML 태그를 제거하는 함수 # # def remove_html_tags(text): # soup = BeautifulSoup(text, "html.parser") # return soup.get_text() # # # JSON 데이터에서 title과 description 추출 및 HTML 태그 제거 # for item in json_data['items']: # title = remove_html_tags(item['title']) # description = remove_html_tags(item['description']) # # print(f"Title: {title}") # print(f"Description: {description}") # print("\n") # 각 뉴스 아이템 사이에 빈 줄 추가 # import requests # # def get_bitcoin_price(coin): # # CoinGecko API 엔드포인트 URL # api_url = "https://api.coingecko.com/api/v3/simple/price" # # if coin == 'bitcoin': # ids = "bitcoin" # elif coin == 'ethereum': # ids = "ethereum" # # # 파라미터 설정 # params = { # "ids": ids, # "vs_currencies": "krw" # 한국 원 (KRW)으로 변경 # } # # try: # # API 요청 보내기 # response = requests.get(api_url, params=params) # # # 응답 확인 # if response.status_code == 200: # data = response.json() # print(data) # bitcoin_price_krw = int(data[ids]["krw"]) # return bitcoin_price_krw # else: # print("API 요청 실패:", response.status_code) # except Exception as e: # print("오류 발생:", str(e)) # # return None # # # # 비트코인 가격 가져오기 # bitcoin_price_krw = get_bitcoin_price('ethereum') # # if bitcoin_price_krw is not None: # print(f"비트코인 현재 가격 (KRW): ₩{bitcoin_price_krw}") # else: # print("가격을 가져올 수 없습니다.") # from multiprocessing import Process, Event # import time # # # tday_time 함수 (시간을 표시하는 프로세스) # def tday_time(event): # while True: # event.wait() # 이벤트가 설정될 때까지 대기 # i =0 # while event.is_set(): # print("tday_time 작동 중...", i) # time.sleep(1) # 실제 작업을 시뮬레이션 # i+=1 # # # # why 함수 (문자열 "Why?"를 표시하는 프로세스) # def why(event): # while True: # event.wait() # 이벤트가 설정될 때까지 대기 # i = 0 # while event.is_set(): # print("why 작동 중...", i) # time.sleep(1) # 실제 작업을 시뮬레이션 # i += 1 # # # listen_for_command 함수 (음성 명령을 대기하는 프로세스) # def listen_for_command(event_tdaytime, event_why): # # tday_time 시작 # event_tdaytime.set() # time.sleep(3) # tday_time이 일정 시간 동안 작동하도록 함 # # # tday_time 중지 및 why 시작 # event_tdaytime.clear() # 이벤트 해제 # event_why.set() # time.sleep(3) # why가 일정 시간 동안 작동하도록 함 # # # why 중지 및 tday_time 재시작 # event_why.clear() # 이벤트 해제 # event_tdaytime.set() # time.sleep(3) # tday_time이 일정 시간 동안 작동하도록 함 # # # tday_time 중지 및 why 시작 # event_tdaytime.clear() # 이벤트 해제 # event_why.set() # time.sleep(3) # why가 일정 시간 동안 작동하도록 함 # # if __name__ == "__main__": # event_tdaytime = Event() # event_why = Event() # # tday_time_process = Process(target=tday_time, args=(event_tdaytime,)) # why_process = Process(target=why, args=(event_why,)) # command_process = Process(target=listen_for_command, args=(event_tdaytime, event_why)) # # tday_time_process.start() # why_process.start() # command_process.start() # # command_process.join() # tday_time_process.join() # why_process.join() # # from luma.core.interface.serial import spi, noop # from luma.core.render import canvas # from luma.led_matrix.device import max7219 # from luma.core.legacy import text, show_message # from time import sleep # # # MAX7219 디바이스 설정 # serial = spi(port=0, device=0, gpio=noop()) # device = max7219(serial,width=32, height=16,block_orientation=-90, blocks_arranged_in_reverse_order=False) # # from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT # # # 메인 함수 # def why(): # x, y = 0, 0 # direction_x, direction_y = 1, 1 # while True: # with canvas(device) as draw: # text(draw, (x, y), "Why?", fill="white", font=proportional(CP437_FONT)) # # 위치 업데이트 # x += direction_x # y += direction_y # # # 벽에 부딪힐 경우 방향 전환 # if x + 5 >= 18 or x <= -5: # direction_x *= -1 # if y + 11 >= 17 or y <= 0: # direction_y *= -1 # sleep(0.1) # # if __name__ == "__main__": # why() # from luma.core.interface.serial import spi, noop # from luma.core.render import canvas # from luma.led_matrix.device import max7219 # from time import sleep # import random # # # MAX7219 디바이스 설정 # serial = spi(port=0, device=0, gpio=noop()) # device = max7219(serial,width=32, height=16,block_orientation=-90, blocks_arranged_in_reverse_order=False) # # # 눈동자의 위치를 업데이트하는 함수 # def update_eye_position(draw, x, y): # draw.point((x, y), fill="white") # # # 메인 함수 # def main(): # while True: # with canvas(device) as draw: # # 랜덤한 위치에 눈동자를 그립니다 # eye_x = random.randint(1, 31) # eye_y = random.randint(1, 15) # update_eye_position(draw, eye_x, eye_y) # # # 눈동자가 잠시 멈춰있게 하기 # sleep(0.5) # # if __name__ == "__main__": # main()