์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐Ÿค– ํŒŒ์ด์ฌ์œผ๋กœ ํŠธ์œ„ํ„ฐ ์ž๋™ ์š”์•ฝ๋ด‡ ๊ฐœ๋ฐœํ•˜๊ธฐ: AI ๊ธฐ์ˆ ๋กœ ์ •๋ณด์˜ ํ™์ˆ˜๋ฅผ ์ •๋ณตํ•˜๋Š” ๋ฒ•

๐Ÿค– ํŒŒ์ด์ฌ์œผ๋กœ ํŠธ์œ„ํ„ฐ ์ž๋™ ์š”์•ฝ๋ด‡ ๊ฐœ๋ฐœํ•˜๊ธฐ: AI ๊ธฐ์ˆ ๋กœ ์ •๋ณด์˜ ํ™์ˆ˜๋ฅผ ์ •๋ณตํ•˜๋Š” ๋ฒ•

SNS ์‹œ๋Œ€, ์Ÿ์•„์ง€๋Š” ํŠธ์œ—์„ AI๋กœ ๋˜‘๋˜‘ํ•˜๊ฒŒ ์š”์•ฝํ•ด๋ณด์ž ใ…‹ใ…‹ใ…‹

๐Ÿ’ก ์š”์ฆ˜ ํŠธ์œ„ํ„ฐ(ํ˜„ X) ํƒ€์ž„๋ผ์ธ ๋ณด๋ฉด ์ง„์งœ ์ •๋ณด๊ฐ€ ๋ฏธ์นœ๋“ฏ์ด ์Ÿ์•„์ง€์ž–์•„์š”? ํ•˜๋ฃจ์— ์ˆ˜๋ฐฑ ๊ฐœ์”ฉ ์˜ฌ๋ผ์˜ค๋Š” ํŠธ์œ—๋“ค ์ค‘์—์„œ ํ•ต์‹ฌ๋งŒ ์™์™ ๋ฝ‘์•„๋‚ด๊ณ  ์‹ถ์€๋ฐ, ์ผ์ผ์ด ๋‹ค ์ฝ๊ธฐ์—” ์‹œ๊ฐ„๋„ ์—†๊ณ ... ๊ทธ๋ž˜์„œ ์˜ค๋Š˜์€ ํŒŒ์ด์ฌ๊ณผ AI ๊ธฐ์ˆ ์„ ํ™œ์šฉํ•ด์„œ ํŠธ์œ„ํ„ฐ ์ž๋™ ์š”์•ฝ๋ด‡์„ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ๋ ค๋“œ๋ฆด๊ฒŒ์š” ใ…Žใ…Ž

์ด ๊ธ€์—์„œ๋Š” ์‹ค์ œ๋กœ ์ž‘๋™ํ•˜๋Š” ๋ด‡์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ ์ „์ฒด ํ”„๋กœ์„ธ์Šค๋ฅผ ๋‹ค๋ฃฐ ๊ฑฐ์˜ˆ์š”. API ์—ฐ๋™๋ถ€ํ„ฐ ์ž์—ฐ์–ด ์ฒ˜๋ฆฌ, ๋จธ์‹ ๋Ÿฌ๋‹ ๋ชจ๋ธ ์ ์šฉ๊นŒ์ง€! ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ดˆ๋ณด์ž๋„ ๋”ฐ๋ผํ•  ์ˆ˜ ์žˆ๊ฒŒ ์ตœ๋Œ€ํ•œ ์‰ฝ๊ฒŒ ์„ค๋ช…ํ•  ํ…Œ๋‹ˆ๊นŒ ๊ฑฑ์ • ๋…ธ๋…ธ~ ๐Ÿš€

๐Ÿฆ ํŠธ์œ— ์ˆ˜์ง‘ API ์—ฐ๋™ AI ๋ถ„์„ ์ž์—ฐ์–ด์ฒ˜๋ฆฌ ์š”์•ฝ ์ƒ์„ฑ ๊ฒฐ๊ณผ ์ถœ๋ ฅ ๐Ÿ“Š ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ ๐Ÿง  ๋จธ์‹ ๋Ÿฌ๋‹ ๋ชจ๋ธ โšก ์ž๋™ํ™” ์Šค์ผ€์ค„๋ง ๐Ÿ’ฌ ๊ฒฐ๊ณผ ๊ณต์œ 

๐ŸŽฏ ์™œ ํŠธ์œ„ํ„ฐ ์ž๋™ ์š”์•ฝ๋ด‡์ด ํ•„์š”ํ• ๊นŒ?

์†”์งํžˆ ๋งํ•ด์„œ ์š”์ฆ˜ SNS๋Š” ์ •๋ณด ๊ณผ๋ถ€ํ•˜ ๊ทธ ์ž์ฒด์ž–์•„์š” ใ…‹ใ…‹ใ…‹ ํŠนํžˆ ํŠธ์œ„ํ„ฐ๋Š” ์‹ค์‹œ๊ฐ„์œผ๋กœ ์—„์ฒญ๋‚œ ์–‘์˜ ์ •๋ณด๊ฐ€ ์Ÿ์•„์ง€๋Š”๋ฐ, ์ด๊ฑธ ๋‹ค ์ฝ์œผ๋ ค๋ฉด ํ•˜๋ฃจ 24์‹œ๊ฐ„๋„ ๋ชจ์ž๋ผ์š”. ๊ทธ๋ž˜์„œ ๋งŽ์€ ๊ธฐ์—…๋“ค๊ณผ ๊ฐœ์ธ ๊ฐœ๋ฐœ์ž๋“ค์ด ์ž๋™ ์š”์•ฝ ์‹œ์Šคํ…œ์— ์ฃผ๋ชฉํ•˜๊ณ  ์žˆ์–ด์š”.

์‹ค์ œ๋กœ ๋‰ด์Šค ๊ธฐ๊ด€, ๋งˆ์ผ€ํŒ… ํšŒ์‚ฌ, ๋ฆฌ์„œ์น˜ ๊ธฐ๊ด€๋“ค์€ ํŠธ์œ„ํ„ฐ์—์„œ ํŠธ๋ Œ๋“œ๋ฅผ ํŒŒ์•…ํ•˜๊ณ  ์—ฌ๋ก ์„ ๋ถ„์„ํ•˜๋Š”๋ฐ ์ด๋Ÿฐ ๋ด‡๋“ค์„ ํ™œ์šฉํ•˜๊ณ  ์žˆ๊ฑฐ๋“ ์š”. ๊ฐœ์ธ์ ์œผ๋กœ๋„ ๊ด€์‹ฌ ๋ถ„์•ผ์˜ ํ•ต์‹ฌ ์ •๋ณด๋งŒ ๋น ๋ฅด๊ฒŒ ์บ์น˜ํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ๊นŒ ์™„์ „ ์œ ์šฉํ•˜์ฃ  ๐Ÿ‘

๐Ÿ“Œ ์ž๋™ ์š”์•ฝ๋ด‡์˜ ์ฃผ์š” ํ™œ์šฉ ์‚ฌ๋ก€

1. ๋‰ด์Šค ๋ชจ๋‹ˆํ„ฐ๋ง: ํŠน์ • ํ‚ค์›Œ๋“œ๋‚˜ ํ•ด์‹œํƒœ๊ทธ ๊ด€๋ จ ํŠธ์œ—์„ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ˆ˜์ง‘ํ•˜๊ณ  ์š”์•ฝ
2. ๋ธŒ๋žœ๋“œ ๋ชจ๋‹ˆํ„ฐ๋ง: ์ž์‚ฌ ์ œํ’ˆ์ด๋‚˜ ์„œ๋น„์Šค์— ๋Œ€ํ•œ ์†Œ๋น„์ž ๋ฐ˜์‘ ๋ถ„์„
3. ํŠธ๋ Œ๋“œ ๋ถ„์„: ์‹ค์‹œ๊ฐ„ ์ด์Šˆ์™€ ์—ฌ๋ก ์˜ ํ๋ฆ„ ํŒŒ์•…
4. ๊ฒฝ์Ÿ์‚ฌ ๋ถ„์„: ๊ฒฝ์Ÿ ์—…์ฒด์˜ ๋งˆ์ผ€ํŒ… ํ™œ๋™๊ณผ ๊ณ ๊ฐ ๋ฐ˜์‘ ์ถ”์ 
5. ๊ฐœ์ธ ํ๋ ˆ์ด์…˜: ๊ด€์‹ฌ ๋ถ„์•ผ์˜ ํ•ต์‹ฌ ์ •๋ณด๋งŒ ๊ณจ๋ผ์„œ ๋ฐ›์•„๋ณด๊ธฐ

๐Ÿ› ๏ธ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์ค€๋น„ํ•˜๊ธฐ

๋ณธ๊ฒฉ์ ์œผ๋กœ ์ฝ”๋”ฉ์— ๋“ค์–ด๊ฐ€๊ธฐ ์ „์— ํ•„์š”ํ•œ ๋„๊ตฌ๋“ค์„ ๋จผ์ € ์„ธํŒ…ํ•ด์•ผ๊ฒ ์ฃ ? ์ƒ๊ฐ๋ณด๋‹ค ๊ฐ„๋‹จํ•ด์š” ใ…Žใ…Ž

1๏ธโƒฃ ํŒŒ์ด์ฌ ์„ค์น˜

ํŒŒ์ด์ฌ 3.8 ์ด์ƒ ๋ฒ„์ „์„ ๊ถŒ์žฅํ•ด์š”. ๊ณต์‹ ํ™ˆํŽ˜์ด์ง€(python.org)์—์„œ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์œผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ด๋ฏธ ์„ค์น˜๋˜์–ด ์žˆ๋‹ค๋ฉด ํ„ฐ๋ฏธ๋„์—์„œ python --version ๋ช…๋ น์–ด๋กœ ๋ฒ„์ „ ํ™•์ธํ•ด๋ณด์„ธ์š”!

2๏ธโƒฃ ํ•„์ˆ˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ํ•„์š”ํ•œ ํŒจํ‚ค์ง€๋“ค์„ ํ•œ ๋ฒˆ์— ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์–ด์š”:

pip install tweepy
pip install transformers
pip install torch
pip install nltk
pip install pandas
pip install python-dotenv
pip install schedule

๐Ÿ’ก ๊ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์—ญํ• : โ€ข tweepy: ํŠธ์œ„ํ„ฐ API์™€ ํ†ต์‹ ํ•˜๊ธฐ ์œ„ํ•œ ํŒŒ์ด์ฌ ๋ž˜ํผ
โ€ข transformers: Hugging Face์˜ ์‚ฌ์ „ ํ•™์Šต๋œ NLP ๋ชจ๋ธ ์‚ฌ์šฉ
โ€ข torch: ๋”ฅ๋Ÿฌ๋‹ ํ”„๋ ˆ์ž„์›Œํฌ (transformers์˜ ๋ฐฑ์—”๋“œ)
โ€ข nltk: ์ž์—ฐ์–ด ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ๊ธฐ๋ณธ ๋„๊ตฌ
โ€ข pandas: ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ๋ฐ ๋ถ„์„
โ€ข python-dotenv: ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๊ด€๋ฆฌ
โ€ข schedule: ์ž๋™ํ™” ์Šค์ผ€์ค„๋ง

3๏ธโƒฃ ํŠธ์œ„ํ„ฐ API ํ‚ค ๋ฐœ๊ธ‰๋ฐ›๊ธฐ

ํŠธ์œ„ํ„ฐ ๊ฐœ๋ฐœ์ž ํฌํ„ธ(developer.twitter.com)์— ์ ‘์†ํ•ด์„œ ์•ฑ์„ ๋“ฑ๋กํ•˜๊ณ  API ํ‚ค๋ฅผ ๋ฐœ๊ธ‰๋ฐ›์•„์•ผ ํ•ด์š”. ์š”์ฆ˜์€ ์œ ๋ฃŒ ํ”Œ๋žœ๋„ ์žˆ์ง€๋งŒ, ๊ธฐ๋ณธ์ ์ธ ํ…Œ์ŠคํŠธ์šฉ์œผ๋กœ๋Š” ๋ฌด๋ฃŒ ํ‹ฐ์–ด๋กœ๋„ ์ถฉ๋ถ„ํ•ฉ๋‹ˆ๋‹ค ใ…‹ใ…‹

๋ฐœ๊ธ‰๋ฐ›์•„์•ผ ํ•  ํ‚ค ์ •๋ณด๋“ค:
โ€ข API Key (Consumer Key)
โ€ข API Secret Key (Consumer Secret)
โ€ข Access Token
โ€ข Access Token Secret
โ€ข Bearer Token (API v2 ์‚ฌ์šฉ ์‹œ)

๐Ÿ” API ์ธ์ฆ ์„ค์ •ํ•˜๊ธฐ

API ํ‚ค๋ฅผ ์•ˆ์ „ํ•˜๊ฒŒ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒŒ ์ง„์งœ ์ค‘์š”ํ•ด์š”! ์ ˆ๋Œ€๋กœ ์ฝ”๋“œ์— ์ง์ ‘ ํ•˜๋“œ์ฝ”๋”ฉํ•˜๋ฉด ์•ˆ ๋ฉ๋‹ˆ๋‹ค. ๊นƒํ—ˆ๋ธŒ์— ์˜ฌ๋ ธ๋‹ค๊ฐ€ ํ‚ค ํ„ธ๋ฆฌ๋ฉด ์ง„์งœ ๋‚œ๋ฆฌ๋‚˜๊ฑฐ๋“ ์š” ใ… ใ… 

๐Ÿ“ .env ํŒŒ์ผ ์ƒ์„ฑ

ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ์— .env ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  ์•„๋ž˜์ฒ˜๋Ÿผ ์ž‘์„ฑํ•˜์„ธ์š”:

TWITTER_API_KEY=your_api_key_here
TWITTER_API_SECRET=your_api_secret_here
TWITTER_ACCESS_TOKEN=your_access_token_here
TWITTER_ACCESS_SECRET=your_access_secret_here
TWITTER_BEARER_TOKEN=your_bearer_token_here

๊ทธ๋ฆฌ๊ณ  ํŒŒ์ด์ฌ ์ฝ”๋“œ์—์„œ๋Š” ์ด๋ ‡๊ฒŒ ๋ถˆ๋Ÿฌ์™€์š”:

import os
from dotenv import load_dotenv
import tweepy

# ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๋กœ๋“œ
load_dotenv()

# API ์ธ์ฆ ์„ค์ •
api_key = os.getenv('TWITTER_API_KEY')
api_secret = os.getenv('TWITTER_API_SECRET')
access_token = os.getenv('TWITTER_ACCESS_TOKEN')
access_secret = os.getenv('TWITTER_ACCESS_SECRET')
bearer_token = os.getenv('TWITTER_BEARER_TOKEN')

# Tweepy ํด๋ผ์ด์–ธํŠธ ์ƒ์„ฑ (API v2)
client = tweepy.Client(
    bearer_token=bearer_token,
    consumer_key=api_key,
    consumer_secret=api_secret,
    access_token=access_token,
    access_token_secret=access_secret
)

print("ํŠธ์œ„ํ„ฐ API ์—ฐ๊ฒฐ ์„ฑ๊ณต! โœ…")

โš ๏ธ ๋ณด์•ˆ ์ฃผ์˜์‚ฌํ•ญ: โ€ข .env ํŒŒ์ผ์€ ๋ฐ˜๋“œ์‹œ .gitignore์— ์ถ”๊ฐ€ํ•˜์„ธ์š”
โ€ข API ํ‚ค๋Š” ์ ˆ๋Œ€ ๊ณต๊ฐœ ์ €์žฅ์†Œ์— ์—…๋กœ๋“œํ•˜์ง€ ๋งˆ์„ธ์š”
โ€ข ์ •๊ธฐ์ ์œผ๋กœ ํ‚ค๋ฅผ ์žฌ๋ฐœ๊ธ‰ํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์€ ์Šต๊ด€์ž…๋‹ˆ๋‹ค

๐Ÿฆ ํŠธ์œ— ๋ฐ์ดํ„ฐ ์ˆ˜์ง‘ํ•˜๊ธฐ

์ด์ œ ๋ณธ๊ฒฉ์ ์œผ๋กœ ํŠธ์œ—์„ ๊ฐ€์ ธ์™€๋ณผ๊นŒ์š”? Tweepy๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ƒ๊ฐ๋ณด๋‹ค ๊ฐ„๋‹จํ•ด์š” ใ…‹ใ…‹

๐Ÿ” ํ‚ค์›Œ๋“œ ๊ธฐ๋ฐ˜ ํŠธ์œ— ๊ฒ€์ƒ‰

ํŠน์ • ํ‚ค์›Œ๋“œ๋‚˜ ํ•ด์‹œํƒœ๊ทธ๊ฐ€ ํฌํ•จ๋œ ํŠธ์œ—์„ ๊ฒ€์ƒ‰ํ•˜๋Š” ๊ธฐ๋ณธ ์ฝ”๋“œ์˜ˆ์š”:

def search_tweets(query, max_results=100):
    """
    ํŠน์ • ํ‚ค์›Œ๋“œ๋กœ ํŠธ์œ— ๊ฒ€์ƒ‰
    
    Args:
        query: ๊ฒ€์ƒ‰ํ•  ํ‚ค์›Œ๋“œ (์˜ˆ: "ํŒŒ์ด์ฌ OR Python")
        max_results: ๊ฐ€์ ธ์˜ฌ ํŠธ์œ— ๊ฐœ์ˆ˜ (์ตœ๋Œ€ 100)
    
    Returns:
        ํŠธ์œ— ๋ฐ์ดํ„ฐ ๋ฆฌ์ŠคํŠธ
    """
    try:
        tweets = client.search_recent_tweets(
            query=query,
            max_results=max_results,
            tweet_fields=['created_at', 'author_id', 'public_metrics', 'lang'],
            expansions=['author_id'],
            user_fields=['username', 'name']
        )
        
        tweet_list = []
        
        if tweets.data:
            # ์‚ฌ์šฉ์ž ์ •๋ณด ๋งคํ•‘
            users = {user.id: user for user in tweets.includes['users']}
            
            for tweet in tweets.data:
                author = users.get(tweet.author_id)
                
                tweet_info = {
                    'id': tweet.id,
                    'text': tweet.text,
                    'created_at': tweet.created_at,
                    'author_name': author.name if author else 'Unknown',
                    'author_username': author.username if author else 'Unknown',
                    'likes': tweet.public_metrics['like_count'],
                    'retweets': tweet.public_metrics['retweet_count'],
                    'replies': tweet.public_metrics['reply_count'],
                    'language': tweet.lang
                }
                
                tweet_list.append(tweet_info)
            
            print(f"โœ… {len(tweet_list)}๊ฐœ์˜ ํŠธ์œ—์„ ์ˆ˜์ง‘ํ–ˆ์Šต๋‹ˆ๋‹ค!")
            return tweet_list
        else:
            print("๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.")
            return []
            
    except Exception as e:
        print(f"โŒ ์—๋Ÿฌ ๋ฐœ์ƒ: {e}")
        return []

# ์‚ฌ์šฉ ์˜ˆ์‹œ
tweets = search_tweets("์ธ๊ณต์ง€๋Šฅ -is:retweet lang:ko", max_results=50)

๐Ÿ’ก ๊ฒ€์ƒ‰ ์ฟผ๋ฆฌ ํŒ: โ€ข -is:retweet: ๋ฆฌํŠธ์œ— ์ œ์™ธ
โ€ข lang:ko: ํ•œ๊ตญ์–ด ํŠธ์œ—๋งŒ
โ€ข "์ •ํ™•ํ•œ ๋ฌธ๊ตฌ": ๋”ฐ์˜ดํ‘œ๋กœ ์ •ํ™•ํ•œ ๋ฌธ๊ตฌ ๊ฒ€์ƒ‰
โ€ข OR: ์—ฌ๋Ÿฌ ํ‚ค์›Œ๋“œ ์ค‘ ํ•˜๋‚˜๋ผ๋„ ํฌํ•จ
โ€ข from:username: ํŠน์ • ์‚ฌ์šฉ์ž์˜ ํŠธ์œ—๋งŒ
โ€ข has:images: ์ด๋ฏธ์ง€๊ฐ€ ํฌํ•จ๋œ ํŠธ์œ—๋งŒ

๐Ÿ“Š ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ

์ˆ˜์ง‘ํ•œ ํŠธ์œ— ๋ฐ์ดํ„ฐ๋ฅผ ์š”์•ฝํ•˜๊ธฐ ์ „์— ์ •์ œ ์ž‘์—…์ด ํ•„์š”ํ•ด์š”. URL, ๋ฉ˜์…˜, ํ•ด์‹œํƒœ๊ทธ ๊ฐ™์€ ๋ถˆํ•„์š”ํ•œ ์š”์†Œ๋“ค์„ ์ œ๊ฑฐํ•ด์•ผ ํ•˜๊ฑฐ๋“ ์š”:

import re
import nltk
from nltk.corpus import stopwords

# NLTK ๋ฐ์ดํ„ฐ ๋‹ค์šด๋กœ๋“œ (์ตœ์ดˆ 1ํšŒ๋งŒ)
nltk.download('stopwords', quiet=True)
nltk.download('punkt', quiet=True)

def clean_tweet(text):
    """
    ํŠธ์œ— ํ…์ŠคํŠธ ์ •์ œ
    """
    # URL ์ œ๊ฑฐ
    text = re.sub(r'http\S+|www\S+|https\S+', '', text, flags=re.MULTILINE)
    
    # ๋ฉ˜์…˜(@username) ์ œ๊ฑฐ
    text = re.sub(r'@\w+', '', text)
    
    # ํ•ด์‹œํƒœ๊ทธ ๊ธฐํ˜ธ๋งŒ ์ œ๊ฑฐ (๋‚ด์šฉ์€ ์œ ์ง€)
    text = re.sub(r'#', '', text)
    
    # ํŠน์ˆ˜๋ฌธ์ž ์ œ๊ฑฐ (ํ•œ๊ธ€, ์˜๋ฌธ, ์ˆซ์ž, ๊ณต๋ฐฑ๋งŒ ์œ ์ง€)
    text = re.sub(r'[^\w\s๊ฐ€-ํžฃ]', '', text)
    
    # ์—ฐ์†๋œ ๊ณต๋ฐฑ ์ œ๊ฑฐ
    text = re.sub(r'\s+', ' ', text).strip()
    
    return text

def preprocess_tweets(tweet_list):
    """
    ํŠธ์œ— ๋ฆฌ์ŠคํŠธ ์ „์ฒ˜๋ฆฌ
    """
    processed_tweets = []
    
    for tweet in tweet_list:
        cleaned_text = clean_tweet(tweet['text'])
        
        # ๋„ˆ๋ฌด ์งง์€ ํŠธ์œ—์€ ์ œ์™ธ (10์ž ๋ฏธ๋งŒ)
        if len(cleaned_text) >= 10:
            tweet['cleaned_text'] = cleaned_text
            processed_tweets.append(tweet)
    
    print(f"โœ… {len(processed_tweets)}๊ฐœ์˜ ํŠธ์œ—์ด ์ „์ฒ˜๋ฆฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!")
    return processed_tweets

# ์‚ฌ์šฉ ์˜ˆ์‹œ
processed_tweets = preprocess_tweets(tweets)

๐Ÿง  AI ์š”์•ฝ ๋ชจ๋ธ ๊ตฌํ˜„ํ•˜๊ธฐ

๋“œ๋””์–ด ํ•ต์‹ฌ ํŒŒํŠธ! AI ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•ด์„œ ํŠธ์œ—์„ ์š”์•ฝํ•˜๋Š” ๋ถ€๋ถ„์ด์—์š”. ์—ฌ๊ธฐ์„œ๋Š” Hugging Face์˜ ์‚ฌ์ „ ํ•™์Šต๋œ ๋ชจ๋ธ์„ ํ™œ์šฉํ•  ๊ฑฐ์˜ˆ์š” ใ…Žใ…Ž

๐Ÿค– Transformers ๋ชจ๋ธ ๋กœ๋“œ

ํ•œ๊ตญ์–ด ์š”์•ฝ์— ํŠนํ™”๋œ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋” ์ข‹์€ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์–ด์š”. ์—ฌ๊ธฐ์„œ๋Š” ๋‹ค๊ตญ์–ด ์ง€์› ๋ชจ๋ธ๊ณผ ํ•œ๊ตญ์–ด ํŠนํ™” ๋ชจ๋ธ ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœํ• ๊ฒŒ์š”:

from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
import torch

class TweetSummarizer:
    def __init__(self, model_name='facebook/bart-large-cnn'):
        """
        ์š”์•ฝ ๋ชจ๋ธ ์ดˆ๊ธฐํ™”
        
        Args:
            model_name: ์‚ฌ์šฉํ•  ๋ชจ๋ธ ์ด๋ฆ„
                - 'facebook/bart-large-cnn': ์˜์–ด ํŠนํ™” (๊ธฐ๋ณธ)
                - 'csebuetnlp/mT5_multilingual_XLSum': ๋‹ค๊ตญ์–ด ์ง€์›
                - 'eenzeenee/t5-base-korean-summarization': ํ•œ๊ตญ์–ด ํŠนํ™”
        """
        print(f"๐Ÿ”„ ๋ชจ๋ธ ๋กœ๋”ฉ ์ค‘: {model_name}")
        
        self.device = 0 if torch.cuda.is_available() else -1
        
        try:
            self.summarizer = pipeline(
                "summarization",
                model=model_name,
                device=self.device
            )
            print("โœ… ๋ชจ๋ธ ๋กœ๋”ฉ ์™„๋ฃŒ!")
        except Exception as e:
            print(f"โŒ ๋ชจ๋ธ ๋กœ๋”ฉ ์‹คํŒจ: {e}")
            print("๊ธฐ๋ณธ ๋ชจ๋ธ๋กœ ์žฌ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค...")
            self.summarizer = pipeline(
                "summarization",
                model='facebook/bart-large-cnn',
                device=self.device
            )
    
    def summarize_text(self, text, max_length=130, min_length=30):
        """
        ๋‹จ์ผ ํ…์ŠคํŠธ ์š”์•ฝ
        """
        try:
            # ํ…์ŠคํŠธ๊ฐ€ ๋„ˆ๋ฌด ์งง์œผ๋ฉด ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜
            if len(text.split()) < 20:
                return text
            
            summary = self.summarizer(
                text,
                max_length=max_length,
                min_length=min_length,
                do_sample=False
            )
            
            return summary[0]['summary_text']
        
        except Exception as e:
            print(f"์š”์•ฝ ์ค‘ ์—๋Ÿฌ: {e}")
            return text[:100] + "..."  # ์—๋Ÿฌ ์‹œ ์•ž๋ถ€๋ถ„๋งŒ ๋ฐ˜ํ™˜
    
    def summarize_multiple_tweets(self, tweets, combine=True):
        """
        ์—ฌ๋Ÿฌ ํŠธ์œ— ์š”์•ฝ
        
        Args:
            tweets: ํŠธ์œ— ๋ฆฌ์ŠคํŠธ
            combine: True๋ฉด ๋ชจ๋“  ํŠธ์œ—์„ ํ•ฉ์ณ์„œ ํ•˜๋‚˜๋กœ ์š”์•ฝ,
                    False๋ฉด ๊ฐ๊ฐ ์š”์•ฝ
        """
        if combine:
            # ๋ชจ๋“  ํŠธ์œ—์„ ํ•˜๋‚˜๋กœ ํ•ฉ์น˜๊ธฐ
            combined_text = " ".join([t['cleaned_text'] for t in tweets])
            
            # ๋„ˆ๋ฌด ๊ธธ๋ฉด ์ž˜๋ผ๋‚ด๊ธฐ (๋ชจ๋ธ์˜ ์ตœ๋Œ€ ์ž…๋ ฅ ๊ธธ์ด ์ œํ•œ)
            if len(combined_text.split()) > 1000:
                words = combined_text.split()[:1000]
                combined_text = " ".join(words)
            
            summary = self.summarize_text(combined_text, max_length=200, min_length=50)
            
            return {
                'type': 'combined',
                'summary': summary,
                'tweet_count': len(tweets)
            }
        else:
            # ๊ฐ ํŠธ์œ— ๊ฐœ๋ณ„ ์š”์•ฝ
            summaries = []
            for tweet in tweets:
                summary = self.summarize_text(
                    tweet['cleaned_text'],
                    max_length=100,
                    min_length=20
                )
                summaries.append({
                    'original': tweet['text'],
                    'summary': summary,
                    'author': tweet['author_name'],
                    'likes': tweet['likes']
                })
            
            return {
                'type': 'individual',
                'summaries': summaries
            }

# ์‚ฌ์šฉ ์˜ˆ์‹œ
summarizer = TweetSummarizer()

# ๋ฐฉ๋ฒ• 1: ๋ชจ๋“  ํŠธ์œ—์„ ํ•ฉ์ณ์„œ ํ•˜๋‚˜์˜ ์š”์•ฝ ์ƒ์„ฑ
combined_summary = summarizer.summarize_multiple_tweets(processed_tweets, combine=True)
print("\n๐Ÿ“ ํ†ตํ•ฉ ์š”์•ฝ:")
print(combined_summary['summary'])

# ๋ฐฉ๋ฒ• 2: ๊ฐ ํŠธ์œ—์„ ๊ฐœ๋ณ„์ ์œผ๋กœ ์š”์•ฝ
individual_summaries = summarizer.summarize_multiple_tweets(processed_tweets, combine=False)
print("\n๐Ÿ“ ๊ฐœ๋ณ„ ์š”์•ฝ:")
for i, item in enumerate(individual_summaries['summaries'][:5], 1):
    print(f"\n{i}. {item['author']} (์ข‹์•„์š” {item['likes']}๊ฐœ)")
    print(f"   ์š”์•ฝ: {item['summary']}")

๐Ÿ’ก ๋ชจ๋ธ ์„ ํƒ ๊ฐ€์ด๋“œ: ์˜์–ด ํŠธ์œ— ์š”์•ฝ:
โ€ข facebook/bart-large-cnn (์ถ”์ฒœ! ์„ฑ๋Šฅ ์ข‹์Œ)
โ€ข google/pegasus-xsum (๋‰ด์Šค ์š”์•ฝ์— ํŠนํ™”)

ํ•œ๊ตญ์–ด ํŠธ์œ— ์š”์•ฝ:
โ€ข eenzeenee/t5-base-korean-summarization
โ€ข lcw99/t5-base-korean-text-summary

๋‹ค๊ตญ์–ด ์ง€์›:
โ€ข csebuetnlp/mT5_multilingual_XLSum
โ€ข facebook/mbart-large-50 (50๊ฐœ ์–ธ์–ด ์ง€์›)

โš ๏ธ ์„ฑ๋Šฅ ์ตœ์ ํ™” ํŒ: โ€ข GPU๊ฐ€ ์žˆ์œผ๋ฉด ํ›จ์”ฌ ๋น ๋ฆ…๋‹ˆ๋‹ค (CUDA ์„ค์น˜ ๊ถŒ์žฅ)
โ€ข ๋ชจ๋ธ ์ฒซ ๋กœ๋”ฉ ์‹œ ์‹œ๊ฐ„์ด ์ข€ ๊ฑธ๋ ค์š” (์ธํ„ฐ๋„ท์—์„œ ๋‹ค์šด๋กœ๋“œ)
โ€ข ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋ถ€์กฑํ•˜๋ฉด ๋” ์ž‘์€ ๋ชจ๋ธ ์‚ฌ์šฉ (์˜ˆ: t5-small)
โ€ข ๋ฐฐ์น˜ ์ฒ˜๋ฆฌ๋กœ ์—ฌ๋Ÿฌ ํŠธ์œ—์„ ํ•œ ๋ฒˆ์— ์ฒ˜๋ฆฌํ•˜๋ฉด ํšจ์œจ์ 

๐Ÿ“Š ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ: ๊ฐ์„ฑ ๋ถ„์„ ์ถ”๊ฐ€ํ•˜๊ธฐ

์š”์•ฝ๋งŒ ํ•˜๋ฉด ์ข€ ์‹ฌ์‹ฌํ•˜์ž–์•„์š”? ใ…‹ใ…‹ ํŠธ์œ—์˜ ๊ฐ์ •(๊ธ์ •/๋ถ€์ •/์ค‘๋ฆฝ)๋„ ๋ถ„์„ํ•ด์„œ ํ•จ๊ป˜ ๋ณด์—ฌ์ฃผ๋ฉด ํ›จ์”ฌ ์œ ์šฉํ•ด์š”!

from transformers import pipeline

class SentimentAnalyzer:
    def __init__(self):
        """๊ฐ์„ฑ ๋ถ„์„ ๋ชจ๋ธ ์ดˆ๊ธฐํ™”"""
        print("๐Ÿ”„ ๊ฐ์„ฑ ๋ถ„์„ ๋ชจ๋ธ ๋กœ๋”ฉ ์ค‘...")
        
        # ๋‹ค๊ตญ์–ด ๊ฐ์„ฑ ๋ถ„์„ ๋ชจ๋ธ
        self.analyzer = pipeline(
            "sentiment-analysis",
            model="cardiffnlp/twitter-xlm-roberta-base-sentiment",
            device=0 if torch.cuda.is_available() else -1
        )
        
        print("โœ… ๊ฐ์„ฑ ๋ถ„์„ ๋ชจ๋ธ ๋กœ๋”ฉ ์™„๋ฃŒ!")
    
    def analyze(self, text):
        """
        ํ…์ŠคํŠธ์˜ ๊ฐ์„ฑ ๋ถ„์„
        
        Returns:
            dict: {'label': 'positive/negative/neutral', 'score': 0.95}
        """
        try:
            result = self.analyzer(text[:512])[0]  # ์ตœ๋Œ€ 512์ž๊นŒ์ง€
            
            # ๋ผ๋ฒจ ํ•œ๊ธ€ํ™”
            label_map = {
                'LABEL_0': 'negative',
                'LABEL_1': 'neutral', 
                'LABEL_2': 'positive',
                'negative': '๋ถ€์ •',
                'neutral': '์ค‘๋ฆฝ',
                'positive': '๊ธ์ •'
            }
            
            label = label_map.get(result['label'], result['label'])
            label_kr = label_map.get(label, label)
            
            return {
                'label': label,
                'label_kr': label_kr,
                'score': round(result['score'], 3)
            }
        
        except Exception as e:
            print(f"๊ฐ์„ฑ ๋ถ„์„ ์—๋Ÿฌ: {e}")
            return {'label': 'unknown', 'label_kr': '์•Œ ์ˆ˜ ์—†์Œ', 'score': 0}
    
    def analyze_tweets(self, tweets):
        """์—ฌ๋Ÿฌ ํŠธ์œ—์˜ ๊ฐ์„ฑ ๋ถ„์„ ๋ฐ ํ†ต๊ณ„"""
        sentiments = []
        
        for tweet in tweets:
            sentiment = self.analyze(tweet['cleaned_text'])
            sentiments.append(sentiment)
        
        # ํ†ต๊ณ„ ๊ณ„์‚ฐ
        positive_count = sum(1 for s in sentiments if s['label'] == 'positive')
        negative_count = sum(1 for s in sentiments if s['label'] == 'negative')
        neutral_count = sum(1 for s in sentiments if s['label'] == 'neutral')
        
        total = len(sentiments)
        
        stats = {
            'positive': {'count': positive_count, 'ratio': positive_count/total if total > 0 else 0},
            'negative': {'count': negative_count, 'ratio': negative_count/total if total > 0 else 0},
            'neutral': {'count': neutral_count, 'ratio': neutral_count/total if total > 0 else 0},
            'total': total
        }
        
        return sentiments, stats

# ์‚ฌ์šฉ ์˜ˆ์‹œ
sentiment_analyzer = SentimentAnalyzer()
sentiments, stats = sentiment_analyzer.analyze_tweets(processed_tweets)

print("\n๐Ÿ˜Š ๊ฐ์„ฑ ๋ถ„์„ ๊ฒฐ๊ณผ:")
print(f"๊ธ์ •: {stats['positive']['count']}๊ฐœ ({stats['positive']['ratio']*100:.1f}%)")
print(f"์ค‘๋ฆฝ: {stats['neutral']['count']}๊ฐœ ({stats['neutral']['ratio']*100:.1f}%)")
print(f"๋ถ€์ •: {stats['negative']['count']}๊ฐœ ({stats['negative']['ratio']*100:.1f}%)")

๐ŸŽจ ๊ฒฐ๊ณผ ์‹œ๊ฐํ™” ๋ฐ ๋ฆฌํฌํŠธ ์ƒ์„ฑ

๋ถ„์„ ๊ฒฐ๊ณผ๋ฅผ ์˜ˆ์˜๊ฒŒ ์ •๋ฆฌํ•ด์„œ ๋ณด์—ฌ์ฃผ๋Š” ๊ฒƒ๋„ ์ค‘์š”ํ•˜์ฃ ! ๊ฐ„๋‹จํ•œ HTML ๋ฆฌํฌํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ฝ”๋“œ์˜ˆ์š”:

from datetime import datetime
import json

class ReportGenerator:
    def __init__(self):
        self.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    
    def generate_html_report(self, summary_data, sentiment_stats, tweets, filename="report.html"):
        """
        HTML ํ˜•์‹์˜ ๋ฆฌํฌํŠธ ์ƒ์„ฑ
        """
        html_template = f"""
        <!DOCTYPE html>
        <html lang="ko">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>ํŠธ์œ„ํ„ฐ ์š”์•ฝ ๋ฆฌํฌํŠธ</title>
            <style>.tx-header{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);
color:#fff;
padding:40px 25px;
border-radius:16px;
text-align:center;
margin-bottom:35px;
box-shadow:0 8px 20px rgba(102,126,234,0.3)}
.tx-intro{background:#f8f9fa;
padding:25px;
border-radius:12px;
margin:25px 0;
border-left:5px solid #667eea}
.tx-section{margin:35px 0}
.tx-box{background:#fff;
border:2px solid #e9ecef;
padding:20px;
border-radius:12px;
margin:20px 0}
.tx-highlight{background:linear-gradient(120deg,#fef3c7 0%,#fde68a 100%);
padding:3px 8px;
border-radius:4px;
font-weight:600}
.tx-tip{background:#e0f2fe;
border-left:4px solid #0284c7;
padding:15px;
border-radius:8px;
margin:20px 0}
.tx-warning{background:#fef3c7;
border-left:4px solid #f59e0b;
padding:15px;
border-radius:8px;
margin:20px 0}
.tx-table{width:100%;
border-collapse:collapse;
margin:20px 0}
.tx-table th{background:#667eea;
color:#fff;
padding:12px;
text-align:left}
.tx-table td{padding:12px;
border-bottom:1px solid #e9ecef}
.tx-step{background:#f1f5f9;
padding:15px;
border-radius:8px;
margin:15px 0;
border-left:4px solid #8b5cf6}
.tx-emoji{font-size:1.3em;
margin:0 5px}</style>
        </head>
        <body>
            <div class="header">
                <h1>๐Ÿฆ ํŠธ์œ„ํ„ฐ ์ž๋™ ์š”์•ฝ ๋ฆฌํฌํŠธ</h1>
                <p>์ƒ์„ฑ ์‹œ๊ฐ„: {self.timestamp}</p>
                <p>๋ถ„์„๋œ ํŠธ์œ— ์ˆ˜: {len(tweets)}๊ฐœ</p>
            </div>
            
            <div class="summary-box">
                <h2>๐Ÿ“ ํ•ต์‹ฌ ์š”์•ฝ</h2>
                <p style="font-size: 1.1em; line-height: 1.6;">
                    {summary_data['summary']}
                </p>
            </div>
            
            <h2>๐Ÿ˜Š ๊ฐ์„ฑ ๋ถ„์„ ๊ฒฐ๊ณผ</h2>
            <div class="sentiment-stats">
                <div class="stat-card positive">
                    <h3>๊ธ์ •</h3>
                    <p style="font-size: 2em; margin: 10px 0;">{sentiment_stats['positive']['count']}</p>
                    <p>{sentiment_stats['positive']['ratio']*100:.1f}%</p>
                </div>
                <div class="stat-card neutral">
                    <h3>์ค‘๋ฆฝ</h3>
                    <p style="font-size: 2em; margin: 10px 0;">{sentiment_stats['neutral']['count']}</p>
                    <p>{sentiment_stats['neutral']['ratio']*100:.1f}%</p>
                </div>
                <div class="stat-card negative">
                    <h3>๋ถ€์ •</h3>
                    <p style="font-size: 2em; margin: 10px 0;">{sentiment_stats['negative']['count']}</p>
                    <p>{sentiment_stats['negative']['ratio']*100:.1f}%</p>
                </div>
            </div>
            
            <div class="summary-box">
                <h2>๐Ÿ”ฅ ์ธ๊ธฐ ํŠธ์œ— TOP 5</h2>
                {self._generate_top_tweets_html(tweets[:5])}
            </div>
            
            <div style="text-align: center; margin-top: 30px; color: #6b7280;">
                <p>Powered by Python & AI ๐Ÿค–</p>
            </div>
        </body>
        </html>
        """
        
        with open(filename, 'w', encoding='utf-8') as f:
            f.write(html_template)
        
        print(f"โœ… ๋ฆฌํฌํŠธ๊ฐ€ ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค: {filename}")
        return filename
    
    def _generate_top_tweets_html(self, tweets):
        """์ธ๊ธฐ ํŠธ์œ— HTML ์ƒ์„ฑ"""
        html = ""
        for i, tweet in enumerate(tweets, 1):
            html += f"""
            <div class="tweet-item">
                <strong>{i}. @{tweet['author_username']}</strong>
                <p>{tweet['text'][:200]}...</p>
                <small>โค๏ธ {tweet['likes']} | ๐Ÿ”„ {tweet['retweets']} | ๐Ÿ’ฌ {tweet['replies']}</small>
            </div>
            """
        return html
    
    def save_json_report(self, data, filename="report.json"):
        """JSON ํ˜•์‹์œผ๋กœ ์ €์žฅ"""
        with open(filename, 'w', encoding='utf-8') as f:
            json.dump(data, f, ensure_ascii=False, indent=2)
        print(f"โœ… JSON ๋ฆฌํฌํŠธ ์ €์žฅ ์™„๋ฃŒ: {filename}")

# ์‚ฌ์šฉ ์˜ˆ์‹œ
reporter = ReportGenerator()

# ํŠธ์œ—์„ ์ข‹์•„์š” ์ˆœ์œผ๋กœ ์ •๋ ฌ
sorted_tweets = sorted(processed_tweets, key=lambda x: x['likes'], reverse=True)

# HTML ๋ฆฌํฌํŠธ ์ƒ์„ฑ
reporter.generate_html_report(
    combined_summary,
    stats,
    sorted_tweets,
    filename="twitter_summary_report.html"
)

# JSON ๋ฐ์ดํ„ฐ๋„ ์ €์žฅ
report_data = {
    'timestamp': reporter.timestamp,
    'summary': combined_summary,
    'sentiment_stats': stats,
    'top_tweets': sorted_tweets[:10]
}
reporter.save_json_report(report_data, "twitter_summary_data.json")

โšก ์ž๋™ํ™” ์Šค์ผ€์ค„๋ง ๊ตฌํ˜„ํ•˜๊ธฐ

์ด์ œ ์ด ๋ชจ๋“  ๊ฑธ ์ž๋™์œผ๋กœ ์‹คํ–‰๋˜๊ฒŒ ๋งŒ๋“ค์–ด๋ณผ๊นŒ์š”? ๋งค์ผ ์ •ํ•ด์ง„ ์‹œ๊ฐ„์— ์ž๋™์œผ๋กœ ํŠธ์œ—์„ ์ˆ˜์ง‘ํ•˜๊ณ  ์š”์•ฝํ•ด์ฃผ๋Š” ๋ด‡์„ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค ใ…Žใ…Ž

import schedule
import time
from datetime import datetime

class TwitterSummaryBot:
    def __init__(self, search_query, max_tweets=50):
        """
        ์ž๋™ ์š”์•ฝ ๋ด‡ ์ดˆ๊ธฐํ™”
        
        Args:
            search_query: ๊ฒ€์ƒ‰ํ•  ํ‚ค์›Œ๋“œ
            max_tweets: ์ˆ˜์ง‘ํ•  ์ตœ๋Œ€ ํŠธ์œ— ์ˆ˜
        """
        self.search_query = search_query
        self.max_tweets = max_tweets
        self.summarizer = TweetSummarizer()
        self.sentiment_analyzer = SentimentAnalyzer()
        self.reporter = ReportGenerator()
        
        print(f"๐Ÿค– ๋ด‡ ์ดˆ๊ธฐํ™” ์™„๋ฃŒ!")
        print(f"๊ฒ€์ƒ‰ ํ‚ค์›Œ๋“œ: {search_query}")
        print(f"์ˆ˜์ง‘ ํŠธ์œ— ์ˆ˜: {max_tweets}๊ฐœ")
    
    def run_summary_job(self):
        """์š”์•ฝ ์ž‘์—… ์‹คํ–‰"""
        print(f"\n{'='*50}")
        print(f"๐Ÿš€ ์ž‘์—… ์‹œ์ž‘: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
        print(f"{'='*50}\n")
        
        try:
            # 1. ํŠธ์œ— ์ˆ˜์ง‘
            print("1๏ธโƒฃ ํŠธ์œ— ์ˆ˜์ง‘ ์ค‘...")
            tweets = search_tweets(self.search_query, self.max_tweets)
            
            if not tweets:
                print("โŒ ์ˆ˜์ง‘๋œ ํŠธ์œ—์ด ์—†์Šต๋‹ˆ๋‹ค.")
                return
            
            # 2. ์ „์ฒ˜๋ฆฌ
            print("2๏ธโƒฃ ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ ์ค‘...")
            processed = preprocess_tweets(tweets)
            
            # 3. ์š”์•ฝ ์ƒ์„ฑ
            print("3๏ธโƒฃ AI ์š”์•ฝ ์ƒ์„ฑ ์ค‘...")
            summary = self.summarizer.summarize_multiple_tweets(processed, combine=True)
            
            # 4. ๊ฐ์„ฑ ๋ถ„์„
            print("4๏ธโƒฃ ๊ฐ์„ฑ ๋ถ„์„ ์ค‘...")
            sentiments, stats = self.sentiment_analyzer.analyze_tweets(processed)
            
            # 5. ๋ฆฌํฌํŠธ ์ƒ์„ฑ
            print("5๏ธโƒฃ ๋ฆฌํฌํŠธ ์ƒ์„ฑ ์ค‘...")
            sorted_tweets = sorted(processed, key=lambda x: x['likes'], reverse=True)
            
            timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
            html_filename = f"report_{timestamp}.html"
            json_filename = f"data_{timestamp}.json"
            
            self.reporter.generate_html_report(
                summary, stats, sorted_tweets, html_filename
            )
            
            report_data = {
                'timestamp': datetime.now().isoformat(),
                'query': self.search_query,
                'summary': summary,
                'sentiment_stats': stats,
                'tweet_count': len(processed),
                'top_tweets': sorted_tweets[:10]
            }
            self.reporter.save_json_report(report_data, json_filename)
            
            print(f"\nโœ… ์ž‘์—… ์™„๋ฃŒ!")
            print(f"๐Ÿ“Š ์š”์•ฝ: {summary['summary'][:100]}...")
            print(f"๐Ÿ˜Š ๊ธ์ •: {stats['positive']['ratio']*100:.1f}% | "
                  f"๐Ÿ˜ ์ค‘๋ฆฝ: {stats['neutral']['ratio']*100:.1f}% | "
                  f"๐Ÿ˜ž ๋ถ€์ •: {stats['negative']['ratio']*100:.1f}%")
            
        except Exception as e:
            print(f"โŒ ์ž‘์—… ์ค‘ ์—๋Ÿฌ ๋ฐœ์ƒ: {e}")
            import traceback
            traceback.print_exc()
    
    def start_scheduler(self, schedule_times=['09:00', '15:00', '21:00']):
        """
        ์Šค์ผ€์ค„๋Ÿฌ ์‹œ์ž‘
        
        Args:
            schedule_times: ์‹คํ–‰ํ•  ์‹œ๊ฐ„ ๋ฆฌ์ŠคํŠธ (์˜ˆ: ['09:00', '15:00'])
        """
        print(f"\nโฐ ์Šค์ผ€์ค„๋Ÿฌ ์‹œ์ž‘!")
        print(f"์‹คํ–‰ ์‹œ๊ฐ„: {', '.join(schedule_times)}")
        
        # ๊ฐ ์‹œ๊ฐ„์— ์ž‘์—… ์Šค์ผ€์ค„๋ง
        for time_str in schedule_times:
            schedule.every().day.at(time_str).do(self.run_summary_job)
            print(f"  - ๋งค์ผ {time_str}์— ์‹คํ–‰ ์˜ˆ์•ฝ๋จ")
        
        # ์ฆ‰์‹œ ํ•œ ๋ฒˆ ์‹คํ–‰
        print("\n๐ŸŽฌ ์ฒซ ์‹คํ–‰์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค...")
        self.run_summary_job()
        
        # ์Šค์ผ€์ค„๋Ÿฌ ๋ฃจํ”„
        print("\nโณ ๋‹ค์Œ ์‹คํ–‰ ๋Œ€๊ธฐ ์ค‘... (Ctrl+C๋กœ ์ข…๋ฃŒ)")
        try:
            while True:
                schedule.run_pending()
                time.sleep(60)  # 1๋ถ„๋งˆ๋‹ค ์ฒดํฌ
        except KeyboardInterrupt:
            print("\n\n๐Ÿ‘‹ ๋ด‡์„ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.")

# ์‚ฌ์šฉ ์˜ˆ์‹œ
if __name__ == "__main__":
    # ๋ด‡ ์ƒ์„ฑ
    bot = TwitterSummaryBot(
        search_query="ํŒŒ์ด์ฌ OR Python -is:retweet lang:ko",
        max_tweets=50
    )
    
    # ์Šค์ผ€์ค„๋Ÿฌ ์‹œ์ž‘ (๋งค์ผ 9์‹œ, 15์‹œ, 21์‹œ์— ์‹คํ–‰)
    bot.start_scheduler(['09:00', '15:00', '21:00'])
    
    # ๋˜๋Š” ์ฆ‰์‹œ ํ•œ ๋ฒˆ๋งŒ ์‹คํ–‰ํ•˜๋ ค๋ฉด:
    # bot.run_summary_job()

๐Ÿ’ก ์Šค์ผ€์ค„๋ง ์˜ต์…˜: ๋งค์ผ ํŠน์ • ์‹œ๊ฐ„:
schedule.every().day.at("09:00").do(job)

๋งค N์‹œ๊ฐ„๋งˆ๋‹ค:
schedule.every(3).hours.do(job)

๋งค์ฃผ ํŠน์ • ์š”์ผ:
schedule.every().monday.at("10:00").do(job)

๋งค N๋ถ„๋งˆ๋‹ค:
schedule.every(30).minutes.do(job)

๐Ÿ”ง ์‹ค์ „ ๋ฐฐํฌ: ์„œ๋ฒ„์—์„œ 24์‹œ๊ฐ„ ์‹คํ–‰ํ•˜๊ธฐ

๋กœ์ปฌ ์ปดํ“จํ„ฐ์—์„œ๋งŒ ๋Œ๋ฆฌ๋ฉด ์ปดํ“จํ„ฐ ๊บผ์ง€๋ฉด ๋ด‡๋„ ๋ฉˆ์ถ”์ž–์•„์š” ใ… ใ…  ํด๋ผ์šฐ๋“œ ์„œ๋ฒ„์— ๋ฐฐํฌํ•ด์„œ 24์‹œ๊ฐ„ ๋Œ์•„๊ฐ€๊ฒŒ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค!

โ˜๏ธ AWS EC2 ๋˜๋Š” Google Cloud์— ๋ฐฐํฌํ•˜๊ธฐ

๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ๋ฐฐํฌ ๋ฐฉ๋ฒ•์ด์—์š”. ๋ฌด๋ฃŒ ํ‹ฐ์–ด๋กœ๋„ ์ถฉ๋ถ„ํžˆ ๋Œ๋ฆด ์ˆ˜ ์žˆ์–ด์š”!

1. ์„œ๋ฒ„ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ

โ€ข AWS EC2 t2.micro (ํ”„๋ฆฌํ‹ฐ์–ด) ๋˜๋Š” Google Cloud e2-micro ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
โ€ข Ubuntu 20.04 LTS ์ด๋ฏธ์ง€ ์„ ํƒ
โ€ข SSH ์ ‘์† ์„ค์ •

2. ์„œ๋ฒ„ ํ™˜๊ฒฝ ์„ค์ •

SSH๋กœ ์ ‘์†ํ•œ ํ›„ ์•„๋ž˜ ๋ช…๋ น์–ด ์‹คํ–‰:

# ์‹œ์Šคํ…œ ์—…๋ฐ์ดํŠธ
sudo apt update && sudo apt upgrade -y

# Python 3.9 ์„ค์น˜
sudo apt install python3.9 python3-pip -y

# Git ์„ค์น˜
sudo apt install git -y

# ํ”„๋กœ์ ํŠธ ํด๋ก 
git clone https://github.com/your-username/twitter-summary-bot.git
cd twitter-summary-bot

# ๊ฐ€์ƒํ™˜๊ฒฝ ์ƒ์„ฑ
python3 -m venv venv
source venv/bin/activate

# ํŒจํ‚ค์ง€ ์„ค์น˜
pip install -r requirements.txt

# .env ํŒŒ์ผ ์ƒ์„ฑ (API ํ‚ค ์ž…๋ ฅ)
nano .env

3. systemd ์„œ๋น„์Šค๋กœ ๋“ฑ๋ก (์ž๋™ ์žฌ์‹œ์ž‘)

์„œ๋ฒ„๊ฐ€ ์žฌ๋ถ€ํŒ…๋˜์–ด๋„ ์ž๋™์œผ๋กœ ๋ด‡์ด ์‹คํ–‰๋˜๊ฒŒ ์„ค์ •:

# ์„œ๋น„์Šค ํŒŒ์ผ ์ƒ์„ฑ
sudo nano /etc/systemd/system/twitter-bot.service

# ์•„๋ž˜ ๋‚ด์šฉ ์ž…๋ ฅ:
[Unit]
Description=Twitter Summary Bot
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/twitter-summary-bot
Environment="PATH=/home/ubuntu/twitter-summary-bot/venv/bin"
ExecStart=/home/ubuntu/twitter-summary-bot/venv/bin/python main.py
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

# ์„œ๋น„์Šค ํ™œ์„ฑํ™” ๋ฐ ์‹œ์ž‘
sudo systemctl daemon-reload
sudo systemctl enable twitter-bot
sudo systemctl start twitter-bot

# ์ƒํƒœ ํ™•์ธ
sudo systemctl status twitter-bot

# ๋กœ๊ทธ ํ™•์ธ
sudo journalctl -u twitter-bot -f

๐Ÿณ Docker๋กœ ๋ฐฐํฌํ•˜๊ธฐ (์ถ”์ฒœ!)

Docker๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํ™˜๊ฒฝ ์„ค์ •์ด ํ›จ์”ฌ ๊ฐ„ํŽธํ•ด์š”:

# Dockerfile ์ƒ์„ฑ
FROM python:3.9-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["python", "main.py"]

# docker-compose.yml ์ƒ์„ฑ
version: '3.8'

services:
  twitter-bot:
    build: .
    container_name: twitter-summary-bot
    restart: unless-stopped
    env_file:
      - .env
    volumes:
      - ./reports:/app/reports
      - ./data:/app/data

# ์‹คํ–‰
docker-compose up -d

# ๋กœ๊ทธ ํ™•์ธ
docker-compose logs -f

๐Ÿ“ฑ ๊ฒฐ๊ณผ ์•Œ๋ฆผ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ํ•˜๊ธฐ

์š”์•ฝ์ด ์™„๋ฃŒ๋˜๋ฉด ์ž๋™์œผ๋กœ ์•Œ๋ฆผ์„ ๋ฐ›์œผ๋ฉด ์ข‹๊ฒ ์ฃ ? ํ…”๋ ˆ๊ทธ๋žจ ๋ด‡์ด๋‚˜ ์ด๋ฉ”์ผ๋กœ ๊ฒฐ๊ณผ๋ฅผ ์ „์†กํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด๋ด…์‹œ๋‹ค!

๐Ÿ“จ ํ…”๋ ˆ๊ทธ๋žจ ์•Œ๋ฆผ

import requests

class TelegramNotifier:
    def __init__(self, bot_token, chat_id):
        """
        ํ…”๋ ˆ๊ทธ๋žจ ์•Œ๋ฆผ ์ดˆ๊ธฐํ™”
        
        Args:
            bot_token: ํ…”๋ ˆ๊ทธ๋žจ ๋ด‡ ํ† ํฐ (@BotFather์—์„œ ๋ฐœ๊ธ‰)
            chat_id: ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ›์„ ์ฑ„ํŒ… ID
        """
        self.bot_token = bot_token
        self.chat_id = chat_id
        self.api_url = f"https://api.telegram.org/bot{bot_token}"
    
    def send_message(self, text):
        """ํ…์ŠคํŠธ ๋ฉ”์‹œ์ง€ ์ „์†ก"""
        url = f"{self.api_url}/sendMessage"
        data = {
            'chat_id': self.chat_id,
            'text': text,
            'parse_mode': 'HTML'
        }
        
        try:
            response = requests.post(url, data=data)
            if response.status_code == 200:
                print("โœ… ํ…”๋ ˆ๊ทธ๋žจ ์•Œ๋ฆผ ์ „์†ก ์™„๋ฃŒ!")
            else:
                print(f"โŒ ์•Œ๋ฆผ ์ „์†ก ์‹คํŒจ: {response.text}")
        except Exception as e:
            print(f"โŒ ์—๋Ÿฌ: {e}")
    
    def send_summary_report(self, summary_data, sentiment_stats):
        """์š”์•ฝ ๋ฆฌํฌํŠธ ์ „์†ก"""
        message = f"""
๐Ÿฆ <b>ํŠธ์œ„ํ„ฐ ์š”์•ฝ ๋ฆฌํฌํŠธ</b>

๐Ÿ“ <b>ํ•ต์‹ฌ ์š”์•ฝ:</b>
{summary_data['summary'][:500]}...

๐Ÿ˜Š <b>๊ฐ์„ฑ ๋ถ„์„:</b>
๊ธ์ •: {sentiment_stats['positive']['ratio']*100:.1f}%
์ค‘๋ฆฝ: {sentiment_stats['neutral']['ratio']*100:.1f}%
๋ถ€์ •: {sentiment_stats['negative']['ratio']*100:.1f}%

๐Ÿ“Š ๋ถ„์„๋œ ํŠธ์œ—: {summary_data['tweet_count']}๊ฐœ
โฐ ์ƒ์„ฑ ์‹œ๊ฐ„: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
        """
        
        self.send_message(message)
    
    def send_file(self, file_path):
        """ํŒŒ์ผ ์ „์†ก (HTML ๋ฆฌํฌํŠธ ๋“ฑ)"""
        url = f"{self.api_url}/sendDocument"
        
        with open(file_path, 'rb') as file:
            files = {'document': file}
            data = {'chat_id': self.chat_id}
            
            try:
                response = requests.post(url, data=data, files=files)
                if response.status_code == 200:
                    print(f"โœ… ํŒŒ์ผ ์ „์†ก ์™„๋ฃŒ: {file_path}")
            except Exception as e:
                print(f"โŒ ํŒŒ์ผ ์ „์†ก ์—๋Ÿฌ: {e}")

# .env ํŒŒ์ผ์— ์ถ”๊ฐ€
# TELEGRAM_BOT_TOKEN=your_bot_token
# TELEGRAM_CHAT_ID=your_chat_id

# ์‚ฌ์šฉ ์˜ˆ์‹œ
telegram = TelegramNotifier(
    bot_token=os.getenv('TELEGRAM_BOT_TOKEN'),
    chat_id=os.getenv('TELEGRAM_CHAT_ID')
)

# ์š”์•ฝ ์™„๋ฃŒ ํ›„ ์•Œ๋ฆผ ์ „์†ก
telegram.send_summary_report(combined_summary, stats)
telegram.send_file("twitter_summary_report.html")

โœ‰๏ธ ์ด๋ฉ”์ผ ์•Œ๋ฆผ

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication

class EmailNotifier:
    def __init__(self, smtp_server, smtp_port, sender_email, sender_password):
        """
        ์ด๋ฉ”์ผ ์•Œ๋ฆผ ์ดˆ๊ธฐํ™”
        
        Args:
            smtp_server: SMTP ์„œ๋ฒ„ (์˜ˆ: smtp.gmail.com)
            smtp_port: ํฌํŠธ ๋ฒˆํ˜ธ (์ผ๋ฐ˜์ ์œผ๋กœ 587)
            sender_email: ๋ฐœ์‹ ์ž ์ด๋ฉ”์ผ
            sender_password: ์ด๋ฉ”์ผ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋˜๋Š” ์•ฑ ๋น„๋ฐ€๋ฒˆํ˜ธ
        """
        self.smtp_server = smtp_server
        self.smtp_port = smtp_port
        self.sender_email = sender_email
        self.sender_password = sender_password
    
    def send_email(self, recipient_email, subject, html_content, attachments=None):
        """
        ์ด๋ฉ”์ผ ์ „์†ก
        
        Args:
            recipient_email: ์ˆ˜์‹ ์ž ์ด๋ฉ”์ผ
            subject: ์ œ๋ชฉ
            html_content: HTML ๋ณธ๋ฌธ
            attachments: ์ฒจ๋ถ€ ํŒŒ์ผ ๋ฆฌ์ŠคํŠธ
        """
        msg = MIMEMultipart('alternative')
        msg['Subject'] = subject
        msg['From'] = self.sender_email
        msg['To'] = recipient_email
        
        # HTML ๋ณธ๋ฌธ ์ถ”๊ฐ€
        html_part = MIMEText(html_content, 'html')
        msg.attach(html_part)
        
        # ์ฒจ๋ถ€ ํŒŒ์ผ ์ถ”๊ฐ€
        if attachments:
            for file_path in attachments:
                with open(file_path, 'rb') as f:
                    attachment = MIMEApplication(f.read())
                    attachment.add_header(
                        'Content-Disposition',
                        'attachment',
                        filename=file_path.split('/')[-1]
                    )
                    msg.attach(attachment)
        
        try:
            # SMTP ์„œ๋ฒ„ ์—ฐ๊ฒฐ ๋ฐ ์ „์†ก
            with smtplib.SMTP(self.smtp_server, self.smtp_port) as server:
                server.starttls()
                server.login(self.sender_email, self.sender_password)
                server.send_message(msg)
            
            print(f"โœ… ์ด๋ฉ”์ผ ์ „์†ก ์™„๋ฃŒ: {recipient_email}")
        
        except Exception as e:
            print(f"โŒ ์ด๋ฉ”์ผ ์ „์†ก ์‹คํŒจ: {e}")
    
    def send_summary_report(self, recipient_email, summary_data, sentiment_stats, report_file):
        """์š”์•ฝ ๋ฆฌํฌํŠธ ์ด๋ฉ”์ผ ์ „์†ก"""
        subject = f"๐Ÿฆ ํŠธ์œ„ํ„ฐ ์š”์•ฝ ๋ฆฌํฌํŠธ - {datetime.now().strftime('%Y-%m-%d')}"
        
        html_content = f"""
        <html>
        <body style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
            <div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); 
                        color: white; padding: 20px; border-radius: 10px;">
                <h1>๐Ÿฆ ํŠธ์œ„ํ„ฐ ์ž๋™ ์š”์•ฝ ๋ฆฌํฌํŠธ</h1>
                <p>{datetime.now().strftime('%Y๋…„ %m์›” %d์ผ %H:%M')}</p>
            </div>
            
            <div style="padding: 20px; background: #f5f5f5; margin-top: 20px; border-radius: 10px;">
                <h2>๐Ÿ“ ํ•ต์‹ฌ ์š”์•ฝ</h2>
                <p style="line-height: 1.6;">{summary_data['summary']}</p>
            </div>
            
            <div style="padding: 20px; margin-top: 20px;">
                <h2>๐Ÿ˜Š ๊ฐ์„ฑ ๋ถ„์„ ๊ฒฐ๊ณผ</h2>
                <table style="width: 100%; text-align: center;">
                    <tr>
                        <td style="padding: 10px; background: #d1fae5; border-radius: 5px;">
                            <strong>๊ธ์ •</strong><br>
                            {sentiment_stats['positive']['ratio']*100:.1f}%
                        </td>
                        <td style="padding: 10px; background: #e5e7eb; border-radius: 5px;">
                            <strong>์ค‘๋ฆฝ</strong><br>
                            {sentiment_stats['neutral']['ratio']*100:.1f}%
                        </td>
                        <td style="padding: 10px; background: #fee2e2; border-radius: 5px;">
                            <strong>๋ถ€์ •</strong><br>
                            {sentiment_stats['negative']['ratio']*100:.1f}%
                        </td>
                    </tr>
                </table>
            </div>
            
            <div style="text-align: center; margin-top: 30px; color: #6b7280;">
                <p>์ƒ์„ธ ๋ฆฌํฌํŠธ๋Š” ์ฒจ๋ถ€ ํŒŒ์ผ์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”!</p>
                <p>Powered by Python & AI ๐Ÿค–</p>
            </div>
        </body>
        </html>
        """
        
        self.send_email(
            recipient_email,
            subject,
            html_content,
            attachments=[report_file]
        )

# ์‚ฌ์šฉ ์˜ˆ์‹œ
email_notifier = EmailNotifier(
    smtp_server='smtp.gmail.com',
    smtp_port=587,
    sender_email=os.getenv('SENDER_EMAIL'),
    sender_password=os.getenv('EMAIL_PASSWORD')
)

email_notifier.send_summary_report(
    recipient_email='your@email.com',
    summary_data=combined_summary,
    sentiment_stats=stats,
    report_file='twitter_summary_report.html'
)

โš ๏ธ Gmail ์‚ฌ์šฉ ์‹œ ์ฃผ์˜์‚ฌํ•ญ: โ€ข 2๋‹จ๊ณ„ ์ธ์ฆ์„ ํ™œ์„ฑํ™”ํ•˜๊ณ  '์•ฑ ๋น„๋ฐ€๋ฒˆํ˜ธ'๋ฅผ ์ƒ์„ฑํ•ด์•ผ ํ•ด์š”
โ€ข Google ๊ณ„์ • ์„ค์ • โ†’ ๋ณด์•ˆ โ†’ ์•ฑ ๋น„๋ฐ€๋ฒˆํ˜ธ์—์„œ ์ƒ์„ฑ ๊ฐ€๋Šฅ
โ€ข ์ผ๋ฐ˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ๋Š” ๋กœ๊ทธ์ธ์ด ์•ˆ ๋  ์ˆ˜ ์žˆ์–ด์š”!

๐ŸŽ“ ์‹ค์ „ ํ™œ์šฉ ์‚ฌ๋ก€ ๋ฐ ํŒ

์ด์ œ ์‹ค์ œ๋กœ ์–ด๋–ป๊ฒŒ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๊ตฌ์ฒด์ ์ธ ์˜ˆ์‹œ๋“ค์„ ์•Œ๋ ค๋“œ๋ฆด๊ฒŒ์š” ใ…Žใ…Ž

๐Ÿ’ผ ๋น„์ฆˆ๋‹ˆ์Šค ํ™œ์šฉ ์‚ฌ๋ก€

1. ๋ธŒ๋žœ๋“œ ๋ชจ๋‹ˆํ„ฐ๋ง ๋ด‡
์ž์‚ฌ ๋ธŒ๋žœ๋“œ๋‚˜ ์ œํ’ˆ๋ช…์„ ์‹ค์‹œ๊ฐ„์œผ๋กœ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๊ณ , ๊ณ ๊ฐ ๋ฐ˜์‘์„ ์š”์•ฝํ•ด์„œ ๋งˆ์ผ€ํŒ…ํŒ€์— ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ์–ด์š”. ํŠนํžˆ ์‹ ์ œํ’ˆ ์ถœ์‹œ ํ›„ ์ดˆ๊ธฐ ๋ฐ˜์‘์„ ๋น ๋ฅด๊ฒŒ ํŒŒ์•…ํ•˜๋Š” ๋ฐ ์œ ์šฉํ•˜์ฃ !

# ๋ธŒ๋žœ๋“œ ๋ชจ๋‹ˆํ„ฐ๋ง ์˜ˆ์‹œ
brand_bot = TwitterSummaryBot(
    search_query="(์šฐ๋ฆฌํšŒ์‚ฌ OR ์šฐ๋ฆฌ์ œํ’ˆ) -is:retweet lang:ko",
    max_tweets=100
)

# 1์‹œ๊ฐ„๋งˆ๋‹ค ์ฒดํฌ
bot.start_scheduler(['09:00', '12:00', '15:00', '18:00', '21:00'])

2. ๊ฒฝ์Ÿ์‚ฌ ๋ถ„์„ ๋ด‡
๊ฒฝ์Ÿ์‚ฌ์˜ ๋งˆ์ผ€ํŒ… ํ™œ๋™๊ณผ ๊ณ ๊ฐ ๋ฐ˜์‘์„ ์ถ”์ ํ•ด์„œ ์šฐ๋ฆฌ ์ „๋žต์— ๋ฐ˜์˜ํ•  ์ˆ˜ ์žˆ์–ด์š”.

competitor_bot = TwitterSummaryBot(
    search_query="(๊ฒฝ์Ÿ์‚ฌA OR ๊ฒฝ์Ÿ์‚ฌB) (์‹ ์ œํ’ˆ OR ์ถœ์‹œ OR ์ด๋ฒคํŠธ) -is:retweet",
    max_tweets=50
)

3. ์—…๊ณ„ ํŠธ๋ Œ๋“œ ๋ถ„์„
ํŠน์ • ์‚ฐ์—…์ด๋‚˜ ๊ธฐ์ˆ  ๋ถ„์•ผ์˜ ์ตœ์‹  ํŠธ๋ Œ๋“œ๋ฅผ ๋งค์ผ ์š”์•ฝํ•ด์„œ ๋ฐ›์•„๋ณผ ์ˆ˜ ์žˆ์–ด์š”. ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ๋„ ์ด๋Ÿฐ ํŠธ๋ Œ๋“œ ์ •๋ณด๋ฅผ ํ™œ์šฉํ•ด์„œ ์ƒˆ๋กœ์šด ์žฌ๋Šฅ ์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ๋ฐœ๊ตดํ•  ์ˆ˜ ์žˆ๊ฒ ์ฃ ?

trend_bot = TwitterSummaryBot(
    search_query="(AI OR ์ธ๊ณต์ง€๋Šฅ OR ๋จธ์‹ ๋Ÿฌ๋‹) (ํŠธ๋ Œ๋“œ OR ๊ธฐ์ˆ  OR ๊ฐœ๋ฐœ) -is:retweet lang:ko",
    max_tweets=80
)

๐ŸŽฏ ๊ฐœ์ธ ํ™œ์šฉ ์‚ฌ๋ก€

1. ๊ด€์‹ฌ ๋ถ„์•ผ ํ๋ ˆ์ด์…˜
๋‚ด๊ฐ€ ๊ด€์‹ฌ ์žˆ๋Š” ์ฃผ์ œ์˜ ํ•ต์‹ฌ ์ •๋ณด๋งŒ ๊ณจ๋ผ์„œ ๋งค์ผ ์•„์นจ ๋ฐ›์•„๋ณผ ์ˆ˜ ์žˆ์–ด์š”. ๋‰ด์Šค๋ ˆํ„ฐ์ฒ˜๋Ÿผ์š”!

2. ํˆฌ์ž ์ •๋ณด ๋ชจ๋‹ˆํ„ฐ๋ง
์ฃผ์‹, ์ฝ”์ธ ๋“ฑ ํˆฌ์ž ๊ด€๋ จ ์ •๋ณด๋ฅผ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์š”์•ฝํ•ด์„œ ๋ฐ›์•„๋ณด๋ฉด ๋น ๋ฅธ ์˜์‚ฌ๊ฒฐ์ •์— ๋„์›€์ด ๋˜์ฃ .

3. ํ•™์Šต ์ž๋ฃŒ ์ˆ˜์ง‘
ํ”„๋กœ๊ทธ๋ž˜๋ฐ, ๋””์ž์ธ ๋“ฑ ํ•™์Šตํ•˜๊ณ  ์‹ถ์€ ๋ถ„์•ผ์˜ ํŒ๊ณผ ์ž๋ฃŒ๋ฅผ ์ž๋™์œผ๋กœ ์ˆ˜์ง‘ํ•˜๊ณ  ์š”์•ฝํ•  ์ˆ˜ ์žˆ์–ด์š”.

๐Ÿ’ก ํšจ๊ณผ์ ์ธ ๊ฒ€์ƒ‰ ์ฟผ๋ฆฌ ์ž‘์„ฑ ํŒ: ์ •ํ™•๋„๋ฅผ ๋†’์ด๋ ค๋ฉด:
โ€ข ๋ถˆํ•„์š”ํ•œ ํ‚ค์›Œ๋“œ๋Š” ๋งˆ์ด๋„ˆ์Šค(-) ๊ธฐํ˜ธ๋กœ ์ œ์™ธ
โ€ข ๋ฆฌํŠธ์œ— ์ œ์™ธ: -is:retweet
โ€ข ์–ธ์–ด ์ง€์ •: lang:ko ๋˜๋Š” lang:en

๋ฒ”์œ„๋ฅผ ๋„“ํžˆ๋ ค๋ฉด:
โ€ข OR ์—ฐ์‚ฐ์ž ํ™œ์šฉ: ํŒŒ์ด์ฌ OR Python OR ํŒŒ์ด์„ 
โ€ข ์œ ์‚ฌ ํ‚ค์›Œ๋“œ ํฌํ•จ: (AI OR ์ธ๊ณต์ง€๋Šฅ OR ๋จธ์‹ ๋Ÿฌ๋‹)

ํŠน์ • ๊ณ„์ • ๋ชจ๋‹ˆํ„ฐ๋ง:
โ€ข from:username: ํŠน์ • ์‚ฌ์šฉ์ž์˜ ํŠธ์œ—๋งŒ
โ€ข to:username: ํŠน์ • ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด๋‚ธ ๋ฉ˜์…˜

์ธ๊ธฐ ํŠธ์œ—๋งŒ:
โ€ข min_faves:100: ์ข‹์•„์š” 100๊ฐœ ์ด์ƒ
โ€ข min_retweets:50: ๋ฆฌํŠธ์œ— 50๊ฐœ ์ด์ƒ

โš ๏ธ ์ฃผ์˜์‚ฌํ•ญ ๋ฐ ์ œํ•œ์‚ฌํ•ญ

์™„๋ฒฝํ•ด ๋ณด์ด์ง€๋งŒ ๋ช‡ ๊ฐ€์ง€ ์ฃผ์˜ํ•  ์ ๋“ค์ด ์žˆ์–ด์š” ใ… ใ… 

๐Ÿšจ ํŠธ์œ„ํ„ฐ API ์ œํ•œ์‚ฌํ•ญ: ๋ฌด๋ฃŒ ํ‹ฐ์–ด (Free Tier):
โ€ข ์›” 1,500๊ฐœ ํŠธ์œ— ์ฝ๊ธฐ ์ œํ•œ
โ€ข ์›” 50๊ฐœ ํŠธ์œ— ์ž‘์„ฑ ์ œํ•œ
โ€ข ์•ฑ 1๊ฐœ๋งŒ ์ƒ์„ฑ ๊ฐ€๋Šฅ

Basic ํ”Œ๋žœ ($100/์›”):
โ€ข ์›” 10,000๊ฐœ ํŠธ์œ— ์ฝ๊ธฐ
โ€ข ์›” 1,000๊ฐœ ํŠธ์œ— ์ž‘์„ฑ
โ€ข ์•ฑ 2๊ฐœ ์ƒ์„ฑ ๊ฐ€๋Šฅ

Pro ํ”Œ๋žœ ($5,000/์›”):
โ€ข ์›” 1,000,000๊ฐœ ํŠธ์œ— ์ฝ๊ธฐ
โ€ข ๋ฌด์ œํ•œ ํŠธ์œ— ์ž‘์„ฑ
โ€ข ์•ฑ ๋ฌด์ œํ•œ

๐Ÿ’ก ํ•ด๊ฒฐ์ฑ…: ๋ฌด๋ฃŒ ํ‹ฐ์–ด๋กœ ์‹œ์ž‘ํ•ด์„œ ํ•„์š”์— ๋”ฐ๋ผ ์—…๊ทธ๋ ˆ์ด๋“œํ•˜๊ฑฐ๋‚˜, ์—ฌ๋Ÿฌ ๊ณ„์ •์„ ๋ฒˆ๊ฐˆ์•„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์–ด์š” (๊ทœ์ • ์œ„๋ฐ˜ ์ฃผ์˜!).

โš–๏ธ ๋ฒ•์ /์œค๋ฆฌ์  ๊ณ ๋ ค์‚ฌํ•ญ: โ€ข ๊ฐœ์ธ์ •๋ณด ๋ณดํ˜ธ: ์ˆ˜์ง‘ํ•œ ํŠธ์œ— ๋ฐ์ดํ„ฐ๋ฅผ ์™ธ๋ถ€์— ๊ณต์œ ํ•˜๊ฑฐ๋‚˜ ์ƒ์—…์ ์œผ๋กœ ์ด์šฉํ•  ๋•Œ๋Š” ์ฃผ์˜
โ€ข ์ €์ž‘๊ถŒ: ํŠธ์œ— ๋‚ด์šฉ๋„ ์ €์ž‘๋ฌผ์ด๋ฏ€๋กœ ๋ฌด๋‹จ ๋ณต์ œ/๋ฐฐํฌ ๊ธˆ์ง€
โ€ข ์ŠคํŒธ ๋ฐฉ์ง€: ์ž๋™ํ™”๋œ ๋Œ€๋Ÿ‰ ์ˆ˜์ง‘์€ ํŠธ์œ„ํ„ฐ ์ •์ฑ… ์œ„๋ฐ˜ ๊ฐ€๋Šฅ
โ€ข Rate Limiting: API ํ˜ธ์ถœ ์ œํ•œ์„ ์ง€ํ‚ค์ง€ ์•Š์œผ๋ฉด ๊ณ„์ • ์ •์ง€๋  ์ˆ˜ ์žˆ์Œ
โ€ข ๋ด‡ ํ‘œ์‹œ: ์ž๋™ํ™”๋œ ๊ณ„์ •์ž„์„ ๋ช…์‹œํ•˜๋Š” ๊ฒŒ ์ข‹์•„์š”

๐Ÿ”ง ์„ฑ๋Šฅ ์ตœ์ ํ™” ํŒ

1. ์บ์‹ฑ ํ™œ์šฉ
์ด๋ฏธ ์ฒ˜๋ฆฌํ•œ ํŠธ์œ—์€ ๋‹ค์‹œ ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š๋„๋ก ์บ์‹ฑ ์‹œ์Šคํ…œ์„ ๊ตฌ์ถ•ํ•˜์„ธ์š”:

import json
import hashlib

class TweetCache:
    def __init__(self, cache_file='tweet_cache.json'):
        self.cache_file = cache_file
        self.cache = self._load_cache()
    
    def _load_cache(self):
        try:
            with open(self.cache_file, 'r') as f:
                return json.load(f)
        except FileNotFoundError:
            return {}
    
    def _save_cache(self):
        with open(self.cache_file, 'w') as f:
            json.dump(self.cache, f)
    
    def is_processed(self, tweet_id):
        return str(tweet_id) in self.cache
    
    def mark_processed(self, tweet_id, summary):
        self.cache[str(tweet_id)] = {
            'summary': summary,
            'timestamp': datetime.now().isoformat()
        }
        self._save_cache()

# ์‚ฌ์šฉ
cache = TweetCache()
for tweet in tweets:
    if not cache.is_processed(tweet['id']):
        summary = summarizer.summarize_text(tweet['cleaned_text'])
        cache.mark_processed(tweet['id'], summary)

2. ๋ฐฐ์น˜ ์ฒ˜๋ฆฌ
์—ฌ๋Ÿฌ ํŠธ์œ—์„ ํ•œ ๋ฒˆ์— ์ฒ˜๋ฆฌํ•˜๋ฉด ๋” ํšจ์œจ์ ์ด์—์š”:

def batch_summarize(tweets, batch_size=10):
    """๋ฐฐ์น˜ ๋‹จ์œ„๋กœ ์š”์•ฝ ์ฒ˜๋ฆฌ"""
    summaries = []
    
    for i in range(0, len(tweets), batch_size):
        batch = tweets[i:i+batch_size]
        combined_text = " [SEP] ".join([t['cleaned_text'] for t in batch])
        
        summary = summarizer.summarize_text(combined_text)
        summaries.append(summary)
    
    return summaries

3. ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ
asyncio๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์—ฌ๋Ÿฌ ์ž‘์—…์„ ๋™์‹œ์— ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด์š”:

import asyncio

async def process_tweet_async(tweet):
    """๋น„๋™๊ธฐ ํŠธ์œ— ์ฒ˜๋ฆฌ"""
    summary = await asyncio.to_thread(
        summarizer.summarize_text,
        tweet['cleaned_text']
    )
    return summary

async def process_all_tweets(tweets):
    """๋ชจ๋“  ํŠธ์œ— ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ"""
    tasks = [process_tweet_async(tweet) for tweet in tweets]
    summaries = await asyncio.gather(*tasks)
    return summaries

# ์‚ฌ์šฉ
summaries = asyncio.run(process_all_tweets(processed_tweets))

๐Ÿš€ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ: ๋งž์ถคํ˜• ์š”์•ฝ ์Šคํƒ€์ผ

์‚ฌ์šฉ์ž๋งˆ๋‹ค ์›ํ•˜๋Š” ์š”์•ฝ ์Šคํƒ€์ผ์ด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์ž–์•„์š”? ์š”์•ฝ ๊ธธ์ด๋‚˜ ํ†ค์„ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด๋ด…์‹œ๋‹ค!

class CustomSummarizer:
    def __init__(self, model_name='facebook/bart-large-cnn'):
        self.summarizer = TweetSummarizer(model_name)
    
    def summarize_with_style(self, text, style='balanced'):
        """
        ์Šคํƒ€์ผ๋ณ„ ์š”์•ฝ ์ƒ์„ฑ
        
        Args:
            text: ์š”์•ฝํ•  ํ…์ŠคํŠธ
            style: 'brief' (๊ฐ„๋‹จ), 'balanced' (๊ท ํ˜•), 'detailed' (์ƒ์„ธ)
        
        Returns:
            ์š”์•ฝ ํ…์ŠคํŠธ
        """
        style_configs = {
            'brief': {
                'max_length': 50,
                'min_length': 20,
                'description': 'ํ•ต์‹ฌ๋งŒ ๊ฐ„๋‹จํ•˜๊ฒŒ'
            },
            'balanced': {
                'max_length': 130,
                'min_length': 50,
                'description': '์ ๋‹นํ•œ ๊ธธ์ด๋กœ'
            },
            'detailed': {
                'max_length': 250,
                'min_length': 100,
                'description': '์ž์„ธํ•˜๊ฒŒ'
            }
        }
        
        config = style_configs.get(style, style_configs['balanced'])
        
        summary = self.summarizer.summarize_text(
            text,
            max_length=config['max_length'],
            min_length=config['min_length']
        )
        
        return summary
    
    def summarize_with_bullets(self, tweets, max_bullets=5):
        """
        ๋ถˆ๋ฆฟ ํฌ์ธํŠธ ํ˜•์‹์œผ๋กœ ์š”์•ฝ
        """
        # ์ค‘์š”๋„ ์ˆœ์œผ๋กœ ์ •๋ ฌ (์ข‹์•„์š” + ๋ฆฌํŠธ์œ—)
        sorted_tweets = sorted(
            tweets,
            key=lambda x: x['likes'] + x['retweets'],
            reverse=True
        )[:max_bullets]
        
        bullets = []
        for tweet in sorted_tweets:
            summary = self.summarizer.summarize_text(
                tweet['cleaned_text'],
                max_length=80,
                min_length=30
            )
            bullets.append(f"โ€ข {summary}")
        
        return "\n".join(bullets)
    
    def summarize_with_categories(self, tweets):
        """
        ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„๋กœ ๋ถ„๋ฅ˜ํ•ด์„œ ์š”์•ฝ
        """
        # ๊ฐ„๋‹จํ•œ ํ‚ค์›Œ๋“œ ๊ธฐ๋ฐ˜ ๋ถ„๋ฅ˜ (์‹ค์ œ๋กœ๋Š” ๋” ์ •๊ตํ•œ ๋ถ„๋ฅ˜ ํ•„์š”)
        categories = {
            '๊ธฐ์ˆ ': ['๊ธฐ์ˆ ', '๊ฐœ๋ฐœ', 'AI', 'ํ”„๋กœ๊ทธ๋ž˜๋ฐ', '์ฝ”๋”ฉ'],
            '๋น„์ฆˆ๋‹ˆ์Šค': ['๋น„์ฆˆ๋‹ˆ์Šค', '๋งˆ์ผ€ํŒ…', '์Šคํƒ€ํŠธ์—…', 'ํˆฌ์ž'],
            '๋‰ด์Šค': ['๋‰ด์Šค', '์†๋ณด', '๋ฐœํ‘œ', '๊ณต์‹'],
            '๊ธฐํƒ€': []
        }
        
        categorized = {cat: [] for cat in categories.keys()}
        
        for tweet in tweets:
            text = tweet['cleaned_text'].lower()
            assigned = False
            
            for category, keywords in categories.items():
                if any(keyword in text for keyword in keywords):
                    categorized[category].append(tweet)
                    assigned = True
                    break
            
            if not assigned:
                categorized['๊ธฐํƒ€'].append(tweet)
        
        # ๊ฐ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ์š”์•ฝ
        result = {}
        for category, cat_tweets in categorized.items():
            if cat_tweets:
                combined_text = " ".join([t['cleaned_text'] for t in cat_tweets])
                summary = self.summarizer.summarize_text(combined_text)
                result[category] = {
                    'summary': summary,
                    'count': len(cat_tweets)
                }
        
        return result

# ์‚ฌ์šฉ ์˜ˆ์‹œ
custom_summarizer = CustomSummarizer()

# ์Šคํƒ€์ผ๋ณ„ ์š”์•ฝ
brief_summary = custom_summarizer.summarize_with_style(combined_text, style='brief')
print("๐Ÿ“Œ ๊ฐ„๋‹จ ์š”์•ฝ:", brief_summary)

detailed_summary = custom_summarizer.summarize_with_style(combined_text, style='detailed')
print("๐Ÿ“ ์ƒ์„ธ ์š”์•ฝ:", detailed_summary)

# ๋ถˆ๋ฆฟ ํฌ์ธํŠธ ์š”์•ฝ
bullets = custom_summarizer.summarize_with_bullets(processed_tweets, max_bullets=5)
print("\n๐ŸŽฏ ํ•ต์‹ฌ ํฌ์ธํŠธ:")
print(bullets)

# ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ์š”์•ฝ
categorized = custom_summarizer.summarize_with_categories(processed_tweets)
print("\n๐Ÿ“‚ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ์š”์•ฝ:")
for category, data in categorized.items():
    print(f"\n[{category}] ({data['count']}๊ฐœ ํŠธ์œ—)")
    print(data['summary'])

๐Ÿ“Š ๋ฐ์ดํ„ฐ ๋ถ„์„ ๋ฐ ์‹œ๊ฐํ™”

์ˆ˜์ง‘ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถ„์„ํ•ด์„œ ์ธ์‚ฌ์ดํŠธ๋ฅผ ์–ป๋Š” ๊ฒƒ๋„ ์ค‘์š”ํ•˜์ฃ ! ๊ฐ„๋‹จํ•œ ํ†ต๊ณ„์™€ ์‹œ๊ฐํ™” ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด๋ด…์‹œ๋‹ค:

import pandas as pd
from collections import Counter
import re

class TweetAnalyzer:
    def __init__(self, tweets):
        self.tweets = tweets
        self.df = pd.DataFrame(tweets)
    
    def get_basic_stats(self):
        """๊ธฐ๋ณธ ํ†ต๊ณ„"""
        stats = {
            'total_tweets': len(self.tweets),
            'total_likes': self.df['likes'].sum(),
            'total_retweets': self.df['retweets'].sum(),
            'avg_likes': self.df['likes'].mean(),
            'avg_retweets': self.df['retweets'].mean(),
            'most_liked': self.df.loc[self.df['likes'].idxmax()].to_dict() if len(self.df) > 0 else None,
            'most_retweeted': self.df.loc[self.df['retweets'].idxmax()].to_dict() if len(self.df) > 0 else None
        }
        return stats
    
    def get_top_hashtags(self, top_n=10):
        """์ธ๊ธฐ ํ•ด์‹œํƒœ๊ทธ ์ถ”์ถœ"""
        all_hashtags = []
        
        for tweet in self.tweets:
            hashtags = re.findall(r'#(\w+)', tweet['text'])
            all_hashtags.extend(hashtags)
        
        counter = Counter(all_hashtags)
        return counter.most_common(top_n)
    
    def get_top_mentions(self, top_n=10):
        """์ž์ฃผ ์–ธ๊ธ‰๋œ ์‚ฌ์šฉ์ž"""
        all_mentions = []
        
        for tweet in self.tweets:
            mentions = re.findall(r'@(\w+)', tweet['text'])
            all_mentions.extend(mentions)
        
        counter = Counter(all_mentions)
        return counter.most_common(top_n)
    
    def get_hourly_distribution(self):
        """์‹œ๊ฐ„๋Œ€๋ณ„ ํŠธ์œ— ๋ถ„ํฌ"""
        self.df['hour'] = pd.to_datetime(self.df['created_at']).dt.hour
        hourly_counts = self.df['hour'].value_counts().sort_index()
        return hourly_counts.to_dict()
    
    def get_engagement_rate(self):
        """์ฐธ์—ฌ์œจ ๊ณ„์‚ฐ (์ข‹์•„์š” + ๋ฆฌํŠธ์œ— + ๋Œ“๊ธ€)"""
        self.df['engagement'] = self.df['likes'] + self.df['retweets'] + self.df['replies']
        self.df['engagement_rate'] = self.df['engagement'] / len(self.df)
        
        return {
            'avg_engagement': self.df['engagement'].mean(),
            'top_engaged': self.df.nlargest(5, 'engagement')[['text', 'engagement']].to_dict('records')
        }
    
    def generate_word_cloud_data(self):
        """์›Œ๋“œ ํด๋ผ์šฐ๋“œ์šฉ ๋ฐ์ดํ„ฐ ์ƒ์„ฑ"""
        all_words = []
        
        for tweet in self.tweets:
            words = tweet['cleaned_text'].split()
            # ๋ถˆ์šฉ์–ด ์ œ๊ฑฐ (๊ฐ„๋‹จํ•œ ์˜ˆ์‹œ)
            stopwords = ['์ด', '๊ทธ', '์ €', '๊ฒƒ', '์ˆ˜', '๋“ฑ', '๋ฐ', '๋ฅผ', '์„', '๊ฐ€', '์ด']
            words = [w for w in words if w not in stopwords and len(w) > 1]
            all_words.extend(words)
        
        counter = Counter(all_words)
        return counter.most_common(50)

# ์‚ฌ์šฉ ์˜ˆ์‹œ
analyzer = TweetAnalyzer(processed_tweets)

# ๊ธฐ๋ณธ ํ†ต๊ณ„
stats = analyzer.get_basic_stats()
print("๐Ÿ“Š ๊ธฐ๋ณธ ํ†ต๊ณ„:")
print(f"์ด ํŠธ์œ— ์ˆ˜: {stats['total_tweets']}๊ฐœ")
print(f"์ด ์ข‹์•„์š”: {stats['total_likes']:,}๊ฐœ")
print(f"ํ‰๊ท  ์ข‹์•„์š”: {stats['avg_likes']:.1f}๊ฐœ")

# ์ธ๊ธฐ ํ•ด์‹œํƒœ๊ทธ
top_hashtags = analyzer.get_top_hashtags(10)
print("\n#๏ธโƒฃ ์ธ๊ธฐ ํ•ด์‹œํƒœ๊ทธ TOP 10:")
for i, (tag, count) in enumerate(top_hashtags, 1):
    print(f"{i}. #{tag} ({count}ํšŒ)")

# ์‹œ๊ฐ„๋Œ€๋ณ„ ๋ถ„ํฌ
hourly = analyzer.get_hourly_distribution()
print("\nโฐ ์‹œ๊ฐ„๋Œ€๋ณ„ ํŠธ์œ— ๋ถ„ํฌ:")
for hour, count in sorted(hourly.items()):
    print(f"{hour:02d}์‹œ: {'โ–ˆ' * (count // 2)} ({count}๊ฐœ)")

# ์ฐธ์—ฌ์œจ ๋ถ„์„
engagement = analyzer.get_engagement_rate()
print(f"\n๐Ÿ’ฌ ํ‰๊ท  ์ฐธ์—ฌ์œจ: {engagement['avg_engagement']:.1f}")
print("\n๐Ÿ”ฅ ์ฐธ์—ฌ์œจ ๋†’์€ ํŠธ์œ— TOP 5:")
for i, tweet in enumerate(engagement['top_engaged'], 1):
    print(f"{i}. {tweet['text'][:80]}... (์ฐธ์—ฌ: {tweet['engagement']})")

# ์›Œ๋“œ ํด๋ผ์šฐ๋“œ ๋ฐ์ดํ„ฐ
word_freq = analyzer.generate_word_cloud_data()
print("\n๐Ÿ“ ์ž์ฃผ ๋‚˜์˜จ ๋‹จ์–ด TOP 20:")
for word, freq in word_freq[:20]:
    print(f"{word}: {freq}ํšŒ")

๐ŸŽ‰ ๋งˆ๋ฌด๋ฆฌ ๋ฐ ๋‹ค์Œ ๋‹จ๊ณ„

์™€! ์—ฌ๊ธฐ๊นŒ์ง€ ์˜ค๋А๋ผ ์ˆ˜๊ณ  ๋งŽ์œผ์…จ์–ด์š” ใ…‹ใ…‹ใ…‹ ์ด์ œ ์—ฌ๋Ÿฌ๋ถ„๋งŒ์˜ ํŠธ์œ„ํ„ฐ ์ž๋™ ์š”์•ฝ๋ด‡์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  ์ง€์‹์„ ๊ฐ–์ถ”์…จ์Šต๋‹ˆ๋‹ค ๐ŸŽŠ

โœ… ์šฐ๋ฆฌ๊ฐ€ ๋ฐฐ์šด ๋‚ด์šฉ ์ •๋ฆฌ

1. ํŠธ์œ„ํ„ฐ API ์—ฐ๋™: Tweepy๋ฅผ ์‚ฌ์šฉํ•œ ํŠธ์œ— ์ˆ˜์ง‘
2. ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ: ํ…์ŠคํŠธ ์ •์ œ ๋ฐ ๋…ธ์ด์ฆˆ ์ œ๊ฑฐ
3. AI ์š”์•ฝ: Transformers ๋ชจ๋ธ์„ ํ™œ์šฉํ•œ ์ž๋™ ์š”์•ฝ
4. ๊ฐ์„ฑ ๋ถ„์„: ํŠธ์œ—์˜ ๊ธ์ •/๋ถ€์ •/์ค‘๋ฆฝ ํŒ๋‹จ
5. ์ž๋™ํ™”: ์Šค์ผ€์ค„๋ง์œผ๋กœ ์ •๊ธฐ์  ์‹คํ–‰
6. ์•Œ๋ฆผ ์‹œ์Šคํ…œ: ํ…”๋ ˆ๊ทธ๋žจ/์ด๋ฉ”์ผ ์•Œ๋ฆผ
7. ๋ฐฐํฌ: ํด๋ผ์šฐ๋“œ ์„œ๋ฒ„์—์„œ 24์‹œ๊ฐ„ ์šด์˜
8. ๋ฐ์ดํ„ฐ ๋ถ„์„: ํ†ต๊ณ„ ๋ฐ ์ธ์‚ฌ์ดํŠธ ๋„์ถœ

๐Ÿš€ ๋” ๋ฐœ์ „์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ๋ฐฉํ–ฅ

1. ์›น ๋Œ€์‹œ๋ณด๋“œ ๊ตฌ์ถ•
Flask๋‚˜ Django๋กœ ์›น ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์„œ ์‹ค์‹œ๊ฐ„์œผ๋กœ ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค์–ด๋ณด์„ธ์š”!

2. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—ฐ๋™
PostgreSQL์ด๋‚˜ MongoDB์— ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•ด์„œ ์žฅ๊ธฐ์ ์ธ ํŠธ๋ Œ๋“œ ๋ถ„์„์„ ํ•  ์ˆ˜ ์žˆ์–ด์š”.

3. ๋จธ์‹ ๋Ÿฌ๋‹ ๋ชจ๋ธ ํŒŒ์ธํŠœ๋‹
ํŠน์ • ๋„๋ฉ”์ธ์— ํŠนํ™”๋œ ์š”์•ฝ ๋ชจ๋ธ์„ ์ง์ ‘ ํ•™์Šต์‹œ์ผœ๋ณด์„ธ์š”. ์„ฑ๋Šฅ์ด ํ›จ์”ฌ ์ข‹์•„์งˆ ๊ฑฐ์˜ˆ์š”!

4. ๋‹ค์ค‘ SNS ์ง€์›
ํŠธ์œ„ํ„ฐ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ธ์Šคํƒ€๊ทธ๋žจ, ํŽ˜์ด์Šค๋ถ, ์œ ํŠœ๋ธŒ ๋Œ“๊ธ€ ๋“ฑ๋„ ํ•จ๊ป˜ ๋ถ„์„ํ•˜๋ฉด ๋” ํ’๋ถ€ํ•œ ์ธ์‚ฌ์ดํŠธ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์–ด์š”.

5. ์‹ค์‹œ๊ฐ„ ์ŠคํŠธ๋ฆฌ๋ฐ
ํŠธ์œ„ํ„ฐ Streaming API๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์‹ค์‹œ๊ฐ„์œผ๋กœ ํŠธ์œ—์„ ๋ฐ›์•„์„œ ์ฆ‰์‹œ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด์š”.

6. ์ด๋ฏธ์ง€/๋น„๋””์˜ค ๋ถ„์„
์ปดํ“จํ„ฐ ๋น„์ „ ๊ธฐ์ˆ ์„ ์ถ”๊ฐ€ํ•ด์„œ ํŠธ์œ—์— ์ฒจ๋ถ€๋œ ์ด๋ฏธ์ง€๋‚˜ ๋น„๋””์˜ค๋„ ๋ถ„์„ํ•ด๋ณด์„ธ์š”!

๐Ÿ’ก ํ•™์Šต ๋ฆฌ์†Œ์Šค ์ถ”์ฒœ: ๊ณต์‹ ๋ฌธ์„œ:
โ€ข Tweepy: https://docs.tweepy.org
โ€ข Hugging Face Transformers: https://huggingface.co/docs
โ€ข Twitter API: https://developer.twitter.com/en/docs

์˜จ๋ผ์ธ ๊ฐ•์˜:
โ€ข Coursera: Natural Language Processing Specialization
โ€ข Udemy: Python for NLP
โ€ข YouTube: ๋‹ค์–‘ํ•œ NLP ํŠœํ† ๋ฆฌ์–ผ

์ปค๋ฎค๋‹ˆํ‹ฐ:
โ€ข Reddit: r/MachineLearning, r/LanguageTechnology
โ€ข Stack Overflow: ๋ง‰ํž ๋•Œ ์งˆ๋ฌธํ•˜๊ธฐ
โ€ข GitHub: ์˜คํ”ˆ์†Œ์Šค ํ”„๋กœ์ ํŠธ ์ฐธ๊ณ ํ•˜๊ธฐ

๊ทธ๋ฆฌ๊ณ  ์žฌ๋Šฅ๋„ท์—์„œ๋„ AI/๋จธ์‹ ๋Ÿฌ๋‹ ๊ด€๋ จ ์žฌ๋Šฅ์„ ๊ฐ€์ง„ ์ „๋ฌธ๊ฐ€๋“ค์„ ๋งŒ๋‚  ์ˆ˜ ์žˆ์œผ๋‹ˆ, ๋ง‰ํžˆ๋Š” ๋ถ€๋ถ„์ด ์žˆ์œผ๋ฉด ๋„์›€์„ ๋ฐ›์•„๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์€ ๋ฐฉ๋ฒ•์ด์—์š”!

๐Ÿค ํ”„๋กœ์ ํŠธ ๊ณต์œ ํ•˜๊ธฐ

์—ฌ๋Ÿฌ๋ถ„์ด ๋งŒ๋“  ๋ด‡์„ GitHub์— ์˜ฌ๋ ค์„œ ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค๊ณผ ๊ณต์œ ํ•ด๋ณด์„ธ์š”! ์˜คํ”ˆ์†Œ์Šค๋กœ ๊ณต๊ฐœํ•˜๋ฉด ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž๋“ค์˜ ํ”ผ๋“œ๋ฐฑ๋„ ๋ฐ›์„ ์ˆ˜ ์žˆ๊ณ , ํฌํŠธํด๋ฆฌ์˜ค๋กœ๋„ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.

README.md์—๋Š” ๋‹ค์Œ ๋‚ด์šฉ์„ ํฌํ•จํ•˜๋ฉด ์ข‹์•„์š”:
โ€ข ํ”„๋กœ์ ํŠธ ์†Œ๊ฐœ ๋ฐ ๋ชฉ์ 
โ€ข ์„ค์น˜ ๋ฐฉ๋ฒ• (requirements.txt ํฌํ•จ)
โ€ข ์‚ฌ์šฉ ๋ฐฉ๋ฒ• ๋ฐ ์˜ˆ์‹œ
โ€ข ์ฃผ์š” ๊ธฐ๋Šฅ ์„ค๋ช…
โ€ข ์Šคํฌ๋ฆฐ์ƒท ๋˜๋Š” ๋ฐ๋ชจ ์˜์ƒ
โ€ข ๋ผ์ด์„ ์Šค ์ •๋ณด
โ€ข ๊ธฐ์—ฌ ๋ฐฉ๋ฒ• (Contributing Guidelines)

โš ๏ธ ๋งˆ์ง€๋ง‰ ๋‹น๋ถ€: โ€ข ์œค๋ฆฌ์  ์‚ฌ์šฉ: ์ˆ˜์ง‘ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์•…์šฉํ•˜์ง€ ๋งˆ์„ธ์š”
โ€ข ๊ฐœ์ธ์ •๋ณด ๋ณดํ˜ธ: ๋ฏผ๊ฐํ•œ ์ •๋ณด๋Š” ์ ˆ๋Œ€ ์ €์žฅํ•˜๊ฑฐ๋‚˜ ๊ณต์œ ํ•˜์ง€ ๋งˆ์„ธ์š”
โ€ข API ์ œํ•œ ์ค€์ˆ˜: ํŠธ์œ„ํ„ฐ ์ •์ฑ…์„ ๊ผญ ์ง€์ผœ์ฃผ์„ธ์š”
โ€ข ์ง€์†์ ์ธ ํ•™์Šต: AI ๊ธฐ์ˆ ์€ ๋น ๋ฅด๊ฒŒ ๋ฐœ์ „ํ•˜๋‹ˆ ๊ณ„์† ๊ณต๋ถ€ํ•˜์„ธ์š”
โ€ข ์ปค๋ฎค๋‹ˆํ‹ฐ ๊ธฐ์—ฌ: ๋ฐฐ์šด ๊ฒƒ์„ ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค๊ณผ ๋‚˜๋ˆ ์ฃผ์„ธ์š”!

๐ŸŽ‰ ํŠธ์œ„ํ„ฐ ์ž๋™ ์š”์•ฝ๋ด‡ ์™„์„ฑ! ์ด์ œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ฐฝ์˜๋ ฅ์„ ๋”ํ•ด๋ณด์„ธ์š” โœ“ API ์—ฐ๋™ โœ“ AI ์š”์•ฝ โœ“ ๊ฐ์„ฑ ๋ถ„์„ โœ“ ์ž๋™ํ™”

๐Ÿš€ ์ง€๊ธˆ ๋ฐ”๋กœ ์‹œ์ž‘ํ•ด๋ณด์„ธ์š”!

์ด ๊ธ€์—์„œ ๋ฐฐ์šด ๋‚ด์šฉ์„ ๋ฐ”ํƒ•์œผ๋กœ ์—ฌ๋Ÿฌ๋ถ„๋งŒ์˜ ๋…ํŠนํ•œ ํŠธ์œ„ํ„ฐ ๋ด‡์„ ๋งŒ๋“ค์–ด๋ณด์„ธ์š”.
๋ง‰ํžˆ๋Š” ๋ถ€๋ถ„์ด ์žˆ๋‹ค๋ฉด ์žฌ๋Šฅ๋„ท์—์„œ AI/๋จธ์‹ ๋Ÿฌ๋‹ ์ „๋ฌธ๊ฐ€๋“ค์˜ ๋„์›€์„ ๋ฐ›์„ ์ˆ˜๋„ ์žˆ์–ด์š”!

Happy Coding! ๐ŸŽ‰

๐Ÿ“š ์ด ๊ธ€์ด ๋„์›€์ด ๋˜์…จ๋‚˜์š”?

๋” ๋งŽ์€ AI/๋จธ์‹ ๋Ÿฌ๋‹ ๊ฐœ๋ฐœ ์ง€์‹์€ ์žฌ๋Šฅ๋„ท์˜ '์ง€์‹์ธ์˜ ์ˆฒ'์—์„œ ๋งŒ๋‚˜๋ณด์„ธ์š”!
ํ”„๋กœ๊ทธ๋ž˜๋ฐ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ ๋ถ„์„๊นŒ์ง€, ๋‹ค์–‘ํ•œ ์žฌ๋Šฅ์„ ๊ฐ€์ง„ ์ „๋ฌธ๊ฐ€๋“ค์ด ๊ธฐ๋‹ค๋ฆฌ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค ๐Ÿ˜Š

๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.