@@ -93,24 +93,32 @@ def _count_reactions(self, message: dict) -> int:
9393 total_count += reaction .get ('count' , 0 )
9494 return total_count
9595
96- def analyze_popular_links (self , days_ago : int = 7 , min_reactions : int = 2 ):
96+ def analyze_popular_links (self , days_ago : int = 7 , min_reactions : int = 2 , max_channels : int = None ):
9797 """人気のリンクを分析"""
9898 print ("Fetching channels..." )
9999 channels = self .get_channels ()
100100
101- # 関連性の高いチャンネルをフィルタリング
102- relevant_channels = []
103- for channel in channels :
104- name = channel .get ('name' , '' ).lower ()
105- # Flutter、React Native、モバイル開発関連のチャンネルを対象
106- if any (keyword in name for keyword in ['flutter' , 'react' , 'mobile' , 'ios' , 'android' , 'general' , 'dev' , 'tech' , 'news' ]):
107- relevant_channels .append (channel )
101+ # すべてのチャンネルを対象にする
102+ relevant_channels = channels
108103
109- print (f"Found { len (relevant_channels )} relevant channels" )
104+ # アクティブなチャンネル順にソート(メンバー数が多い順)
105+ relevant_channels .sort (key = lambda x : x .get ('num_members' , 0 ), reverse = True )
106+
107+ # オプションでチャンネル数を制限
108+ if max_channels :
109+ relevant_channels = relevant_channels [:max_channels ]
110+ print (f"Limited to top { max_channels } channels by member count" )
111+
112+ print (f"Found { len (relevant_channels )} channels to process" )
110113
111114 all_links = []
112115
113- for channel in relevant_channels [:10 ]: # 最初の10チャンネルのみ処理
116+ for i , channel in enumerate (relevant_channels ): # すべてのチャンネルを処理
117+ # Rate limiting: 簡単な遅延を追加
118+ if i > 0 and i % 10 == 0 :
119+ print (f"Processed { i } channels, pausing briefly..." )
120+ import time
121+ time .sleep (2 )
114122 channel_id = channel ['id' ]
115123 channel_name = channel ['name' ]
116124 print (f"Processing channel: #{ channel_name } " )
@@ -169,7 +177,7 @@ def get_popular_slack_links():
169177
170178 try :
171179 analyzer = SlackPopularLinksAnalyzer (slack_token )
172- popular_links = analyzer .analyze_popular_links (days_ago = 7 , min_reactions = 1 )
180+ popular_links = analyzer .analyze_popular_links (days_ago = 7 , min_reactions = 1 , max_channels = 50 )
173181
174182 print (f"Found { len (popular_links )} popular links" )
175183 for link in popular_links :
0 commit comments