Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
software-project-WS25
Github Team
Commits
dcb636ad
Unverified
Commit
dcb636ad
authored
Oct 29, 2025
by
Noé Lopez
Browse files
Refactor into functions
parent
8b4a0464
Changes
1
Show whitespace changes
Inline
Side-by-side
data_fetch.py
View file @
dcb636ad
...
...
@@ -2,28 +2,27 @@ import requests
import
json
import
pandas
as
pd
# Repository details
owner
=
"EbookFoundation"
repo
=
"free-programming-books"
# GitHub API endpoint
url
=
f
"https://api.github.com/repos/
{
owner
}
/
{
repo
}
/issues"
headers
=
{
def
fetch_issues
(
owner
,
repo
):
'''Return a list of issues from OWNER/REPO.
'''
# GitHub API endpoint
url
=
f
"https://api.github.com/repos/
{
owner
}
/
{
repo
}
/issues"
headers
=
{
"Accept"
:
"application/vnd.github+json"
,
# "Authorization": "Bearer YOUR_GITHUB_TOKEN" # optional
}
# Fetch issues
response
=
requests
.
get
(
url
,
headers
=
headers
)
if
response
.
status_code
==
200
:
issues
=
response
.
json
()
# Extract key fields from each issue
data
=
[]
for
issue
in
issues
:
data
.
append
({
}
# Fetch issues
response
=
requests
.
get
(
url
,
headers
=
headers
)
if
response
.
status_code
==
200
:
return
response
.
json
()
else
:
raise
f
"Failed to fetch issues from
{
owner
}
/
{
repo
}
: status
{
response
.
status_code
}
"
def
serialize_issue
(
issue
):
'''Serializes an issue object from the Github API to a dictionary
of key fields.
'''
return
{
"id"
:
issue
.
get
(
"id"
),
"number"
:
issue
.
get
(
"number"
),
"title"
:
issue
.
get
(
"title"
),
...
...
@@ -33,12 +32,22 @@ if response.status_code == 200:
"user_login"
:
issue
[
"user"
][
"login"
]
if
"user"
in
issue
and
issue
[
"user"
]
else
None
,
"comments"
:
issue
.
get
(
"comments"
),
"html_url"
:
issue
.
get
(
"html_url"
)
})
}
def
main
():
# Repository details
owner
=
"EbookFoundation"
repo
=
"free-programming-books"
issues
=
fetch_issues
(
owner
,
repo
)
data
=
[]
for
issue
in
issues
:
data
.
append
(
serialize_issue
(
issue
))
# Convert to DataFrame
df
=
pd
.
DataFrame
(
data
)
print
(
df
.
head
())
df
.
to_json
(
"github_data.json"
)
else
:
print
(
f
"Failed to fetch issues:
{
response
.
status_code
}
"
)
if
__name__
==
"__main__"
:
main
(
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment