获取stars数量,同时过滤掉stars数量少的项目
(data)
| 132 | |
| 133 | |
| 134 | def get_stars(data): |
| 135 | """ |
| 136 | 获取stars数量,同时过滤掉stars数量少的项目 |
| 137 | """ |
| 138 | project_info_list = [] |
| 139 | for fi_data in data: |
| 140 | project_info = dict() |
| 141 | project_info['user'] = fi_data['actor']['login'] |
| 142 | project_info['user_url'] = 'https://github.com/' + project_info['user'] |
| 143 | project_info['avatar_url'] = fi_data['actor']['avatar_url'] |
| 144 | project_info['repo_name'] = fi_data['repo']['name'] |
| 145 | project_info['repo_url'] = 'https://github.com/' + project_info['repo_name'] |
| 146 | project_info['date_time'] = fi_data['date_time'] |
| 147 | try: |
| 148 | repo_stars = requests.get(fi_data['repo']['url'], timeout=2).json() |
| 149 | if repo_stars: |
| 150 | project_info['repo_stars'] = int(repo_stars['stargazers_count']) |
| 151 | else: |
| 152 | project_info['repo_stars'] = -1 |
| 153 | except Exception as e: |
| 154 | project_info['repo_stars'] = -1 |
| 155 | logger.warning(u'获取:{} 项目星数失败——{}'.format( |
| 156 | project_info['repo_name'], e)) |
| 157 | finally: |
| 158 | if project_info['repo_stars'] >= STARS or project_info['repo_stars'] == -1: |
| 159 | # 过滤掉star数量低于临界值的项目 |
| 160 | project_info_list.append(project_info) |
| 161 | project_info_list = sorted(project_info_list, key=itemgetter('repo_stars'), reverse=True) |
| 162 | return project_info_list |
| 163 | |
| 164 | |
| 165 | def make_content(): |