@@ -296,9 +296,10 @@ def main():
296
296
input_group = parser .add_mutually_exclusive_group (required = True )
297
297
input_group .add_argument ("-t" , "--text" , type = str , help = "Text to fact check" )
298
298
input_group .add_argument ("-f" , "--file" , type = str , help = "Path to file containing text to fact check" )
299
+ input_group .add_argument ("-u" , "--url" , type = str , help = "URL of the article to fact check" )
299
300
300
301
parser .add_argument (
301
- "-m" ,
302
+ "-m" ,
302
303
"--model" ,
303
304
type = str ,
304
305
default = FactChecker .DEFAULT_MODEL ,
@@ -340,9 +341,35 @@ def main():
340
341
except Exception as e :
341
342
print (f"Error reading file: { e } " , file = sys .stderr )
342
343
return 1
343
- else :
344
+ elif args .url :
345
+ try :
346
+ print (f"Fetching content from URL: { args .url } " , file = sys .stderr )
347
+ response = requests .get (args .url , timeout = 15 ) # Add a timeout
348
+ response .raise_for_status () # Raise HTTPError for bad responses (4xx or 5xx)
349
+
350
+ article = Article (url = args .url )
351
+ article .download (input_html = response .text )
352
+ article .parse ()
353
+ text = article .text
354
+ if not text :
355
+ print (f"Error: Could not extract text from URL: { args .url } " , file = sys .stderr )
356
+ return 1
357
+ except RequestException as e :
358
+ print (f"Error fetching URL: { e } " , file = sys .stderr )
359
+ return 1
360
+ except ArticleException as e :
361
+ print (f"Error parsing article content: { e } " , file = sys .stderr )
362
+ return 1
363
+ except Exception as e : # Catch other potential errors during fetch/parse
364
+ print (f"An unexpected error occurred while processing the URL: { e } " , file = sys .stderr )
365
+ return 1
366
+ else : # This corresponds to args.text
344
367
text = args .text
345
-
368
+
369
+ if not text : # Ensure text is not empty before proceeding
370
+ print ("Error: No text found to fact check." , file = sys .stderr )
371
+ return 1
372
+
346
373
print ("Fact checking in progress..." , file = sys .stderr )
347
374
results = fact_checker .check_claim (
348
375
text ,
0 commit comments