File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 99import sys
1010from pathlib import Path
1111
12+ import requests
13+
1214if len (sys .argv ) != 2 :
1315 print (f"Usage: { sys .argv [0 ]} <file>" )
1416 exit (1 )
1517
18+ f = sys .argv [1 ]
19+ if Path (f ).is_file ():
20+ calendar = Path (f ).read_text ()
21+ elif f .isdigit ():
22+ s = Path ("~/.adventofcode.session" ).expanduser ()
23+ if s .is_file ():
24+ session = s .read_text ().strip ()
25+ calendar = requests .get (
26+ f"https://adventofcode.com/{ f } " ,
27+ headers = {
28+ "Cookie" : f"session={ session } " ,
29+ "user-agent" : "Mozilla/5.0" ,
30+ },
31+ ).content .decode ()
32+
1633
1734def rgb (s : str ) -> str :
1835 rgb = re .search (r"#([\da-f]+);" , s ).group (1 )
@@ -38,11 +55,10 @@ def rgb(s: str) -> str:
3855
3956
4057colors = {}
41-
4258colors [None ] = rgb ("#606060;" ) # "\033[0m"
4359
4460
45- for line in Path ( sys . argv [ 1 ]). read_text () .splitlines ():
61+ for line in calendar .splitlines ():
4662
4763 if line .startswith (".calendar .calendar-color-" ):
4864
You can’t perform that action at this time.
0 commit comments