File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import datetime
2+ import pytz
3+
4+ README_PATH = "README.md"
5+
6+ def get_traffic_light_state ():
7+ cst = pytz .timezone ('US/Central' )
8+ now = datetime .datetime .now (cst )
9+ if 10 <= now .hour < 11 :
10+ return "GREEN"
11+ elif 11 <= now .hour < 12 :
12+ return "YELLOW"
13+ else :
14+ return "RED"
15+
16+ def badge_url (state ):
17+ colors = {
18+ "GREEN" : "brightgreen" ,
19+ "YELLOW" : "yellow" ,
20+ "RED" : "red"
21+ }
22+ return f"https://img.shields.io/badge/Traffic_Light-{ state } -{ colors [state ]} "
23+
24+ def update_readme ():
25+ state = get_traffic_light_state ()
26+ badge = badge_url (state )
27+ with open (README_PATH , "r" ) as f :
28+ lines = f .readlines ()
29+
30+ # Find and replace the badge line between the markers.
31+ with open (README_PATH , "w" ) as f :
32+ for line in lines :
33+ if line .strip ().startswith (":
34+ f .write (f"\n " )
35+ else :
36+ f .write (line )
37+
38+ if __name__ == "__main__" :
39+ update_readme ()
You can’t perform that action at this time.
0 commit comments