1
+ """Takes Issues Filed in the last week and puts them in a file for the upcoming stream"""
2
+ import os
3
+ from venv import create
4
+ import httpx
5
+ from datetime import datetime , timedelta
6
+ import pathlib
7
+ from jinja2 import FileSystemLoader , Environment
8
+ # Get the date of the next friday
9
+
10
+ api_key : str = os .environ .get ('GITHUB_API_KEY' , None )
11
+
12
+ loader = FileSystemLoader ("./app/templates" )
13
+ environment = Environment (loader = loader )
14
+
15
+ def get_last_friday ():
16
+ """Returns the previous friday"""
17
+ upcoming_friday = datetime .today () - timedelta (4 - datetime .today ().weekday ())
18
+ last_friday = upcoming_friday - timedelta (days = 7 )
19
+ return last_friday .isoformat ()
20
+
21
+ def get_issues_from_github ():
22
+ """Returns the issues filed in the last week"""
23
+ url = 'https://api.github.com/repos/kjaymiller/Python-Community-News/issues'
24
+ since_date = get_last_friday ()
25
+ params = {
26
+ "query" : "label=Content" ,
27
+ "since" : since_date
28
+ }
29
+ request = httpx .get (url , params = params )
30
+ return request .json ()
31
+
32
+ def create_post_for_week ():
33
+ """Creates a markdown document for this week for render_engine to process"""
34
+ friday = (datetime .today () - timedelta (4 - datetime .today ().weekday ())).strftime ("%Y-%m-%d" )
35
+ current_week = pathlib .Path ('app/content' ).joinpath (friday ).with_suffix ('.md' )
36
+ issues = get_issues_from_github ()
37
+ template = environment .get_template ("content_gen/episode_template.md" )
38
+ return current_week .write_text (template .render (issues = issues , date = friday ))
39
+
40
+ if __name__ == "__main__" :
41
+ print (create_post_for_week ())
0 commit comments