|
1 | 1 | import requests |
2 | 2 | import datetime |
3 | | -import os |
4 | 3 | import json |
5 | 4 | from bs4 import BeautifulSoup |
| 5 | +import contextlib |
| 6 | +import argparse |
| 7 | +import sys |
| 8 | +import os # Add os import for directory handling |
6 | 9 |
|
7 | 10 | # GitHub API settings |
8 | 11 | GITHUB_API_URL = "https://api.github.com/graphql" |
@@ -293,9 +296,9 @@ def get_html_title(url): |
293 | 296 | return None |
294 | 297 |
|
295 | 298 | if __name__ == "__main__": |
296 | | - import sys |
297 | | - import argparse |
298 | | - import contextlib |
| 299 | + # Ensure the reports directory exists in the current working directory |
| 300 | + reports_dir = os.path.join(os.getcwd(), "reports") |
| 301 | + os.makedirs(reports_dir, exist_ok=True) |
299 | 302 |
|
300 | 303 | parser = argparse.ArgumentParser(description="Generate Learning Path monthly report.") |
301 | 304 | parser.add_argument("--month", type=str, help="Month to generate report for (format: YYYY-MM). Defaults to current month.") |
@@ -332,10 +335,10 @@ def get_html_title(url): |
332 | 335 | month_filter = datetime.date.today().strftime("%Y-%m") |
333 | 336 |
|
334 | 337 | if month_range: |
335 | | - output_filename = f"LP-report-{month_range[0].strftime('%Y-%m')}_to_{month_range[1].strftime('%Y-%m')}.md" |
| 338 | + output_filename = os.path.join(reports_dir, f"LP-report-{month_range[0].strftime('%Y-%m')}_to_{month_range[1].strftime('%Y-%m')}.md") |
336 | 339 | else: |
337 | 340 | report_month = datetime.datetime.strptime(month_filter, "%Y-%m") |
338 | | - output_filename = f"LP-report-{report_month.strftime('%Y-%m')}.md" |
| 341 | + output_filename = os.path.join(reports_dir, f"LP-report-{report_month.strftime('%Y-%m')}.md") |
339 | 342 |
|
340 | 343 | with open(output_filename, "w") as f: |
341 | 344 | with contextlib.ExitStack() as stack: |
|
0 commit comments