ckfrpark commited on
Commit
2ebcd0a
โ€ข
1 Parent(s): d59f33a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -14
app.py CHANGED
@@ -1,28 +1,25 @@
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}")
 
1
  import requests
2
 
3
+ # Pexels API ํ‚ค ์„ค์ •
4
+ API_KEY = 'XDDeRl6U3IY8VRzv7YBGRrnGuOwqpOYD2yS9VTAYM7VEfZcr1aWXubZ1'
5
  API_ENDPOINT = 'https://api.pexels.com/v1/search'
6
 
7
+ def fetch_high_quality_images(keyword, per_page=80):
8
  headers = {
9
  'Authorization': API_KEY
10
  }
11
  params = {
12
  'query': keyword,
13
+ 'per_page': per_page,
14
+ 'size': 'large'
15
  }
16
  response = requests.get(API_ENDPOINT, headers=headers, params=params)
17
  if response.status_code == 200:
18
  data = response.json()
19
+ images = data['photos']
20
+ for image in images:
21
+ print(image['src']['original'])
 
 
22
 
23
+ if __name__ == '__main__':
24
+ keyword = input("Enter keyword: ")
25
+ fetch_high_quality_images(keyword)