Spaces:
Build error
Build error
File size: 197,745 Bytes
1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 17e1803 1179be6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### The file aims for the demonstration of the methdology pipeline, please used our new designed database (new excel attached )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### The following code is when user put a new news article link into the model, the model will extract the headline , Date and Content"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Headline: Singapore Airlines stops using Iranian airspace as 'precautionary measure' amid Middle East tensions\n",
"Publication Date: 2024-04-14 08:58:00\n",
"Content: Advertisement Singapore Singapore Airlines stops using Iranian airspace as 'precautionary measure' amid Middle East tensions Singapore Airlines says it is closely monitoring the situation in the Middle East. (File photo: REUTERS/Edgar Su) New: You can now listen to articles. Sorry, the audio is unavailable right now. Please try again later. This audio is AI-generated. 14 Apr 2024 08:58AM (Updated: 14 Apr 2024 06:15PM) Bookmark Bookmark Share WhatsApp Telegram Facebook Twitter Email LinkedIn SING\n"
]
}
],
"source": [
"import requests\n",
"from bs4 import BeautifulSoup\n",
"from datetime import datetime\n",
"\n",
"\n",
"def get_article_details(article_url):\n",
" response = requests.get(article_url)\n",
" soup = BeautifulSoup(response.content, \"html.parser\")\n",
"\n",
" # Extract headline\n",
" headline_tag = soup.find(\"h1\")\n",
" headline = (\n",
" headline_tag.get_text(strip=True) if headline_tag else \"No headline found\"\n",
" )\n",
"\n",
" # Attempt to extract publication date with error handling\n",
" date_container = soup.find(\"div\", class_=\"article-publish\")\n",
" if date_container:\n",
" # Extract the text and handle cleaning it up\n",
" date_text = date_container.get_text(strip=True)\n",
" # Extract the first date assuming it's the publication date (before \"Updated:\")\n",
" publication_date_text = date_text.split(\"(Updated:\")[0].strip()\n",
" try:\n",
" publication_date = datetime.strptime(\n",
" publication_date_text, \"%d %b %Y %I:%M%p\"\n",
" ).strftime(\"%Y-%m-%d %H:%M:%S\")\n",
" except ValueError:\n",
" publication_date = \"No publication date found\"\n",
" else:\n",
" publication_date = \"No publication date found\"\n",
"\n",
" # Extract main content of the article\n",
" article_body = soup.find(\"article\")\n",
" if not article_body:\n",
" article_body = soup\n",
" article_text = (\n",
" article_body.get_text(separator=\" \", strip=True)\n",
" if article_body\n",
" else \"No article content found\"\n",
" )\n",
"\n",
" return headline, publication_date, article_text\n",
"\n",
"\n",
"# Example usage\n",
"article_url = \"https://www.channelnewsasia.com/singapore/singapore-airlines-stops-using-iran-airspace-israel-hamas-war-middle-east-escalation-4264011\"\n",
"headline, publication_date, article_content = get_article_details(article_url)\n",
"print(\"Headline:\", headline)\n",
"print(\"Publication Date:\", publication_date)\n",
"print(\"Content:\", article_content[:500]) # Print the first 500 characters to check"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Here is the code for Summarization of the aritlce (PLEASE USE UR OWN OPENAI KEY HAHA)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Summary: Singapore Airlines has stopped using Iranian airspace as a precautionary measure amid tensions in the Middle East. This decision was made after Iran launched more than 200 drones and missiles at Israel, causing concerns for the safety of flights. The move by Singapore Airlines mirrored that of other airlines, including Lufth\n"
]
}
],
"source": [
"import openai\n",
"\n",
"\n",
"openai.api_key = \"\"\n",
"\n",
"\n",
"def summarize_article(article_content):\n",
" try:\n",
" # Generating the prompt for GPT-3\n",
" prompt_text = (\n",
" \"Summarize the following article in about 70 words, focusing on \"\n",
" \"what happened, where it happened, and the consequences (economic loss, environmental impact, etc.):\\n\\n\"\n",
" f\"{article_content}\"\n",
" )\n",
"\n",
" # Call to OpenAI's Completion API\n",
" response = openai.Completion.create(\n",
" engine=\"gpt-3.5-turbo-instruct\",\n",
" prompt=prompt_text,\n",
" temperature=0.5,\n",
" max_tokens=60, # Adjust as needed to fit the summary length\n",
" top_p=1,\n",
" frequency_penalty=0,\n",
" presence_penalty=0,\n",
" )\n",
"\n",
" # Extracting the text from the response\n",
" summary = response.choices[0].text.strip()\n",
" return summary\n",
" except Exception as e:\n",
" print(f\"An error occurred: {e}\")\n",
" return \"\"\n",
"\n",
"\n",
"summary = summarize_article(article_content)\n",
"print(\"Summary:\", summary)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['Mine Workers Strike' 'Travel Warning' 'Port Congestion'\n",
" 'Bombing, Police Operations'\n",
" 'Roadway Closure / Disruption, Flooding, Severe Winds, Weather Advisory'\n",
" 'Cargo/Warehouse Theft' 'Tropical Cyclone / Storm' 'Storm' 'Earthquake'\n",
" 'Workplace Accident' 'Tornado' 'Industrial Action'\n",
" 'Public Safety / Security' 'Public Transportation Disruption'\n",
" 'General Strike' 'Protest / Riot' 'Port Disruption, Severe Winds'\n",
" 'Miscellaneous Events' 'Customs Regulation' 'Port Disruption'\n",
" 'Port Disruption, Weather Advisory' 'Port Disruption,Port Congestion'\n",
" 'Flooding' 'Train Delays / Disruption,Cargo Disruption'\n",
" 'Port Disruption, Customs Delay' 'Security Advisory' 'Weather Advisory'\n",
" 'Port Closure' 'Customs Delay'\n",
" 'Public Safety / Security, Weather Advisory' 'Trade Regulation'\n",
" 'Trade Restrictions' 'Organized Crime'\n",
" 'Roadway Closure / Disruption, Public Safety / Security'\n",
" 'Military Operations, Ground Transportation Advisory'\n",
" 'Ground Transportation Advisory'\n",
" 'Protest / Riot, Ground Transportation Advisory'\n",
" 'Bomb Detonation / Explosion, Port Congestion, Maritime Accident, Miscellaneous Events, Non-industrial Fire'\n",
" 'Protest / Riot, Miscellaneous Strikes, Ground Transportation Advisory'\n",
" 'Ground Transportation Advisory, Roadway Closure / Disruption'\n",
" 'Maritime Advisory' 'Waterway Closure / Disruption'\n",
" 'Maritime Accident, Chemical Spill' 'Port Strike' 'Hazmat Response'\n",
" 'Roadway Closure / Disruption,Maritime Accident'\n",
" 'Port Strike,Port Disruption'\n",
" 'Protest / Riot, Ground Transportation Advisory, Death / Injury, Individuals in Focus'\n",
" 'Protest / Riot, Death / Injury, Individuals in Focus'\n",
" 'Protest / Riot, Ground Transportation Advisory, Maritime Advisory'\n",
" 'Kidnap / Detention, Individuals in Focus'\n",
" 'Miscellaneous Events, Maritime Advisory'\n",
" 'Ground Transportation Advisory, Maritime Advisory' 'Industrial Fire'\n",
" 'Protest / Riot, Ground Transportation Advisory, Miscellaneous Strikes'\n",
" 'Tropical Cyclone / Storm, Weather Advisory' 'Miscellaneous Strikes'\n",
" 'Kidnap / Detention, Piracy' 'Miscellaneous Events, Individuals in Focus'\n",
" 'Public Safety / Security, Flooding, Roadway Closure / Disruption'\n",
" 'Non-industrial Fire, Port Disruption'\n",
" 'Non-industrial Fire, Maritime Accident'\n",
" 'Roadway Closure / Disruption,Port Disruption'\n",
" 'Roadway Closure / Disruption' 'Production Halt' 'Maritime Accident'\n",
" 'Roadway Closure / Disruption, Vehicle Accident'\n",
" 'Explosion, Chemical Spill' 'Cargo Disruption' 'Civil Service Strike'\n",
" 'Public Safety / Security, Roadway Closure / Disruption, Vehicle Accident'\n",
" 'Protest / Riot, Roadway Closure / Disruption' 'Non-industrial Fire'\n",
" 'Regulatory Advisory' 'Chemical Spill'\n",
" 'Military Operations, Security Advisory, Ground Transportation Advisory, Maritime Advisory'\n",
" 'Military Operations, Security Advisory, Ground Transportation Advisory, Maritime Advisory, Death / Injury, Individuals in Focus'\n",
" 'Fuel Disruption' 'Port Congestion,Port Disruption'\n",
" 'Port Disruption,Port Closure' 'Force Majeure'\n",
" 'Public Safety / Security, Flooding, Roadway Closure / Disruption, Weather Advisory'\n",
" 'Public Health Advisory, Military Operations' 'Military Operations'\n",
" 'Public Safety / Security, Roadway Closure / Disruption'\n",
" 'Bomb Detonation / Explosion, Non-industrial Fire'\n",
" 'Port Closure,Cargo Disruption,Port Disruption'\n",
" 'Port Disruption, Non-industrial Fire' 'Organized Crime,Cargo Disruption'\n",
" 'Train Accident / Derailment, Train Delays / Disruption, Roadway Closure / Disruption, Vehicle Accident'\n",
" 'Organized Crime, Maritime Advisory, Cargo/Warehouse Theft'\n",
" 'Maritime Accident, Non-industrial Fire' 'Death / Injury'\n",
" 'Individuals in Focus, Maritime Advisory, Protest / Riot'\n",
" 'Organized Crime, Kidnap / Detention, Ground Transportation Advisory, Individuals in Focus, Cargo/Warehouse Theft'\n",
" 'Terror Attack'\n",
" 'Organized Crime, Security Advisory, Individuals in Focus, Kidnap / Detention, Maritime Advisory, Cargo/Warehouse Theft'\n",
" 'Organized Crime, Security Advisory, Ground Transportation Advisory'\n",
" 'Explosion'\n",
" 'Chemical Spill, Non-industrial Fire, Train Accident / Derailment'\n",
" 'Roadway Closure / Disruption, Shooting, Public Safety / Security'\n",
" 'Network Disruption' 'Truck Driving Ban' 'Power Outage'\n",
" 'Customs Regulation, Public Health Advisory' 'Telecom Outage'\n",
" 'Cargo Disruption, Port Strike, Maritime Advisory'\n",
" 'Maritime Accident,Port Disruption' 'Piracy' 'Energy Sector Strike'\n",
" 'Civil Unrest Advisory, Miscellaneous Events, Ground Transportation Advisory'\n",
" 'Cargo Transportation Strike' 'Severe Winds'\n",
" 'Cargo Disruption, Roadway Closure / Disruption, Maritime Advisory'\n",
" 'Port Disruption,Cargo Disruption,Organized Crime'\n",
" 'Train Accident / Derailment, Train Delays / Disruption'\n",
" 'Chemical Spill, Non-industrial Fire, Roadway Closure / Disruption, Vehicle Accident'\n",
" 'Regulatory Advisory,Industry Directives'\n",
" 'Cargo Transportation Strike,Protest / Riot'\n",
" 'Public Health Advisory, Roadway Closure / Disruption' 'Barge Accident'\n",
" 'Public Safety / Security, Non-industrial Fire, Roadway Closure / Disruption'\n",
" 'Non-industrial Fire, Roadway Closure / Disruption'\n",
" 'Earthquake, Public Safety / Security' 'Storm, Weather Advisory'\n",
" 'Flooding, Landslide, Severe Winds, Storm'\n",
" 'Flight Delays / Cancellations, Public Safety / Security'\n",
" 'Protest / Riot, Public Safety / Security'\n",
" 'Organized Crime, Cargo/Warehouse Theft'\n",
" 'Organized Crime, Cargo/Warehouse Theft, Public Safety / Security'\n",
" 'Maritime Advisory, Port Disruption' 'Port Disruption,Weather Advisory'\n",
" 'Port Congestion,Cargo Disruption' 'Cargo Disruption,Weather Advisory'\n",
" 'Public Health Advisory' 'Cargo Transportation Strike,Port Disruption'\n",
" 'Industrial Fire,Roadway Closure / Disruption'\n",
" 'Power Outage,Port Disruption' 'Maritime Accident,Cargo Disruption'\n",
" 'Military Operations, Protest / Riot, Death / Injury, Miscellaneous Events, Individuals in Focus'\n",
" 'Train Delays / Disruption' 'Train Delays / Disruption,Protest / Riot'\n",
" 'Roadway Closure / Disruption,Weather Advisory'\n",
" 'Port Disruption, Severe Winds, Ground Transportation Advisory'\n",
" 'Public Safety / Security, Non-industrial Fire, Maritime Accident'\n",
" 'Vehicle Accident' 'Waterway Closure / Disruption, Cargo Disruption'\n",
" 'Roadway Closure / Disruption,Protest / Riot'\n",
" 'Bomb Detonation / Explosion' 'Port Closure,Port Disruption'\n",
" 'Port Disruption,Train Delays / Disruption,Severe Winds'\n",
" 'Production Halt,Earthquake'\n",
" 'Maritime Accident, Chemical Spill, Hazmat Response'\n",
" 'Waterway Closure / Disruption,Port Disruption'\n",
" 'Customs Regulation,Trade Regulation' 'Industry Directives'\n",
" 'Protest / Riot, Miscellaneous Strikes'\n",
" 'Flooding, Severe Winds, Storm, Weather Advisory'\n",
" 'Protest / Riot,Roadway Closure / Disruption'\n",
" 'Train Delays / Disruption,Industrial Action'\n",
" 'Protest / Riot, Roadway Closure / Disruption, Miscellaneous Strikes'\n",
" 'Flooding, Public Health Advisory, Ground Transportation Advisory'\n",
" 'Flooding, Landslide, Roadway Closure / Disruption'\n",
" 'Protest / Riot, Public Safety / Security, Shooting, Miscellaneous Strikes'\n",
" 'Severe Winds, Storm'\n",
" 'Protest / Riot, Public Safety / Security, Roadway Closure / Disruption'\n",
" 'Miscellaneous Strikes, Ground Transportation Advisory'\n",
" 'Train Delays / Disruption, Miscellaneous Strikes'\n",
" 'Industrial Action,Port Disruption' 'Hurricane'\n",
" 'Port Strike,Cargo Disruption' 'Port Closure, Port Congestion'\n",
" 'Network Disruption,Customs Delay'\n",
" 'Cargo/Warehouse Theft, Organized Crime' 'Civil Unrest Advisory'\n",
" 'Robbery' 'Train Accident / Derailment, Chemical Spill'\n",
" 'Structure Collapse' 'Regulatory Advisory,Maritime Advisory'\n",
" 'Kidnap / Detention' 'Typhoon'\n",
" 'Chemical Spill, Hazmat Response, Maritime Accident'\n",
" 'Vehicle Accident, Public Safety / Security'\n",
" 'Ground Transportation Advisory,Weather Advisory'\n",
" 'Train Accident / Derailment'\n",
" 'Cargo Disruption,Vehicle Accident,Port Disruption'\n",
" 'Vehicle Accident, Roadway Closure / Disruption'\n",
" 'Protest / Riot,Port Disruption'\n",
" 'Roadway Closure / Disruption,Protest / Riot,Cargo Transportation Strike'\n",
" 'Port Strike, Cargo Disruption' 'Storm, Ground Transportation Advisory'\n",
" 'Robbery, Cargo/Warehouse Theft'\n",
" 'Regulatory Advisory,Cargo Disruption,Customs Regulation'\n",
" 'Airline Incident / Crash, Flight Delays / Cancellations'\n",
" 'Roadway Closure / Disruption, Public Safety / Security, Non-industrial Fire'\n",
" 'Public Safety / Security, Non-industrial Fire'\n",
" 'Flight Delays / Cancellations, Non-industrial Fire, Train Delays / Disruption'\n",
" 'Train Delays / Disruption, Roadway Closure / Disruption'\n",
" 'Protest / Riot, Port Disruption, Roadway Closure / Disruption'\n",
" 'Flight Delays / Cancellations, Train Delays / Disruption'\n",
" 'Protest / Riot, Roadway Closure / Disruption, Ground Transportation Advisory'\n",
" 'Train Delays / Disruption, Vehicle Accident'\n",
" 'Non-industrial Fire, Roadway Closure / Disruption, Vehicle Accident'\n",
" 'Public Safety / Security, Wildfire' 'Wildfire'\n",
" 'Public Safety / Security, Non-industrial Fire, Public Health Advisory'\n",
" 'Public Health Advisory, Port Disruption, Roadway Closure / Disruption, Miscellaneous Strikes, Weather Advisory, Wildfire'\n",
" 'Flight Delays / Cancellations, Public Safety / Security, Wildfire'\n",
" 'Flooding, Power Outage, Storm, Weather Advisory'\n",
" 'Tropical Cyclone / Storm, Power Outage, Severe Winds'\n",
" 'Flooding, Public Health Advisory, Hurricane, Severe Winds, Weather Advisory'\n",
" 'Flooding, Hurricane, Power Outage, Severe Winds, Ground Transportation Advisory'\n",
" 'Tropical Cyclone / Storm, Port Disruption'\n",
" 'Tropical Cyclone / Storm, Port Disruption, Storm'\n",
" 'Power Outage, Weather Advisory'\n",
" 'Chemical Spill, Bomb Detonation / Explosion'\n",
" 'Flooding, Power Outage, Ground Transportation Advisory'\n",
" 'Flight Delays / Cancellations, Protest / Riot, Non-industrial Fire, Public Safety / Security, Roadway Closure / Disruption, Miscellaneous Strikes'\n",
" 'Protest / Riot, Roadway Closure / Disruption, Miscellaneous Strikes, Ground Transportation Advisory'\n",
" 'Political Info / Event'\n",
" 'Protest / Riot, Public Safety / Security, Roadway Closure / Disruption, Ground Transportation Advisory'\n",
" 'Protest / Riot, Non-industrial Fire, Public Safety / Security, Train Delays / Disruption, Roadway Closure / Disruption, Shooting'\n",
" 'Protest / Riot, Non-industrial Fire, Public Safety / Security'\n",
" 'Flight Delays / Cancellations, Protest / Riot, Public Safety / Security, Train Delays / Disruption, Roadway Closure / Disruption, Ground Transportation Advisory'\n",
" 'Protest / Riot, Public Safety / Security, Train Delays / Disruption, Roadway Closure / Disruption, Miscellaneous Strikes'\n",
" 'Flight Delays / Cancellations, Public Safety / Security, Flooding, Port Disruption, Power Outage, Train Delays / Disruption, Roadway Closure / Disruption, Severe Winds, Storm'\n",
" 'Public Safety / Security, Storm, Weather Advisory'\n",
" 'Public Safety / Security, Flooding, Landslide, Roadway Closure / Disruption, Weather Advisory'\n",
" 'Earthquake, Public Safety / Security, Public Health Advisory'\n",
" 'Ground Transportation Advisory, Storm'\n",
" 'Port Disruption, Severe Winds, Weather Advisory'\n",
" 'Train Delays / Disruption, Miscellaneous Strikes, Ground Transportation Advisory'\n",
" 'Flooding, Storm, Weather Advisory'\n",
" 'Protest / Riot, Roadway Closure / Disruption, Miscellaneous Strikes, Public Safety / Security'\n",
" 'Protest / Riot, Security Advisory, Political Info / Event, Roadway Closure / Disruption, Miscellaneous Strikes'\n",
" 'Public Safety / Security, Ground Transportation Advisory'\n",
" 'Power Outage, Ground Transportation Advisory'\n",
" 'Earthquake, Train Delays / Disruption, Roadway Closure / Disruption'\n",
" 'Hazmat Response, Train Delays / Disruption'\n",
" 'Flight Delays / Cancellations, Train Accident / Derailment, Train Delays / Disruption'\n",
" 'Flooding, Roadway Closure / Disruption, Weather Advisory'\n",
" 'Airport Accident / Closure, Public Safety / Security, Hurricane, Severe Winds, Ground Transportation Advisory, Weather Advisory'\n",
" 'Flooding, Hurricane, Power Outage, Severe Winds, Weather Advisory'\n",
" 'Public Safety / Security, Flooding, Power Outage, Storm, Weather Advisory'\n",
" 'Public Safety / Security, Maritime Advisory, Robbery'\n",
" 'Port Disruption, Maritime Advisory' 'Port Closure,Port Congestion'\n",
" 'Port Closure,Roadway Closure / Disruption'\n",
" 'Cargo Disruption,Regulatory Advisory' 'Customs Delay,Port Disruption'\n",
" 'Train Delays / Disruption,Port Disruption' 'Flooding,Weather Advisory'\n",
" 'Port Congestion, Port Closure' 'Port Strike,Port Congestion'\n",
" 'Weather Advisory,Roadway Closure / Disruption'\n",
" 'Port Disruption, Port Strike'\n",
" 'Port Strike,Roadway Closure / Disruption,Port Congestion'\n",
" 'Public Safety / Security, Ground Transportation Advisory, Wildfire'\n",
" 'General Strike,Roadway Closure / Disruption'\n",
" 'Border Closure / Delay,Roadway Closure / Disruption'\n",
" 'Roadway Closure / Disruption, Protest / Riot'\n",
" 'Port Congestion,Weather Advisory' 'Maritime Advisory,Port Congestion'\n",
" 'Protest / Riot,Industrial Action,Port Strike,Port Disruption'\n",
" 'Port Strike,Customs Delay,General Strike'\n",
" 'Customs Delay,Civil Service Strike,Port Congestion'\n",
" 'Industrial Action, Miscellaneous Strikes'\n",
" 'Industrial Action,Plant Closure' 'Typhoon,Landslide,Flooding'\n",
" 'Roadway Closure / Disruption,Protest / Riot,Maritime Advisory,Port Disruption'\n",
" 'Hurricane, Public Safety / Security' 'Port Congestion,Port Closure'\n",
" 'Port Disruption,Port Closure,Port Congestion'\n",
" 'Aviation Advisory,Ground Transportation Advisory'\n",
" 'Customs Regulation,Port Congestion' 'Industrial Fire, Hazmat Response'\n",
" 'Port Strike, Miscellaneous Strikes'\n",
" 'Port Congestion,Waterway Closure / Disruption,Maritime Advisory'\n",
" 'Miscellaneous Strikes, Customs Delay, Civil Service Strike'\n",
" 'Miscellaneous Strikes, Industrial Action'\n",
" 'Train Accident / Derailment,Train Delays / Disruption'\n",
" 'Industrial Action,Protest / Riot,Cargo Transportation Strike'\n",
" 'Port Disruption,Cargo Disruption'\n",
" 'Roadway Closure / Disruption, Non-industrial Fire'\n",
" 'Roadway Closure / Disruption, Vehicle Accident, Public Safety / Security'\n",
" 'Robbery, Public Safety / Security, Roadway Closure / Disruption'\n",
" 'Public Safety / Security, Roadway Closure / Disruption, Shooting'\n",
" 'Non-industrial Fire, Public Safety / Security'\n",
" 'Public Safety / Security, Flooding'\n",
" 'Non-industrial Fire, Train Delays / Disruption'\n",
" 'Chemical Spill, Bomb Detonation / Explosion, Non-industrial Fire'\n",
" 'Flooding, Roadway Closure / Disruption'\n",
" 'Public Safety / Security, Security Advisory, Roadway Closure / Disruption, Vehicle Accident'\n",
" 'Public Safety / Security, Train Delays / Disruption' 'Shooting'\n",
" 'Roadway Closure / Disruption, Miscellaneous Strikes'\n",
" 'Blizzard, Weather Advisory'\n",
" 'Chemical Spill, Roadway Closure / Disruption'\n",
" 'Severe Winds, Storm, Weather Advisory'\n",
" 'Power Outage, Roadway Closure / Disruption, Vehicle Accident'\n",
" 'Maritime Accident, Roadway Closure / Disruption'\n",
" 'Roadway Closure / Disruption, Storm, Weather Advisory'\n",
" 'Airline Incident / Crash'\n",
" 'Security Advisory, Ground Transportation Advisory, Death / Injury, Individuals in Focus'\n",
" 'Ground Transportation Advisory, Death / Injury, Individuals in Focus'\n",
" 'Protest / Riot, Ground Transportation Advisory, Aviation Advisory, Maritime Advisory, Miscellaneous Events, Individuals in Focus'\n",
" 'Flooding, Roadway Closure / Disruption, Storm, Weather Advisory'\n",
" 'Production Halt, Cargo Disruption, Port Congestion, Public Holidays'\n",
" 'Public Health Advisory, Ground Transportation Advisory, Security Advisory'\n",
" 'Outbreak of disease' 'Cargo Disruption, Port Disruption'\n",
" 'Maritime Advisory, Cargo Disruption'\n",
" 'Maritime Advisory, Outbreak of disease'\n",
" 'Individuals in Focus, Political Info / Event, Miscellaneous Events'\n",
" 'Miscellaneous Events, Political Info / Event, Ground Transportation Advisory'\n",
" 'Public Safety / Security, Security Advisory'\n",
" 'Roadway Closure / Disruption, Cargo Transportation Strike'\n",
" 'Maritime Advisory, Political Info / Event, Miscellaneous Events'\n",
" 'Regulatory Advisory, Ground Transportation Advisory, Miscellaneous Strikes, Maritime Advisory'\n",
" 'Roadway Closure / Disruption, Weather Advisory'\n",
" 'Weather Advisory, Ground Transportation Advisory, Flooding'\n",
" 'Flight Delays / Cancellations'\n",
" 'Tropical Cyclone / Storm, Severe Winds, Weather Advisory'\n",
" 'Maritime Advisory, Waterway Closure / Disruption'\n",
" 'Miscellaneous Events, Political Info / Event, Maritime Advisory'\n",
" 'Maritime Advisory, Political Info / Event, Public Safety / Security, Military Operations'\n",
" 'Military Operations, Political Info / Event, Ground Transportation Advisory'\n",
" 'Insolvency' 'Protest / Riot, Port Disruption'\n",
" 'Public Health Advisory, Ground Transportation Advisory, Public Safety / Security, Security Advisory'\n",
" 'Ground Transportation Advisory, Vehicle Accident, Port Disruption'\n",
" 'Political Info / Event, Protest / Riot'\n",
" 'Public Safety / Security, Maritime Advisory, Death / Injury, Individuals in Focus, Robbery'\n",
" 'Maritime Advisory, Political Info / Event, Miscellaneous Events, Public Safety / Security'\n",
" 'Maritime Advisory, Political Info / Event, Miscellaneous Events, Individuals in Focus, Public Safety / Security'\n",
" 'Public Safety / Security, Maritime Advisory'\n",
" 'Regulatory Advisory, Ground Transportation Advisory, Public Health Advisory, Security Advisory'\n",
" 'Hazmat Response, Ground Transportation Advisory, Network Disruption'\n",
" 'Port Congestion, Port Disruption' 'Chemical Spill, Port Disruption'\n",
" 'Train Delays / Disruption, Protest / Riot'\n",
" 'Port Closure, Maritime Advisory' 'Hazmat Response, Port Disruption'\n",
" 'Port Disruption, Roadway Closure / Disruption, Weather Advisory'\n",
" 'Flooding, Weather Advisory' 'Ransomware'\n",
" 'Aviation Advisory, Political Info / Event, Ground Transportation Advisory, Network Disruption, Maritime Advisory, Hurricane, Weather Advisory'\n",
" 'Miscellaneous Events, Political Info / Event'\n",
" 'Miscellaneous Events, Political Info / Event, Protest / Riot, Death / Injury, Individuals in Focus'\n",
" 'Individuals in Focus, Protest / Riot'\n",
" 'Public Safety / Security, Individuals in Focus'\n",
" 'Miscellaneous Events, Public Safety / Security'\n",
" 'Maritime Advisory, Protest / Riot, Miscellaneous Events'\n",
" 'Miscellaneous Events, Political Info / Event, Maritime Advisory, Outbreak Of War'\n",
" 'Port Disruption, Waterway Closure / Disruption'\n",
" 'Production Halt, Fuel Disruption'\n",
" 'Miscellaneous Events, Ground Transportation Advisory, Public Health Advisory, Network Disruption, Maritime Advisory, Regulatory Advisory, Security Advisory'\n",
" 'Regulatory Advisory, Political Info / Event, Network Disruption, Hurricane, Weather Advisory'\n",
" 'Maritime Advisory, Military Operations'\n",
" 'Port Disruption, Cargo Disruption'\n",
" 'Train Delays / Disruption, Cargo Disruption'\n",
" 'Regulatory Advisory, Public Health Advisory'\n",
" 'Public Safety / Security, Train Delays / Disruption, Hazmat Response'\n",
" 'Maritime Advisory, Political Info / Event, Military Operations'\n",
" 'Flooding, Train Delays / Disruption, Landslide, Weather Advisory'\n",
" 'Regulatory Advisory, Cargo Disruption'\n",
" 'Public Health Advisory, Public Safety / Security, Security Advisory'\n",
" 'Public Safety / Security, Ground Transportation Advisory, Network Disruption'\n",
" 'Ransomware, Data breach' 'Civil Service Strike, Border Closure / Delay'\n",
" 'Outbreak of disease, Miscellaneous Strikes'\n",
" 'Political Info / Event, Ground Transportation Advisory, Public Health Advisory'\n",
" 'Data breach' 'Public Safety / Security, Hazmat Response'\n",
" 'Weather Advisory, Network Disruption'\n",
" 'Production Halt, Tropical Cyclone / Storm' 'Piracy, Maritime Advisory'\n",
" 'Protest / Riot, Miscellaneous Strikes, Maritime Advisory, Public Safety / Security'\n",
" 'Outbreak of disease, Production Halt' 'Port Closure, Port Disruption'\n",
" 'Border Closure / Delay'\n",
" 'Public Safety / Security, Shooting, Roadway Closure / Disruption'\n",
" 'Weather Advisory, Ground Transportation Advisory, Hazmat Response, Maritime Advisory'\n",
" 'Non-industrial Fire, Port Disruption, Public Safety / Security'\n",
" 'Miscellaneous Strikes, Protest / Riot, Public Safety / Security'\n",
" 'Train Accident / Derailment, Train Delays / Disruption, Hazmat Response'\n",
" 'Tropical Cyclone / Storm, Power Outage, Landslide, Public Safety / Security, Flooding'\n",
" 'Weather Advisory, Security Advisory'\n",
" 'Public Health Advisory, Security Advisory'\n",
" 'Flight Delays / Cancellations, Non-industrial Fire, Roadway Closure / Disruption'\n",
" 'Miscellaneous Events, Ground Transportation Advisory, Network Disruption, Death / Injury'\n",
" 'Miscellaneous Events, Protest / Riot, Ground Transportation Advisory'\n",
" 'Death / Injury, Protest / Riot, Ground Transportation Advisory, Kidnap / Detention'\n",
" 'Ground Transportation Advisory, Protest / Riot'\n",
" 'Aviation Advisory, Ground Transportation Advisory, Network Disruption, Maritime Advisory, Miscellaneous Events'\n",
" 'Weather Advisory, Hazmat Response, Network Disruption' 'Ice Storm'\n",
" 'Roadway Closure / Disruption, Ground Transportation Advisory, Storm, Weather Advisory'\n",
" 'Example Category']\n"
]
}
],
"source": [
"unique_categories = df[\"Category\"].unique()\n",
"print(unique_categories)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"import openai\n",
"\n",
"\n",
"def classify_article(article_content):\n",
" prompt = f\"\"\"Read the following article and classify its content into one of these categories: 'Aviation Advisory',\n",
"'Bombing',\n",
"'Cargo Disruption',\n",
"'Warehouse Theft',\n",
"'Chemical Spill',\n",
"'Injury',\n",
"'Earthquake',\n",
"'Flooding',\n",
"'Ground Transportation Advisory',\n",
"'Hazmat Response',\n",
"'Ice Storm',\n",
"'Individuals in Focus',\n",
"'Industrial Action',\n",
"'Maritime Accident',\n",
"'Maritime Accident.Ground Transportation Advisory',\n",
"'Maritime Advisory',\n",
"'Mine Workers Strike',\n",
"'Miscellaneous Events',\n",
"'Miscellaneous Strikes',\n",
"'Network Disruption',\n",
"'Non-industrial Fire',\n",
"'Police Operations',\n",
"'Port Closure',\n",
"'Port Congestion',\n",
"'Port Disruption',\n",
"'Power Outage',\n",
"'Production Halt',\n",
"'Protest',\n",
"'Public Safety ,\n",
"'Public Transportation Disruption',\n",
"'Roadway Closuren',\n",
"'Severe Winds',\n",
"'Storm',\n",
"'Tornado',\n",
"'Train Delays,\n",
"'Travel Warning',\n",
"'Tropical Cyclone Storm',\n",
"'Typhoon',\n",
"'Vehicle Accident',\n",
"'Weather Advisory',\n",
"'Workplace Accident'\n",
"Summary: {article_content}\n",
"Category:\"\"\"\n",
"\n",
" response = openai.Completion.create(\n",
" engine=\"gpt-3.5-turbo-instruct\", # Adjust according to the latest available and appropriate model\n",
" prompt=prompt,\n",
" temperature=0.7,\n",
" max_tokens=60, # Adjust based on your needs\n",
" top_p=1.0,\n",
" frequency_penalty=0,\n",
" presence_penalty=0,\n",
" stop=[\"\\n\"], # Stop generating further when a newline character is encountered\n",
" )\n",
" category = response.choices[0].text.strip()\n",
" return category"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"from bs4 import BeautifulSoup\n",
"\n",
"\n",
"def fetch_article_content(url):\n",
" response = requests.get(url)\n",
" soup = BeautifulSoup(response.content, \"html.parser\")\n",
" article_text = \" \".join([p.text for p in soup.find_all(\"p\")])\n",
" return article_text"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Category: Aviation Advisory\n"
]
}
],
"source": [
"import openai\n",
"\n",
"\n",
"def classify_article(url):\n",
" # Fetch article content\n",
" article_content = fetch_article_content(url)\n",
"\n",
" # Construct the classification prompt\n",
" prompt = f\"\"\"Read the following article and classify its content into one of these categories:\n",
" 'Aviation Advisory', 'Bombing',\n",
"'Cargo Disruption',\n",
"'Chemical Spill',\n",
"'Death',\n",
"'Earthquake',\n",
"'Flooding',\n",
"'Ground Transportation Advisory',\n",
"'Hazmat Response',\n",
"'Ice Storm',\n",
"'Individuals in Focus',\n",
"'Industrial Action',\n",
"'Maritime Accident',\n",
"'Maritime Accident.Ground Transportation Advisory',\n",
"'Maritime Advisory',\n",
"'Mine Workers Strike',\n",
"'Miscellaneous Events',\n",
"'Miscellaneous Strikes',\n",
"'Network Disruption',\n",
"'Non-industrial Fire',\n",
"'Police Operations',\n",
"'Port Closure',\n",
"'Port Congestion',\n",
"'Port Disruption',\n",
"'Power Outage',\n",
"'Production Halt',\n",
"'Protest / Riot',\n",
"'Public Safety / Security',\n",
"'Public Transportation Disruption',\n",
"'Roadway Closure / Disruption',\n",
"'Severe Winds',\n",
"'Storm',\n",
"'Tornado',\n",
"'Train Delays / Disruption',\n",
"'Travel Warning',\n",
"'Tropical Cyclone / Storm',\n",
"'Typhoon',\n",
"'Vehicle Accident',\n",
"'Weather Advisory',\n",
"'Workplace Accident', ...\n",
" \n",
" Article:\n",
" {article_content}\n",
" \n",
" Category:\"\"\"\n",
"\n",
" # Classify using OpenAI GPT-3\n",
" response = openai.Completion.create(\n",
" engine=\"gpt-3.5-turbo-instruct\", # Ensure using a correct and non-deprecated model\n",
" prompt=prompt,\n",
" temperature=0.7,\n",
" max_tokens=60,\n",
" top_p=1.0,\n",
" frequency_penalty=0,\n",
" presence_penalty=0,\n",
" stop=[\"\\n\"], # Stop generating further when a newline character is encountered\n",
" )\n",
" category = response.choices[0].text.strip()\n",
" return category\n",
"\n",
"\n",
"# Example usage\n",
"url = \"https://www.channelnewsasia.com/singapore/singapore-airlines-stops-using-iran-airspace-israel-hamas-war-middle-east-escalation-4264011\"\n",
"category = classify_article(url)\n",
"print(\"Category:\", category)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Now you the classfication result, which is quite accurate :))"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2 dead, 3 missing in Guangzhou after cargo ship rams bridge over Pearl River\n"
]
}
],
"source": [
"print(headline)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Update our database!"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Database updated successfully with ID 16.\n"
]
}
],
"source": [
"import pandas as pd\n",
"from datetime import datetime\n",
"\n",
"\n",
"def update_database(file_path, url):\n",
" # Fetch details from the article\n",
" headline, publication_date, article_content = get_article_details(article_url)\n",
" summary = summarize_article(article_content)\n",
" category = classify_article(url)\n",
"\n",
" new_data = {\n",
" \"Headline\": headline,\n",
" \"Summary\": summary,\n",
" \"Category\": category,\n",
" \"Datetime\": publication_date,\n",
" \"URL\": article_url,\n",
" }\n",
"\n",
" # Load the existing data from the CSV file\n",
" try:\n",
" df = pd.read_csv(file_path)\n",
" except FileNotFoundError:\n",
" # If the file does not exist, create a new DataFrame\n",
" df = pd.DataFrame(\n",
" columns=[\"id\", \"Headline\", \"Summary\", \"Category\", \"Datetime\", \"URL\"]\n",
" )\n",
" new_id = 1 # Start with ID 1 if no file exists\n",
" else:\n",
" # If IDs exist, increment from the last used ID\n",
" new_id = df[\"id\"].max() + 1 if not df.empty else 1\n",
"\n",
" # Prepare the new data entry\n",
" new_entry = pd.DataFrame(\n",
" {\n",
" \"id\": [new_id],\n",
" \"Headline\": [new_data[\"Headline\"]],\n",
" \"Summary\": [new_data[\"Summary\"]],\n",
" \"Category\": [new_data[\"Category\"]],\n",
" \"Datetime\": [new_data[\"Datetime\"]],\n",
" \"URL\": [new_data[\"URL\"]],\n",
" }\n",
" )\n",
"\n",
" # Append the new data entry to the DataFrame using concat\n",
" df = pd.concat([df, new_entry], ignore_index=True)\n",
"\n",
" # Save the updated DataFrame back to CSV\n",
" df.to_csv(file_path, index=False)\n",
" print(f\"Database updated successfully with ID {new_id}.\")\n",
"\n",
"\n",
"# Example usage\n",
"url = \"https://www.channelnewsasia.com/singapore/singapore-airlines-stops-using-iran-airspace-israel-hamas-war-middle-east-escalation-4264011\"\n",
"file_path = \"cleaned_data1.csv\"\n",
"update_database(file_path, url)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" id Headline \\\n",
"22 28 UPDATE 1 - Attacks on tanker and oil facility ... \n",
"24 30 WATCH FOR: Road, rail, air, and maritime cargo... \n",
"21 27 The Search and Rescue Agencies of Indonesia a... \n",
"20 22 Hurricane Isaias to Impact Florida Coast this ... \n",
"23 29 UPDATE 1 - Australia unlikely to directly reta... \n",
"19 21 Beirut International Airport suffers damage fr... \n",
"18 20 Air Arabia flight G9-661 bound for Khartoum ma... \n",
"17 19 Victoria Harbour - Reports of a plane crash we... \n",
"16 18 UPDATE: Pakistan partially closes 3 internatio... \n",
"14 15 Gatwick Airport (LGW) - British Airways flight... \n",
"15 17 UPDATE - USA: Hurricane Dorian forecast to imp... \n",
"13 14 Delta Flight 472 met by PAPD firefighters at J... \n",
"\n",
" Summary Category \\\n",
"22 An explosion caused damage to the Greek-operat... Aviation Advisory \n",
"24 Risk analysis: Several trade unions including ... Aviation Advisory \n",
"21 The Search and Rescue Agencies of Indonesia a... Aviation Advisory \n",
"20 Hurricane Isaias is continuing to strengthen a... Aviation Advisory \n",
"23 According to Chinese and international media r... Aviation Advisory \n",
"19 On August 5, media sources reported that Beiru... Aviation Advisory \n",
"18 Flight monitoring sources are reporting a chan... Aviation Advisory \n",
"17 Updated sources are reporting that reports of ... Aviation Advisory \n",
"16 Updated media reports indicate on August 28 th... Aviation Advisory \n",
"14 Media sources indicated that British Airways f... Aviation Advisory \n",
"15 According to the latest details on 1 September... Aviation Advisory \n",
"13 Local media sources indicated on September 20 ... Aviation Advisory \n",
"\n",
" Datetime URL \n",
"22 2020-11-26 09:24:00 https://www.spglobal.com/commodityinsights/en/... \n",
"24 2020-11-19 11:24:00 https://www.wantedinrome.com/news/italy-faces-... \n",
"21 2020-10-15 07:05:00 https://www.todayonline.com/world/asia/live-up... \n",
"20 2020-07-31 23:07:00 https://www.guycarp.com/insights/2020/07/hurri... \n",
"23 2020-06-11 09:24:00 https://www.reuters.com/world/asia-pacific/rel... \n",
"19 2020-05-08 21:07:00 https://www.theguardian.com/world/2023/aug/03/... \n",
"18 2020-01-14 13:12:00 https://www.bbc.com/news/world-africa-65444282 \n",
"17 2019-10-05 08:26:00 https://www.scmp.com/magazines/post-magazine/s... \n",
"16 2019-08-28 02:37:00 https://www.google.com/search?client=safari&rl... \n",
"14 2019-03-14 17:17:00 https://www.theguardian.com/uk-news/2018/jul/2... \n",
"15 2019-01-09 10:10:00 https://www.guycarp.com/insights/2019/09/weath... \n",
"13 2018-09-21 13:06:00 https://www.guycarp.com/insights/2020/07/hurri... \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/65/44v_jv_n0qx33txj6vvbf1k00000gn/T/ipykernel_31218/1610732821.py:15: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
" filtered_df['Datetime'] = pd.to_datetime(filtered_df['Datetime'])\n",
"/var/folders/65/44v_jv_n0qx33txj6vvbf1k00000gn/T/ipykernel_31218/1610732821.py:15: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" filtered_df['Datetime'] = pd.to_datetime(filtered_df['Datetime'])\n"
]
}
],
"source": [
"import pandas as pd\n",
"\n",
"\n",
"def rank_related_articles(file_path, category):\n",
" # Load the existing data from the CSV file\n",
" try:\n",
" df = pd.read_csv(file_path)\n",
" except FileNotFoundError:\n",
" print(\"Database file not found.\")\n",
" return\n",
"\n",
" # Filter articles by the specified category\n",
" filtered_df = df[df[\"Category\"] == category]\n",
"\n",
" # Convert 'Datetime' from string to datetime objects for accurate sorting\n",
" filtered_df[\"Datetime\"] = pd.to_datetime(filtered_df[\"Datetime\"])\n",
"\n",
" # Sort articles by 'Datetime' in descending order to get the most recent articles first\n",
" sorted_df = filtered_df.sort_values(by=\"Datetime\", ascending=False)\n",
"\n",
" # Display the sorted DataFrame\n",
" print(sorted_df[[\"id\", \"Headline\", \"Summary\", \"Category\", \"Datetime\", \"URL\"]])\n",
" return sorted_df\n",
"\n",
"\n",
"# Example usage\n",
"file_path = \"cleaned_data1.csv\"\n",
"category = \"Aviation Advisory\"\n",
"ranked_articles = rank_related_articles(file_path, category)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+----+-------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n",
"| id | Headline | Summary | Category | Datetime | URL |\n",
"+----+-------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n",
"| 28 | UPDATE 1 - Attacks on tanker and oil facility indicate growing Houthi intent and capacity to target Saudi strategic infrastructure | An explosion caused damage to the Greek-operated Agrari oil tanker on 25 November while it was about to depart from Saudi Arabia’s port of Shuqaiq in the Jizan region bordering Yemen. The incident came after Yemen-based Houthi militants fired a cruise missile at a Saudi oil facility in the port city of Jeddah on 23 November.Men stand by debris following an attack at the Saudi Aramco oil facility in Saudi Arabia’s Red Sea city of Jeddah on 24 November 2020.Photo by Fayez Nureldine/AFP via Getty ImagesThe attacks are part of the ongoing Houthi campaign targeting strategic infrastructure in Saudi Arabia, which has intensified since early September. The Greek operator of the oil tanker, TMS Tankers, stated that the tanker was “struck about one meter above the waterline and has suffered a breach”, and added that no injuries were reported. Although local and international media speculated that the tanker was hit by a naval mine, Saudi officials described the incident as a “foiled terrorist act” that occurred when an explosive-laden boat launched by the Houthis was intercepted and destroyed. Either way, IHS Markit assesses that the Houthi are the likely perpetrator of the attack, as the militia has used both marine vehicle-borne improvised explosive devices (UM-VBIEDs) and floating naval mines to target Saudi commercial and military vessels in the Red Sea. No other group has similar capabilities to target Saudi Arabia.The attack on Jeddah demonstrates that the Houthi are still developing more sophisticated missile capabilities. Saudi officials have acknowledged the attack on Jeddah and satellite imagery accessed by IHS Markit confirmed the damage at a fuel tank at Jeddah distribution station. The Houthis stated that attack was perpetrated using a new cruise missile, called Quds-2, which they have not yet publicly unveiled. Houthi military spokesperson Yahya Saree, however, said in an interview released on Houthi social media channels that the new missile was developed to fly at lower altitudes with the aim of reducing the effectiveness of anti-missile systems deployed in Saudi Arabia. A member of the Houthi political bureau, Abd al-Wahhab al-Mahbashi, also stated that the missile was being developed to target the city of Eilat, Israel's southernmost city on the Red Sea, given its growing diplomatic rapprochement with Saudi Arabia. The immediate requirement for the missile was to target Jeddah given Saudi ongoing military operations in Yemen against the movement. The latest threat, which extends to Israel, reflects the propensity of the Houthi’s leadership to further escalate against the coalition by expanding its target set. There has been no evidence, however, of Yemeni insurgent use of missiles with a longer range than 1,100 km, which is not sufficient to target Eilat (approximately 1,600 km from the Houthi-controlled northernmost point in Yemen’s Sadaa province). Any attack on Israel would almost certainly bring a very heavy response, not just from Israel but likely from the United States as well. Houthi cross-border attacks into Saudi Arabia and maritime attacks are likely to intensify, as long as the movement and the coalition do not resume formal negotiations. These attacks reflect the current impasse in peace talks brokered by the United Nations, which have failed to produce any tangible outcome since the Hodeidah ceasefire was signed in December 2018. The likely resumption of Saudi airstrikes in Yemen in response to recent attacks, especially around Sanaa, is expected to lead the movement to intensify its cross-border attacks into Saudi Arabia with missiles and armed drones, with airports, oil facilities, and desalination plants in the south of Saudi Arabia at highest risk, particularly Jizan, Abha, and Najran. Given the group’s ready access to UM-VBIEDs and sea mines, the Red Sea coast is also very likely to continue to be an area of active targeting by the Houthi.Indicators of changing risk environmentIncreasing riskHouthi militants start probing attacks on the northern section of the Red Sea, indicating intent to strike Israel.Houthi militants successfully stage an attack using a combination of cruise missiles and drones, inflicting significant damage to Riyadh or Jeddah airport.Houthi militants stage a cross-border ground attack and seize territory inside Saudi Arabia.Saudi Arabia launches a new campaign of precision airstrikes with Israeli support killing high-profile Houthi leaders.Israel starts covert operations in Yemen.Decreasing riskThe UN calls for a new round of peace talks and both Saudi Arabia and the Houthis agree to implement a ceasefire.© 2020, IHS Markit Inc. All rights reserved. Reproduction in whole or in part without permission is prohibited. | Aviation Advisory | 2020-11-26 09:24:00 | https://www.spglobal.com/commodityinsights/en/market-insights/latest-news/oil/032524-houthis-threaten-saudi-arabias-oil-installations-for-supporting-us-aggression |\n",
"| 30 | WATCH FOR: Road, rail, air, and maritime cargo and transport disruption in Italy during general strike on 25 November | Risk analysis: Several trade unions including USB, Osp Filt-Cgil, Uilt-Uil, Faisa-Cisal, and Confail have called for a general strike of the public transport sector on 25 November. The strike will last four hours and is likely to disrupt road, rail, marine, and air transport and cargo across Italy on the day of the strike. Delays and cancellations to train, bus, taxi, and ferry services, scheduled flights, and shipping operations will be likely at railway stations including Milano Centrale and Roma Termini, airports including Milan Malpensa (MXP) and Rome Ciampino (CIA), and ports including the Port of Genoa and Port of Gioia Tauro. Minimum services will be guaranteed under Italian law.© 2020, IHS Markit Inc. All rights reserved. Reproduction in whole or in part without permission is prohibited. | Aviation Advisory | 2020-11-19 11:24:00 | https://www.wantedinrome.com/news/italy-faces-national-general-strike-by-public-sector-workers-on-25-november.html |\n",
"| 27 | The Search and Rescue Agencies of Indonesia and Singapore started its 38th | The Search and Rescue Agencies of Indonesia and Singapore started its 38th Joint Exercise 2020 in Pangkalpinang on the prevention of accidents on vessels and aircraft in an effort to strengthen bilateral ties between both the nations. | Aviation Advisory | 2020-10-15 07:05:00 | https://www.todayonline.com/world/asia/live-updates-day-6-jan-2-search-airasia-flight-qz8501 |\n",
"| 22 | Hurricane Isaias to Impact Florida Coast this Weekend Before Moving up the Eastern Seaboard | Hurricane Isaias is continuing to strengthen as it moves through the Bahamas towards the east Florida coast. The storm is currently a Category 1 hurricane on the Saffir-Simpson wind scale, with winds of at least 75 miles per hour. Strengthening is expected beginning Friday night and the storm may increase to a Category 2 hurricane. The current forecast shows Isaias skirting the east coast of Florida beginning Saturday night before moving up the East Coast. Landfall is currently forecast sometime on Monday near the South Carolina-North Carolina border. Isaias will then weaken into a tropical storm and is expected to continue moving up the coast, potentially impacting the Northeast coast. Some uncertainty in the track of the storm remains and its possible the storm makes landfall along the upper east coast of Florida late Sunday in addition to the expected landfall in the Carolinas. The National Hurricane Center (NHC) has issued a hurricane warning for portions of the central and southern Atlantic Florida coasts. A state of emergency has been issued for the entire eastern Florida coast as well as for the states of North Carolina and Virginia. | Aviation Advisory | 2020-07-31 23:07:00 | https://www.guycarp.com/insights/2020/07/hurricane-isaias-threatens-much-of-eastern-us-seaboard.html |\n",
"| | | | | | |\n",
"| | | | | | |\n",
"| | | | | | |\n",
"| | | Assessment: As of this writing, the only evacuations issued are on Ocracoke Island in North Carolina. Evacuations remain a possibility for the coast of Florida as the storm continues to move closer to land and the hurricane track evolves. Airport closures and flight delays also remain a possibility both along the eastern coast of Florida, as well as up the rest of the East Coast as the storm moves up the coastline. Portions of Florida and the Carolinas are forecast to see upwards of five inches of rain and flash flooding is possible along the entire east coast of the United States. Similarly, port closures remain a possibility but as of this writing, none have been issued. Several ports in Florida, South Carolina, North Carolina, and Virginia have been set to Port Condition Whiskey. This means that ports remain open to all commercial and cargo operations but commercial vessels greater than 500 gross tons should begin making plans to depart the port. The strong winds from Isaias are likely to cause widespread power outages across the eastern seaboard. Some outages may be prolonged for multiple days depending on other impacts caused by the storm. Those with interests along the U.S. East Coast are advised to continue monitoring the situation closely. The public should use extreme caution in storm conditions and heed all weather warnings and instructions from local authorities. | | | |\n",
"| 29 | UPDATE 1 - Australia unlikely to directly retaliate against mainland China’s targeted measures; foreign policy position also unlikely to change | According to Chinese and international media reports, Chinese traders have received an informal notice from authorities that Australian products in seven categories – barley, sugar, lobster, wine, timber, coal, and copper ore and concentrate – will not be cleared in customs from 6 November. The Chinese government has denied that there are any restrictions on Australian commodities, and the implementation of the notice has yet to be confirmed. Australian exporters have nevertheless already cancelled shipments to China and Chinese traders have cancelled orders.The timing and extent of Chinese action against Australian imports give credibility to recent media reporting that this reflects Chinese government policy and not just buyers’ commercial decisions. China-Australia relations have deteriorated significantly in recent months, particularly after the Australian government called for an independent inquiry into the origins of coronavirus disease 2019 (COVID-19) in April. Beginning in May, Chinese authorities imposed a series of restrictions on Australian imports, ostensibly due to alleged breaches of trade practices (resulting in tariffs on barley) or quality issues found during routine product inspections (affecting some shipments of beef, barley, lobster, and timber). On 9 October, there were reports that some Chinese ports had been told not to accept Australian coal. Although coal import quotas are not uncommon, this came days after a meeting between foreign ministers of the recently revived Quadrilateral Security Dialogue (Quad) nations, comprising Australia, India, Japan, and the United States. China has previously labelled the Quad as an “Asian NATO” (see Australia-India-Japan-US:2 October 2020: Future of Australia-India-Japan-US Quad dialogue and maritime security in the Indo-Pacific). Australian Trade Minister Simon Birmingham has accused China of taking “discriminatory action” against Australia in imposing import restrictions. China has repeatedly denied any targeting of Australia, stating that reduced imports were the result of buyers’ decisions.Given its vulnerability to wider Chinese discrimination against Australian imports, the Australian government is unlikely to retaliate. According to the Australian Department of Foreign Affairs and Trade, China accounted for 32.6% (AUD153.2 billion, or USD111.1 billion) of its total goods and services exports in the financial year ending 2019. According to China’s National Bureau of Statistics, Australia in 2019 only accounted for 1.9% of mainland Chinese exports globally and 3.8% of mainland China’s exports to the Asia-Pacific and Oceania regions. This indicates that, while China has scope to extend restrictions on other Australian imports, Australia is unlikely to respond in reciprocal measures and equivalent degree. Rather, the Australian government will probably increase conciliatory advances towards China, notably through public statements on the importance of the bilateral relationship. The government is also likely to rein in backbenchers, both within the Liberal-National coalition and the Labor Party opposition, who frequently criticise China publicly. In addition, Australia will probably refrain from taking a prominent role in any further international initiatives challenging China, as it did in April when it led an international call for a COVID-19 inquiry. Repeated Chinese import restrictions are unlikely to result in Australian reversal on foreign policy issues challenged by China, however. Although Australia will avoid taking a prominent role in future international initiatives against China, its participation in the ongoing India-Japan-US Malabar naval exercise this month indicates that the Australian government is unlikely to reverse core policies that are at odds with China. This includes Australia’s commitment to the Quad grouping and its stance on issues such as Hong Kong SAR and the South China Sea. Participation in the current Malabar exercise contrasts with the last time Australia took part in 2007: China’s negative response resulted in the government of then-prime minister Kevin Rudd withdrawing from the exercises and accompanying security talks, resulting in the dissolution of the Quad. Nevertheless, given its economic vulnerability vis-à-vis China, Australia will probably seek to adjust its approach to the Quad and other regional defence activities by minimising its profile. Indicators of changing risk environmentIncreasing riskIf November and December 2020 shipments of Australian coal continue to show signs of regulatory targeting indicated by significant congestions in major ports in mainland China, this would further signal worsening bilateral relationships due to Beijing’s evident refusal to lift restrictions on Australian coal during the winter months – traditionally a period of higher power consumption and coal demand.If China imposes import restrictions or heightens regulatory barriers against Australian iron ore, this would indicate a significant worsening of bilateral relations. In 2019, 62% of China’s iron ore imports came from Australia. The economic cost of Chinese targeting of iron ore would likely be disproportionally borne in China’s infrastructure sector, which remains important in its investment-led economic recovery and relies on an inexpensive and stable supply of steel. Targeted measures against iron ore would indicate both a long-term policy shift of trade diversion from Australia to alternative markets for raw materials as well as intent to significantly damage the Australian economy, given that iron ore is Australia’s largest export to China.The passage into law of draft Australian federal legislation affecting foreign, particularly Chinese, commercial interests in Australia – likely in January 2021 (see Australia:8 June 2020: Proposed changes to Australia’s foreign investment rules likely to target Chinese investors, increasing risk of forced divestments and Australia:4 September 2020: Australia’s proposed legislation on agreements between states/territories and foreign governments indicates increased likelihood of state contract cancellation) – would be a further indicator of the trajectory of relations between Australia and China. Any amendments targeting Chinese interests more explicitly would probably result in a further deterioration of relations, increasing the likelihood of further restrictions on Australian goods and services or other targeted measures against Australian assets.Decreasing riskDirect talks between either Australian Prime Minister Scott Morrison and Chinese President Xi Jinping or their respective foreign ministers would increase the likelihood of an improvement in relations.Any delays or a government reversal on passing the draft legislation affecting Chinese interests would slightly decrease the likelihood of further Chinese restrictions on Australian products, as long as Australia avoids further high-profile diplomatic confrontations with China.© 2020, IHS Markit Inc. All rights reserved. Reproduction in whole or in part without permission is prohibited. | Aviation Advisory | 2020-06-11 09:24:00 | https://www.reuters.com/world/asia-pacific/release-journalist-unlikely-shift-australias-china-policy-2023-10-12/ |\n",
"| 21 | Beirut International Airport suffers damage from port explosion | On August 5, media sources reported that Beirut International Airport has suffered damage from the port explosion on August 4. Rafic Hariri International Airport is located 10 kilometers from where the epicenter of the explosion was located. So far, Emirates Airlines has confirmed that flights from Dubai to Beirut continue to operate as scheduled. This is an indication that flight operations will not be impacted by the damage. | Aviation Advisory | 2020-05-08 21:07:00 | https://www.theguardian.com/world/2023/aug/03/port-of-beirut-explosion-aftermath-scars-on-already-broken-lebanon |\n",
"| 20 | Air Arabia flight G9-661 bound for Khartoum makes U-turn over Port Sudan, heading for Jeddah | Flight monitoring sources are reporting a change in the flight plan of Air Arabia flight G9-661 bound for Khartoum on Tuesday, 14 January. The flight from Sharjah, UAE, has made a U-turn over Port Sudan and appears to be diverting to Jeddah. Although not explicitly stated there is a strong potential that this is due to a reported airspace closure of Khartoum amid reports of clashes involving sections of the security forces. | Aviation Advisory | 2020-01-14 13:12:00 | https://www.bbc.com/news/world-africa-65444282 |\n",
"| 19 | Victoria Harbour - Reports of a plane crash were erroneous. Incident closed. | Updated sources are reporting that reports of a small plane crash in Victoria Harbour were erroneous. This incident is closed. | Aviation Advisory | 2019-10-05 08:26:00 | https://www.scmp.com/magazines/post-magazine/short-reads/article/3192997/when-plane-plunged-victoria-harbour-hong-kong |\n",
"| 18 | UPDATE: Pakistan partially closes 3 international routes over Karachi until August 31; India threatens to block ships bound for Karachi Port in retaliation | Updated media reports indicate on August 28 that Pakistan has closed three aviation routes over Karachi from August 28-31, according to the country’s civil aviation authority, after a senior Pakistani minister stated a day earlier that the government was contemplating a complete ban on Indian flights using the country’s airspace. The four-day ban will reportedly expire on September 1. Pilots have been provided with an alternate route to get around restrictions on the Karachi airspace. Reports suggest that the decision was reportedly taken to allow for possible missile test firing in light of recent rising bilateral tensions. In retaliation, senior Indian politician and Bharatiya Janata Party (BJP) leader suggested on Twitter that India should respond by blocking ships bound for the Port of Karachi by placing a naval blockade in the Arabian Sea. Pakistan previously lifted all commercial restrictions over Pakistani airspace on the morning of July 16 after the airspace was closed to civilian flights from February 27 due to tensions between India and Pakistan in the Kashmir region. Bilateral tensions have been simmering this month after Indian Prime Minister Narendra Modi revoked Kashmir’s special status. Customers are advised to monitor developments closely and re-route shipments through alternative air and land transport routes should Pakistan decide to close the airspace indefinitely. | Aviation Advisory | 2019-08-28 02:37:00 | https://www.google.com/search?client=safari&rls=en&q=UPDATE%3A+Pakistan+partially+closes+3+international+routes+over+Karachi+until+August+31%3B+India+threatens+to+block+ships+bound+for+Karachi+Port+in+retaliation&ie=UTF-8&oe=UTF-8 |\n",
"| 15 | Gatwick Airport (LGW) - British Airways flight 2068 made an emergency landing. Incident closed. | Media sources indicated that British Airways flight 2068 from Port Louis to London made an emergency landing at Gatwick Airport (LGW) due to an unspecified emergency. No injuries were immediately indicated. This incident is closed. | Aviation Advisory | 2019-03-14 17:17:00 | https://www.theguardian.com/uk-news/2018/jul/20/british-airways-plane-in-emergency-landing-at-gatwick |\n",
"| 17 | UPDATE - USA: Hurricane Dorian forecast to impact coasts of Georgia and Carolinas, as well as Florida | According to the latest details on 1 September, Hurricane Dorian remains at Category 4 strength as it moves westwards at 8 mph, with maximum sustained winds of 150 mph; just shy of Category 5. Peak winds are predicted to increase to 155 mph. The weather system, previously heading towards Florida's Atlantic coast, is now forecast to target the coasts of Georgia and the Carolinas, where it may approach as a Category 2 system, bringing life-threatening storm surges. The cities of Brunswick, GA; Charleston, SC; and Wilmington, NC, could all see more than six inches of rainfall. A number of Florida’s mandatory evacuation orders have since been postponed, though voluntary requests for evacuations remain across several counties. A significant storm surge and devastating hurricane-force winds are both possible along portions of Florida’s east coast by the early-to-middle part of next week. Even while the majority of computer models predict Dorian to remain just offshore of Florida, officials have warned of significant and potentially devastating impacts. A stretch of Florida's east coast, from Deerfield Beach to Sebastian Inlet, is under a Tropical Storm Watch. Since the storm is predicted to slow down and turn northward as it approaches, the effects from wind, rain and storm surges could be prolonged. Nevertheless, the storm's path could still change and fluctuations in intensity are likely. However, irrespective of the storm’s ultimate course, significant coastal flooding is to be expected. | Aviation Advisory | 2019-01-09 10:10:00 | https://www.guycarp.com/insights/2019/09/weather-sentinel-category-5-dorian-labor-day-update.html |\n",
"| 14 | Delta Flight 472 met by PAPD firefighters at JFK due to brake smoke | Local media sources indicated on September 20 that Delta flight 472 from Sao Paulo Guarulhos International Airport to New York’s JFK International Airport was met by Port Authority Police Department firefighters upon its landing at 5:30AM on September 20 after reports of smoking brakes. The Delta 767 initially reported overheating brakes mid-air shortly after landing, and the passengers were deplaned normally, with no injuries to report. | Aviation Advisory | 2018-09-21 13:06:00 | https://www.guycarp.com/insights/2020/07/hurricane-isaias-threatens-much-of-eastern-us-seaboard.html |\n",
"+----+-------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/65/44v_jv_n0qx33txj6vvbf1k00000gn/T/ipykernel_31218/2109249609.py:7: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
" df['Datetime'] = pd.to_datetime(df['Datetime'])\n"
]
}
],
"source": [
"import pandas as pd\n",
"from tabulate import tabulate\n",
"\n",
"\n",
"def print_ranked_articles_tabulate(file_path, category):\n",
" try:\n",
" df = pd.read_csv(file_path)\n",
" df[\"Datetime\"] = pd.to_datetime(df[\"Datetime\"])\n",
" filtered_df = df[df[\"Category\"] == category]\n",
" sorted_df = filtered_df.sort_values(by=\"Datetime\", ascending=False)\n",
"\n",
" # Print DataFrame using tabulate\n",
" print(tabulate(sorted_df, headers=\"keys\", tablefmt=\"pretty\", showindex=False))\n",
" except FileNotFoundError:\n",
" print(\"Database file not found.\")\n",
"\n",
"\n",
"# Example usage\n",
"file_path = \"cleaned_data1.csv\"\n",
"category = \"Aviation Advisory\"\n",
"print_ranked_articles_tabulate(file_path, category)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|