|
3 | 3 | import sys |
4 | 4 | from core import tl |
5 | 5 | from core import kick |
| 6 | +from core import cookies_manager |
6 | 7 |
|
7 | 8 | def get_writable_dir(): |
8 | 9 | if getattr(sys, 'frozen', False): |
@@ -109,6 +110,59 @@ def collect_usernames(json_filename='current_views.json'): |
109 | 110 | }) |
110 | 111 | return streamers_data |
111 | 112 |
|
| 113 | +def collect_targeted_streamers(json_filename='current_views.json'): |
| 114 | + cookies = cookies_manager.load_cookies("cookies.txt") |
| 115 | + server_data = {"data": []} |
| 116 | + if cookies: |
| 117 | + try: |
| 118 | + server_data = kick.get_drops_progress(cookies) or {"data": []} |
| 119 | + except: |
| 120 | + pass |
| 121 | + |
| 122 | + views_path = os.path.join(get_writable_dir(), json_filename) |
| 123 | + reward_to_usernames = {} |
| 124 | + |
| 125 | + try: |
| 126 | + with open(views_path, 'r', encoding='utf-8') as f: |
| 127 | + content = f.read().strip() |
| 128 | + if content: |
| 129 | + data = json.loads(content) |
| 130 | + for item in data.get('data', {}).get('planned', []): |
| 131 | + reward_id = item.get('id') |
| 132 | + if reward_id and item.get('usernames'): |
| 133 | + reward_to_usernames[str(reward_id)] = item['usernames'] |
| 134 | + except: |
| 135 | + pass |
| 136 | + |
| 137 | + result = [] |
| 138 | + for campaign in server_data.get('data', []): |
| 139 | + campaign_id = campaign.get('id') or campaign.get('category', {}).get('id') |
| 140 | + category_name = campaign.get('category', {}).get('name', '') |
| 141 | + |
| 142 | + for reward in campaign.get('rewards', []): |
| 143 | + rid = reward.get('id') or reward.get('reward_id') |
| 144 | + if not rid: |
| 145 | + continue |
| 146 | + |
| 147 | + key = str(rid) |
| 148 | + usernames = reward_to_usernames.get(key, []) |
| 149 | + |
| 150 | + s = { |
| 151 | + 'usernames': usernames, |
| 152 | + 'drop_name': reward.get('name') or '', |
| 153 | + 'progress': reward.get('progress'), |
| 154 | + 'claimed': reward.get('claimed', False), |
| 155 | + 'required_seconds': reward.get('required_seconds', 0), |
| 156 | + 'claim': 1 if reward.get('claimed') else 0, |
| 157 | + 'category_name': category_name, |
| 158 | + 'reward_id': rid, |
| 159 | + 'campaign_id': campaign_id, |
| 160 | + } |
| 161 | + result.append(s) |
| 162 | + |
| 163 | + return result |
| 164 | + |
| 165 | + |
112 | 166 | def update_streamer_progress(username, watched_seconds, json_filename='current_views.json', update_type=1): |
113 | 167 | watched_minutes = round(watched_seconds / 60.0, 1) |
114 | 168 | views_path = os.path.join(get_writable_dir(), json_filename) |
|
0 commit comments