13
13
14
14
token = ""
15
15
if token :
16
- headers = {"Authorization" : "Token %s" % token }
16
+ headers = {"Authorization" : f "Token { token } " }
17
17
else :
18
18
print (
19
19
"Warning: No CourtListener token used. You'll run out of free "
@@ -60,8 +60,7 @@ def make_slug(name: str) -> str | None:
60
60
61
61
try :
62
62
result_json = requests .get (
63
- "https://www.courtlistener.com/api/rest/v4/search/?type=p&name=%s&court=cand"
64
- % name ,
63
+ f"https://www.courtlistener.com/api/rest/v4/search/?type=p&name={ name } &court=cand" ,
65
64
headers = headers ,
66
65
timeout = 10 ,
67
66
).json ()
@@ -76,24 +75,18 @@ def make_slug(name: str) -> str | None:
76
75
return None
77
76
78
77
if result_json ["count" ] > 1 :
79
- print (
80
- "Warning: Got back %s results for %s"
81
- % (
82
- result_json ["count" ],
83
- name ,
84
- )
85
- )
78
+ print (f"Warning: Got back { result_json ['count' ]} results for { name } " )
86
79
return None
87
80
if result_json ["count" ] < 1 :
88
- print ("Warning: Got back no results for %s" % name )
81
+ print (f "Warning: Got back no results for { name } " )
89
82
name_parts = name .split ()
90
83
if len (name_parts ) == 2 :
91
84
return f"{ name_parts [1 ].lower ()} -{ name_parts [0 ].lower ()} "
92
85
return None
93
86
94
87
result_id = result_json ["results" ][0 ]["id" ]
95
88
result_json = requests .get (
96
- "https://www.courtlistener.com/api/rest/v4/people/?id=%s" % result_id ,
89
+ f "https://www.courtlistener.com/api/rest/v4/people/?id={ result_id } " ,
97
90
headers = headers ,
98
91
timeout = 10 ,
99
92
).json ()
@@ -145,7 +138,6 @@ def run_things():
145
138
judge_info .append ((name , url ))
146
139
147
140
for judge_name , judge_link in judge_info :
148
-
149
141
try :
150
142
judge_r = requests .get (judge_link , timeout = 10 )
151
143
except Timeout :
@@ -165,7 +157,7 @@ def run_things():
165
157
'//div[@class = "judge_portrait"]//img/@src'
166
158
)[0 ]
167
159
except IndexError :
168
- print ("Failed to find image for %s" % judge_link )
160
+ print (f "Failed to find image for { judge_link } " )
169
161
continue
170
162
171
163
try :
@@ -197,12 +189,15 @@ def run_things():
197
189
"hash" : img_hash ,
198
190
}
199
191
200
- json .dump (
201
- judge_pics ,
202
- open (os .path .join (judge_root , "judges.json" ), "w" , encoding = "utf-8" ),
203
- sort_keys = True ,
204
- indent = 2 ,
205
- )
192
+ with open (
193
+ os .path .join (judge_root , "judges.json" ), "w" , encoding = "utf-8"
194
+ ) as fp :
195
+ json .dump (
196
+ judge_pics ,
197
+ fp ,
198
+ sort_keys = True ,
199
+ indent = 2 ,
200
+ )
206
201
207
202
208
203
if __name__ == "__main__" :
0 commit comments