Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 50 additions & 12 deletions app/core/api_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,16 @@ def format_response(issues: list) -> list:
Takes a list of issues, and returns them sorted by language and comments.
"""
unique_languages = sorted(set([issue['language'] for issue in issues]))
formatted_results = []
formatted_results = []

for language in unique_languages:
results = [issue for issue in issues if issue['language'] == language]
sorted_results = sorted(results, key=lambda x: x['comments'])
formatted_results.append(sorted_results)
sorted_formatted_results = Utils.create_list_from_lists(formatted_results)


sorted_formatted_results = Utils.create_list_from_lists(formatted_results)
return sorted_formatted_results

@staticmethod
def render_template(csv_path, template_path, today):
"""
Expand All @@ -121,24 +122,61 @@ def render_template(csv_path, template_path, today):

with open(csv_path, newline='', encoding='utf-8') as f:
reader = csv.DictReader(f)

for row in reader:
results.append({
'repo': row['repo'],
'repo': row['repo'],
'language': row['language'],
'title': row['title'],
'url': row['url'],
'title': row['title'],
'url': row['url'],
Comment on lines 106 to +131
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you deleted those unnecesary tabs there!

'comments': row['comments'],
})

env = Environment(loader=FileSystemLoader(template_path))
env = Environment(loader=FileSystemLoader(template_path))

template = env.get_template('README.md.j2')
rendered_readme = template.render(results=results, today=today)
with open("README.md", "w+") as f:

with open("README.md", "w+", encoding="utf-8") as f:
f.write(rendered_readme)

return rendered_readme

@staticmethod
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect implementation with the static method, and improved readability in the CSV columns by using new lines instead all in the same one!

def write_output(issues, output_file):
"""
Write issues to a file in CSV or JSON format.
"""
import json

ext = output_file.lower().split('.')[-1]

if ext == 'csv':
with open(output_file, 'w', newline='', encoding='utf-8') as f:
writer = csv.DictWriter(
f,
fieldnames=[
'repo',
'language',
'title',
'url',
'comments',
'labels',
'state'
]
)
writer.writeheader()
writer.writerows(issues)

elif ext == 'json':
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(issues, f, indent=2)

else:
raise ValueError(
f"Unsupported output format: .{ext} "
f"(use --output issues.csv or --output issues.json)"
)

class Utils:
@staticmethod
Expand Down
19 changes: 1 addition & 18 deletions app/update_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import datetime
import time
import argparse
import csv
import json
import requests

from jinja2 import Environment, FileSystemLoader
Expand All @@ -23,21 +21,6 @@
Utils,
)


def write_output(issues, output_file):
"""Write issues to a file in CSV or JSON format."""
ext = output_file.lower().split('.')[-1]
if ext == 'csv':
with open(output_file, 'w', newline='', encoding='utf-8') as f:
writer = csv.DictWriter(f, fieldnames=['repo', 'language', 'title', 'url', 'comments', 'labels', 'state'])
writer.writeheader()
writer.writerows(issues)
elif ext == 'json':
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(issues, f, indent=2)
else:
raise ValueError(f"Unsupported output format: .{ext} (use --output issues.csv or --output issues.json)")

def main(args):
"""
1- Gathers all issues associated with all public repos
Expand Down Expand Up @@ -74,7 +57,7 @@ def main(args):
formatted_response = TemplateManager.format_response(issues)

if args.output:
write_output(formatted_response, args.output)
TemplateManager.write_output(formatted_response, args.output)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect call for a static method here!

logging.info(f"Wrote {len(issues)} issues to {args.output}")

logging.info(f"Rendered README file.")
Expand Down