ckfrpark commited on
Commit
e128525
ยท
verified ยท
1 Parent(s): b5afc3b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ # Pexels API ์„ค์ •
4
+ API_KEY = '์—ฌ๊ธฐ์—_๋‹น์‹ ์˜_API_ํ‚ค๋ฅผ_์ž…๋ ฅํ•˜์„ธ์š”'
5
+ API_ENDPOINT = 'https://api.pexels.com/v1/search'
6
+
7
+ def fetch_images(keyword, total_images=80):
8
+ headers = {
9
+ 'Authorization': API_KEY
10
+ }
11
+ params = {
12
+ 'query': keyword,
13
+ 'per_page': total_images
14
+ }
15
+ response = requests.get(API_ENDPOINT, headers=headers, params=params)
16
+ if response.status_code == 200:
17
+ data = response.json()
18
+ images = [photo['src']['original'] for photo in data['photos']]
19
+ return images
20
+ else:
21
+ print("Error:", response.status_code)
22
+ return []
23
+
24
+ if __name__ == "__main__":
25
+ keyword = input("๊ฒ€์ƒ‰ํ•  ํ‚ค์›Œ๋“œ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”: ")
26
+ images = fetch_images(keyword)
27
+ for i, image in enumerate(images, start=1):
28
+ print(f"{i}: {image}")