import requests
import pygal
from pygal.style import LightColorizedStyle as LCS, LightStyle as LS
# 執行API呼叫并存盤回應
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
r = requests.get(url)
print("Status code:", r.status_code)
# 將API回應存盤在一個變數中
response_dict = r.json()
print("Total repositories:",response_dict['total_count'])
# 探索有關倉庫的資訊
repo_dicts = response_dict['items']
names, stars = [], []
for repo_dict in repo_dicts:
names.append(repo_dict['name'])
stars.append(repo_dict['stargazers_count'])
# 可視化
my_style = LS('#333366', base_style=LCS)
chart = pygal.Bar(style=my_style, x_label_rotation=45, show_legend=False)
chart.title = 'Most-Starred Python Projects on Github'
chart.x_labels = names
chart.add('', stars)
chart.render_to_file('Python_repos.svg')
結果為什么報這種錯,我都是按照書上打的,pygal也裝了啊
line 23, in <module>
my_style = LS('#333366', base_style=LCS)
TypeError: __init__() takes 1 positional argument but 2 were given
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/270167.html
標籤:其他數據庫
