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
e251785e
Unverified
Commit
e251785e
authored
Nov 03, 2025
by
Noé Lopez
Browse files
Use document writer to output issues in right format
parent
b4c53206
Pipeline
#12099
canceled with stages
Changes
1
Pipelines
2
Show whitespace changes
Inline
Side-by-side
data_fetch.py
View file @
e251785e
import
requests
import
json
import
pandas
as
pd
from
document
import
Document
from
document_writer
import
DocumentWriter
def
fetch_issues
(
owner
,
repo
):
'''Return a list of issues from OWNER/REPO.
...
...
@@ -18,21 +20,26 @@ def fetch_issues(owner, repo):
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.
def
serialize_issue
(
issue
,
owner
,
repo
):
'''Serializes an issue object from the Github API to a Document object.
'''
return
{
id
=
issue
.
get
(
"id"
)
doc
=
Document
()
doc
.
set_name
(
f
"
{
owner
}
/
{
repo
}
/issues/
{
id
}
"
)
doc
.
set_title
(
issue
.
get
(
"title"
))
doc
.
set_attributes
({
"id"
:
issue
.
get
(
"id"
),
"number"
:
issue
.
get
(
"number"
),
"title"
:
issue
.
get
(
"title"
),
"state"
:
issue
.
get
(
"state"
),
"creat
ed_
at"
:
issue
.
get
(
"created_at"
),
"creat
ion_d
at
e
"
:
issue
.
get
(
"created_at"
),
"updated_at"
:
issue
.
get
(
"updated_at"
),
"user_login"
:
issue
[
"user"
][
"login"
]
if
"user"
in
issue
and
issue
[
"user"
]
else
None
,
#
"user_login": issue["user"]["login"] if "user" in issue and issue["user"] else None,
"comments"
:
issue
.
get
(
"comments"
),
"html_url"
:
issue
.
get
(
"html_url"
)
}
})
doc
.
set_main_content
(
issue
.
get
(
"body"
)
or
""
)
return
doc
def
main
():
# Repository details
...
...
@@ -40,14 +47,15 @@ def main():
repo
=
"free-programming-books"
issues
=
fetch_issues
(
owner
,
repo
)
d
ata
=
[]
d
ocuments
=
[]
for
issue
in
issues
:
data
.
append
(
serialize_issue
(
issue
))
documents
.
append
(
serialize_issue
(
issue
,
owner
,
repo
))
print
(
f
"Collected
{
len
(
documents
)
}
documents"
)
# Convert to DataFrame
df
=
pd
.
DataFrame
(
data
)
print
(
df
.
head
())
df
.
to_json
(
"github_data.json"
)
writer
=
DocumentWriter
(
"output"
)
for
doc
in
documents
:
writer
.
write_document
(
doc
)
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