๋ฐ˜์‘ํ˜•
250x250
Recent Posts
ยซ   2024/12   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Hello creators ๐Ÿ™Œ

[1-6] os ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํ™œ์šฉํ•ด์„œ ํŒŒ์ด์ฌ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ, ์ด๋ฆ„ ๋ฐ”๊พธ๊ธฐ (feat. ์ŠคํŒŒ๋ฅดํƒ€์ฝ”๋”ฉํด๋Ÿฝ ๋ฐ์ดํ„ฐ ๋ถ„์„ ์ˆ˜์—…) ๋ณธ๋ฌธ

[WEB & AI] (feat. ์ทจ์ค€)/Python

[1-6] os ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํ™œ์šฉํ•ด์„œ ํŒŒ์ด์ฌ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ, ์ด๋ฆ„ ๋ฐ”๊พธ๊ธฐ (feat. ์ŠคํŒŒ๋ฅดํƒ€์ฝ”๋”ฉํด๋Ÿฝ ๋ฐ์ดํ„ฐ ๋ถ„์„ ์ˆ˜์—…)

๋ถ€์‹œ๋งค๋‚˜_HA 2022. 12. 10. 15:18
728x90
๋ฐ˜์‘ํ˜•

 

Colab URL ์ฃผ์†Œ

 

Colab URL https://bit.ly/3Ph9e9p

 

 


 

 ๋‰ด์Šค๋กœ ๋ฐ›๊ณ  ์‹ถ์€ ๊ธฐ์—…๋“ค์„ ๋ฆฌ์ŠคํŠธ์—…ํ•ด์„œ > news ํด๋”์—, ์—‘์…€ ํŒŒ์ผ๋กœ ํ•˜๋‚˜ ํ•˜๋‚˜ ๋„ฃ์–ด์ฃผ๊ธฐ 

# ๋‰ด์Šค๋กœ ๋ฐ›๊ณ  ์‹ถ์€ ๊ธฐ์—…๋“ค์„ ๋ฆฌ์ŠคํŠธ์—…ํ•ด์„œ, > news ํด๋”์—, ์—‘์…€ ํŒŒ์ผ๋กœ ํ•˜๋‚˜ ํ•˜๋‚˜ ๋„ฃ์–ด์ฃผ๊ธฐ 

keywords = ['์‚ผ์„ฑ์ „์ž','LG์—๋„ˆ์ง€์†”๋ฃจ์…˜','SKํ•˜์ด๋‹‰์Šค','NAVER','์‚ผ์„ฑ๋ฐ”์ด์˜ค๋กœ์ง์Šค','์‚ผ์„ฑ์ „์ž์šฐ','์นด์นด์˜ค','์‚ผ์„ฑSDI','ํ˜„๋Œ€์ฐจ','LGํ™”ํ•™','๊ธฐ์•„','POSCOํ™€๋”ฉ์Šค','KB๊ธˆ์œต','์นด์นด์˜ค๋ฑ…ํฌ','์…€ํŠธ๋ฆฌ์˜จ','์‹ ํ•œ์ง€์ฃผ','์‚ผ์„ฑ๋ฌผ์‚ฐ','ํ˜„๋Œ€๋ชจ๋น„์Šค','SK์ด๋…ธ๋ฒ ์ด์…˜','LG์ „์ž','์นด์นด์˜คํŽ˜์ด','SK','ํ•œ๊ตญ์ „๋ ฅ','ํฌ๋ž˜ํ”„ํ†ค','ํ•˜๋‚˜๊ธˆ์œต์ง€์ฃผ','LG์ƒํ™œ๊ฑด๊ฐ•','HMM','์‚ผ์„ฑ์ƒ๋ช…','ํ•˜์ด๋ธŒ','๋‘์‚ฐ์ค‘๊ณต์—…','SKํ…”๋ ˆ์ฝค','์‚ผ์„ฑ์ „๊ธฐ','SK๋ฐ”์ด์˜ค์‚ฌ์ด์–ธ์Šค','LG','S-Oil','๊ณ ๋ ค์•„์—ฐ','KT&G','์šฐ๋ฆฌ๊ธˆ์œต์ง€์ฃผ','๋Œ€ํ•œํ•ญ๊ณต','์‚ผ์„ฑ์—์Šค๋””์—์Šค','ํ˜„๋Œ€์ค‘๊ณต์—…','์—”์”จ์†Œํ”„ํŠธ','์‚ผ์„ฑํ™”์žฌ','์•„๋ชจ๋ ˆํผ์‹œํ”ฝ','KT','ํฌ์Šค์ฝ”์ผ€๋ฏธ์นผ','๋„ท๋งˆ๋ธ”','SK์•„์ด์ดํ…Œํฌ๋†€๋กœ์ง€','LG์ด๋…ธํ…','๊ธฐ์—…์€ํ–‰']
    # ํ•จ์ˆ˜๋ฅผ ๋Œ๋ฆฌ๊ณ  ์‹ถ์€ ๊ธฐ์—…๋“ค (๊ฒ€์ƒ‰ํ•ด์„œ, ๋‰ด์Šค๋กœ ๋ฝ‘๊ณ  ์‹ถ์€ ๊ฒƒ๋“ค) ์„ ๋„ฃ์Œ 

for keyword in keywords:    # ์œ„์— ๋ฉ์–ด๋ฆฌ์—์„œ ํ•˜๋‚˜์”ฉ ๊บผ๋‚ด์™€์„œ ๋‹ด์Œ
  print(keyword)    # ์ง€๊ธˆ ์–ด๋””๊นŒ์ง€ ํ•˜๊ณ  ์žˆ๋Š”์ง€, '์ง„์ฒ™๋„' ๋ฅผ ํŒŒ์•…ํ•˜๊ธฐ ์œ„ํ•ด์„œ 
  get_news(keyword)   # ์ด๊ฑธ ํ•จ์ˆ˜์— ๋„ฃ์Œ > ๊ทธ ๊ฒฐ๊ณผ, '๋‚ ์งœ_ ์—‘์…€ ํŒŒ์ผ' ์ด๋ฆ„์ด ๋‹ด๊น€

 

 

ํด๋”๋ฅผ '์••์ถ•ํ•ด์„œ' ๋‹ค์šด ๋ฐ›๊ธฐ 

# ํด๋”๋ฅผ '์••์ถ•ํ•ด์„œ' ๋‹ค์šด ๋ฐ›๊ธฐ 

keywords = ['์‚ผ์„ฑ์ „์ž','LG์—๋„ˆ์ง€์†”๋ฃจ์…˜','SKํ•˜์ด๋‹‰์Šค','NAVER','์‚ผ์„ฑ๋ฐ”์ด์˜ค๋กœ์ง์Šค','์‚ผ์„ฑ์ „์ž์šฐ','์นด์นด์˜ค','์‚ผ์„ฑSDI','ํ˜„๋Œ€์ฐจ','LGํ™”ํ•™','๊ธฐ์•„','POSCOํ™€๋”ฉ์Šค','KB๊ธˆ์œต','์นด์นด์˜ค๋ฑ…ํฌ','์…€ํŠธ๋ฆฌ์˜จ','์‹ ํ•œ์ง€์ฃผ','์‚ผ์„ฑ๋ฌผ์‚ฐ','ํ˜„๋Œ€๋ชจ๋น„์Šค','SK์ด๋…ธ๋ฒ ์ด์…˜','LG์ „์ž','์นด์นด์˜คํŽ˜์ด','SK','ํ•œ๊ตญ์ „๋ ฅ','ํฌ๋ž˜ํ”„ํ†ค','ํ•˜๋‚˜๊ธˆ์œต์ง€์ฃผ','LG์ƒํ™œ๊ฑด๊ฐ•','HMM','์‚ผ์„ฑ์ƒ๋ช…','ํ•˜์ด๋ธŒ','๋‘์‚ฐ์ค‘๊ณต์—…','SKํ…”๋ ˆ์ฝค','์‚ผ์„ฑ์ „๊ธฐ','SK๋ฐ”์ด์˜ค์‚ฌ์ด์–ธ์Šค','LG','S-Oil','๊ณ ๋ ค์•„์—ฐ','KT&G','์šฐ๋ฆฌ๊ธˆ์œต์ง€์ฃผ','๋Œ€ํ•œํ•ญ๊ณต','์‚ผ์„ฑ์—์Šค๋””์—์Šค','ํ˜„๋Œ€์ค‘๊ณต์—…','์—”์”จ์†Œํ”„ํŠธ','์‚ผ์„ฑํ™”์žฌ','์•„๋ชจ๋ ˆํผ์‹œํ”ฝ','KT','ํฌ์Šค์ฝ”์ผ€๋ฏธ์นผ','๋„ท๋งˆ๋ธ”','SK์•„์ด์ดํ…Œํฌ๋†€๋กœ์ง€','LG์ด๋…ธํ…','๊ธฐ์—…์€ํ–‰']
    # ํ•จ์ˆ˜๋ฅผ ๋Œ๋ฆฌ๊ณ  ์‹ถ์€ ๊ธฐ์—…๋“ค (๊ฒ€์ƒ‰ํ•ด์„œ, ๋‰ด์Šค๋กœ ๋ฝ‘๊ณ  ์‹ถ์€ ๊ฒƒ๋“ค) ์„ ๋„ฃ์Œ 

for keyword in keywords:    # ์œ„์— ๋ฉ์–ด๋ฆฌ์—์„œ ํ•˜๋‚˜์”ฉ ๊บผ๋‚ด์™€์„œ ๋‹ด์Œ
  # print(keyword)    # ์ง€๊ธˆ ์–ด๋””๊นŒ์ง€ ํ•˜๊ณ  ์žˆ๋Š”์ง€, '์ง„์ฒ™๋„' ๋ฅผ ํŒŒ์•…ํ•˜๊ธฐ ์œ„ํ•ด์„œ 
  get_news(keyword)   # ์ด๊ฑธ ํ•จ์ˆ˜์— ๋„ฃ์Œ > ๊ทธ ๊ฒฐ๊ณผ, '๋‚ ์งœ_ ์—‘์…€ ํŒŒ์ผ' ์ด๋ฆ„์ด ๋‹ด๊น€

!zip -r /content/files.zip /content/news    # โœ… ์••์ถ•ํ•ด์ฃผ๋Š” ์ฝ”๋“œ 
                                              # '/content/news' ์— ์žˆ๋Š” ํŒŒ์ผ์„ ๋ฌถ์–ด์„œ > /content/files.zip ํŒŒ์ผ๋กœ ๋งŒ๋“ค์–ด์ค˜

 

 

'2022_12_09_์‚ผ์„ฑ์ „์ž.xlsx' ๋ฅผ ๐Ÿ‘‰ '2022_12_09_์‚ผ์„ฑ์ „์ž(๋‰ด์Šค).xlsx' ๋กœ ๋ฐ”๊พธ๊ธฐ_part1

# '2022_12_09_์‚ผ์„ฑ์ „์ž.xlsx' ๋ฅผ ๐Ÿ‘‰ '2022_12_09_์‚ผ์„ฑ์ „์ž(๋‰ด์Šค).xlsx' ๋กœ ๋ฐ”๊พธ๊ธฐ_part1

# cf. ์ด๋ ‡๊ฒŒ ๋˜๋Š”์ง€ ํ…Œ์ŠคํŠธ ํ•ด๋ณด๊ธฐ! 
name = '2022_12_09_์‚ผ์„ฑ์ „์ž.xlsx'
name.split('.')[0]+'(๋‰ด์Šค).xlsx'

 

 

 

'2022_12_09_์‚ผ์„ฑ์ „์ž.xlsx' ๋ฅผ ๐Ÿ‘‰ '2022_12_09_์‚ผ์„ฑ์ „์ž(๋‰ด์Šค).xlsx' ๋กœ ๋ฐ”๊พธ๊ธฐ_part2

# '2022_12_09_์‚ผ์„ฑ์ „์ž.xlsx' ๋ฅผ ๐Ÿ‘‰ '2022_12_09_์‚ผ์„ฑ์ „์ž(๋‰ด์Šค).xlsx' ๋กœ ๋ฐ”๊พธ๊ธฐ_part2

import os   # os ๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ธ๊ฐ€?โ“โ“ 

path = '/content/news'    # ๋‰ด์Šค๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š” ํด๋”์˜ ๊ฒฝ๋กœ
files = os.listdir(path)    # os ๋กœ ๋“ค์–ด๊ฐ€์„œ ๋ญ”๊ฐ€๋ฅผ ํ• ๊ฑฐ์•ผ > ๋””ํ…ํ† ๋ฆฌ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ณผ๊ฑฐ์•ผ, ์–ด๋””๊ฑธ? path ๊ฒฝ๋กœ์— ์žˆ๋Š”๊ฑธ > ๊ทธ ๋””๋ ‰ํ† ๋ฆฌ ๋ฆฌ์ŠคํŠธ๋ฅผ files ์— ๋‹ด์•„ / ๐Ÿ“›๐Ÿ“› / 
                              # ์ด ์ˆœ๊ฐ„, 'path ์•ˆ์— ์žˆ๋Š” ํŒŒ์ผ๋“ค'์ด files ์— ๋“ค์–ด๊ฐ„๋‹ค.

for name in files:    # 'path ์•ˆ์— ์žˆ๋Š” ํŒŒ์ผ๋“ค' ์„ ํ•˜๋‚˜์”ฉ ๊บผ๋‚ด์„œ > name ์— ๋‹ด๋Š”๋‹ค.
  new_name = name.split('.')[0]+'(๋‰ด์Šค).xlsx'   # ํŒŒ์ผ ์ด๋ฆ„ ํ•˜๋‚˜๋ฅผ . ์œผ๋กœ ์ชผ๊ฐœ๊ณ  > (๋‰ด์Šค) ๋ฅผ ๋”ํ•œ๋‹ค.
  os.rename(f'/content/news/{name}', f'/content/news/{new_name}')   
      # ์›๋ž˜ ์ด๋ฆ„์„ ๋„ฃ๊ณ  > ๋ฐ”๊ฟ€ ์ด๋ฆ„์„ ๋„ฃ์–ด์ฃผ๋ฉด > ํ•ด๋‹น ํŒŒ์ผ ์ด๋ฆ„์„ ๋ฐ”๊ฟ”์ค€๋‹ค. โœ… โญโญ
        # ์›๋ž˜ full ์ด๋ฆ„์€ '/content/news/'2022_12_09_์‚ผ์„ฑ์ „์ž.xlsx' ์ด๊ฑฐ์ž„ ๐Ÿ‘‰ ์•ž์— ๊ฒฝ๋กœ๊นŒ์ง€ ์จ์ฃผ๋Š” ์ด์œ ๋Š”? ๐Ÿ‘‰ ํƒ€๊ณ  ํƒ€๊ณ  ๋“ค์–ด๊ฐ€์„œ ๋ฐ”๊พธ๋ผ๋Š” ์˜๋ฏธโ“

๋ฐ˜์‘ํ˜•

 

 


ํ•™์Šต ๋ฆฌ์†Œ์Šค

๊ฐ•์˜ URL https://bit.ly/3W2CYsK
Colab URL https://bit.ly/3Ph9e9p

 

์ด์ „ ํŒŒ์ด์ฌ ์ˆ˜์—… ๋…ธํŠธ

๐Ÿ’ญ 2022.12.10 - [[AI]/Python] - [1-5] openpyxl, Workbook ํ™œ์šฉํ•ด์„œ ํŒŒ์ด์ฌ์œผ๋กœ ์—‘์…€ ๋‹ค๋ฃจ๊ธฐ (feat. ์ŠคํŒŒ๋ฅดํƒ€ ์ฝ”๋”ฉํด๋Ÿฝ ๋ฐ์ดํ„ฐ ๋ถ„์„ ์ˆ˜์—…)

๐Ÿ’ญ 2022.12.08 - [[AI]/Python] - [1-4] ๋‰ด์Šค ๊ธฐ์‚ฌ ์ œ๋ชฉ ๊ฐ€์ ธ์˜ค๊ธฐ [python beautifulsoup request ํ™œ์šฉ crwaling] (Feat. ์ŠคํŒŒ๋ฅดํƒ€ ์ฝ”๋”ฉํด๋Ÿฝ_๋ฐ์ดํ„ฐ๋ถ„์„ ์ˆ˜์—…)

728x90
๋ฐ˜์‘ํ˜•

'[WEB & AI] (feat. ์ทจ์ค€) > Python' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[2-1&2] Pandas ๊ธฐ์ดˆ (feat. ์ŠคํŒŒ๋ฅดํƒ€์ฝ”๋”ฉํด๋Ÿฝ_๋ฐ์ดํ„ฐ๋ถ„์„์ˆ˜์—…)  (0) 2022.12.13
[1-8] ํŒŒ์ด์ฌ์œผ๋กœ 50๊ฐœ ๊ธฐ์—… 3๋…„์น˜ ์ฃผ์‹ ๊ทธ๋ž˜ํ”„ ํ•œ๋ฒˆ์— ๋ฐ›์•„๋ณด๊ธฐ (feat. ์ŠคํŒŒ๋ฅดํƒ€์ฝ”๋”ฉํด๋Ÿฝ_๋ฐ์ดํ„ฐ๋ถ„์„์ˆ˜์—…)  (2) 2022.12.10
[1-7] urllib.request ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉํ•ด์„œ ์ด๋ฏธ์ง€ ๋‹ค์šด ๋ฐ›๊ธฐ (feat. ์ŠคํŒŒ๋ฅดํƒ€ ์ฝ”๋”ฉํด๋Ÿฝ ๋ฐ์ดํ„ฐ ๋ถ„์„ ์ˆ˜์—…)  (0) 2022.12.10
[1-5] openpyxl, Workbook ํ™œ์šฉํ•ด์„œ ํŒŒ์ด์ฌ์œผ๋กœ ์—‘์…€ ๋‹ค๋ฃจ๊ธฐ (feat. ์ŠคํŒŒ๋ฅดํƒ€ ์ฝ”๋”ฉํด๋Ÿฝ ๋ฐ์ดํ„ฐ ๋ถ„์„ ์ˆ˜์—…)  (0) 2022.12.10
[1-4] ๋‰ด์Šค ๊ธฐ์‚ฌ ์ œ๋ชฉ ๊ฐ€์ ธ์˜ค๊ธฐ [python beautifulsoup request ํ™œ์šฉ crwaling] (Feat. ์ŠคํŒŒ๋ฅดํƒ€ ์ฝ”๋”ฉํด๋Ÿฝ_๋ฐ์ดํ„ฐ๋ถ„์„ ์ˆ˜์—…)  (0) 2022.12.08
Comments