3232# Constants
3333BASE_URL = "https://commons.wikimedia.org/w/api.php"
3434FILE_WIKICOMMONS = shared .path_join (
35- PATHS ["data_phase" ], "wikicommons_fetch .csv"
35+ PATHS ["data_phase" ], "wikicommons_legal_tool_counts .csv"
3636)
3737HEADER_WIKICOMMONS = ["LICENSE_TYPE" , "FILE_COUNT" , "PAGE_COUNT" ]
3838ROOT_CATEGORY = "Free_Creative_Commons_licenses"
@@ -156,7 +156,7 @@ def traverse(category, path, depth=0):
156156 {
157157 "LICENSE_TYPE" : path ,
158158 "FILE_COUNT" : contents ["FILE_COUNT" ],
159- "PAGE_COUNT" : contents ["FILE_COUNT " ],
159+ "PAGE_COUNT" : contents ["PAGE_COUNT " ],
160160 }
161161 )
162162
@@ -166,10 +166,7 @@ def traverse(category, path, depth=0):
166166
167167 # Logging label
168168 label = "categories" if depth == 0 else "subcategories"
169- if count == 0 :
170- LOGGER .warning (f"Skipping { category } — 0 { label } found." )
171- else :
172- LOGGER .info (f"Fetched { count } { label } for { category } ." )
169+ LOGGER .info (f"Fetched { count } { label } for { category } ." )
173170
174171 # Recursively traverse subcategories
175172 for sub in subcats :
@@ -187,10 +184,12 @@ def write_data(args, wikicommons_data):
187184 return args
188185
189186 os .makedirs (PATHS ["data_phase" ], exist_ok = True )
190- with open (FILE_WIKICOMMONS , "w" , encoding = "utf-8" , newline = "\n " ) as f :
187+ with open (
188+ FILE_WIKICOMMONS , "w" , encoding = "utf-8" , newline = "\n "
189+ ) as file_obj :
191190
192191 writer = csv .DictWriter (
193- f , fieldnames = HEADER_WIKICOMMONS , dialect = "unix"
192+ file_obj , fieldnames = HEADER_WIKICOMMONS , dialect = "unix"
194193 )
195194 writer .writeheader ()
196195 writer .writerows (wikicommons_data )
0 commit comments