Question: Need help with a Python CSV-to-JSON filter, thanks a lot The following is some examples of csv filesvessel raw data.txt) IMO number|1000007;Name of the ship|ATHINA;Vessel

Need help with a Python CSV-to-JSON filter, thanks a lot

Need help with a Python CSV-to-JSON filter, thanks a lot The following

is some examples of csv filesvessel raw data.txt) IMO number|1000007;Name of theThe following is some examples of csv filesvessel raw data.txt) IMO number|1000007;Name of the ship|ATHINA;Vessel type|Yacht;Flag|Liberia;Length|38 m;Breadth|7 m;Description|ATHINA is a Yacht.;Seafarers worked on|No sea service records found IMO number|1000019;MMSI|235095435;Name of the ship|LADY K II;Former names|LADY K II (2012, Panama)%RADIANT II (2009)%PRINCESS TANYA (1961)%COLUMBINE%;Vessel type|Yacht;Operating status|Active;Flag|United Kingdom (UK);Gross tonnage|551 tons;Deadweight|164 tons;Length|57 m;Breadth|8 m;Engine type|Sulzer;Engine power|1236 KW;Year of build|1961;Builder|A&P GROUP - SUNDERLAND, U.K.;Classification society|LLOYD'S SHIPPING REGISTER;Owner|AZURE MARITIME - LUGANO, SWITZERLAND;Manager|AZURE MARITIME - LUGANO, SWITZERLAND;Description|LADY K II is a Yacht built in 1961 by A&P GROUP - SUNDERLAND, U.K.. Currently sailing under the flag of United Kingdom (UK). Formerly also known as LADY K II, RADIANT II, PRINCESS TANYA, COLUMBINE. It's gross tonnage is 551 tons.;Seafarers worked on|1 service record found IMO number|1000021;MMSI|319904000;Name of the ship|MONTKAJ;Former names|MONTKAJ (2013, Cayman Islands)%RHINE%;Vessel type|Yacht;Operating status|Active;Flag|Cayman Islands;Gross tonnage|2000 tons;Deadweight|484 tons;Length|78 m;Breadth|13 m;Year of build|1995;Builder|SLOB SCHEEPSWERF PAPENDRECHT;Classification society|LLOYD'S SHIPPING REGISTER;Home port|GEORGE TOWN;Owner|AL BILAD - RIYADH, SAUDI ARABIA;Manager|AL BILAD - RIYADH, SAUDI ARABIA;Description|MONTKAJ is a Yacht built in 1995 by SLOB SCHEEPSWERF PAPENDRECHT. Currently sailing under the flag of Cayman Islands. Formerly also known as MONTKAJ, RHINE. It's gross tonnage is 2000 tons.;Seafarers worked on|No sea service records found IMO number|1000033;MMSI|234028000;Name of the ship|ASTRALIUM;Former names|POWERFUL%;Vessel type|Yacht;Operating status|Active;Flag|United Kingdom (UK);Gross tonnage|178 tons;Length|31 m;Breadth|7 m;Year of build|1995;Builder|LOWLAND YACHTS - ZOETERWOUDE, NETHERLANDS;Description|ASTRALIUM is a Yacht built in 1995 by LOWLAND YACHTS - ZOETERWOUDE, NETHERLANDS. Currently sailing under the flag of United Kingdom (UK). Formerly also known as POWERFUL. It's gross tonnage is 178 tons.;Seafarers worked on|No sea service records found
The following is some examples of csv filesimo to callsign and type.txt)
IMO Callsign VesselType 5898610 WCY5117 Pusher/Tug 5683467 RAI Pusher/Tug 5557230 B9037 Fishing vessel 5481900 VORD Pusher/Tug 5429201 D2D8G2 Pusher/Tug 5429081 ERAH Special Purpose 5428817 XPMB Fishing vessel 5428702 E5U2579 Pusher/Tug 5428439 PPPS Special Purpose 5428233 OJOR Ship 5427784 JVWG6 Pilot tender 5427631 MHMV Ship 5427370 EILZ Special Purpose 5427019 SALVOR Pusher/Tug 5425619 SV6732 Pusher/Tug 5424990 UIBX Tanker 5424562 LIXN Passenger ship 5424380 TFAA Special Purpose 5423788 CFD8101 Fishing vessel 5422540 SGFI Passenger ship 5422203 OITW Liquefied gas carrier 5420724 HP6016 Pilot tender 5419244 DDTC Pusher/Tug 5419086 CYJZ Yacht 5418719 CFD7756 Fishing vessel 5418381 5VAQ5 Oil tanker 5418197 UBWX Ice breaker 5417753 SV4195 Ship 5417210 XPPI Trawler 5416852 SEIP RoRo ship 5416553 HP5608 Passenger ship 5416280 3WGU General cargo vessel 5415092 CB4277 Cargo ship 5414464 HO4478 General cargo vessel 5412026 OIWX Pusher/Tug 5411917  Ship 5409586 CYLY RoRo ship

This assignment has you write a short script that takes a list of vessels, and converts it into a list of JSON records, with an extra field for the call sign. The slides for Week #2 (Taming the Raw Data) provide two useful Python recipes for this project: Working with 2 files, and convert the AIS CSV files to JSON. Combine and adapt the two patterns to suit your purpose.:w INPUT: Consider the following input files: vessel raw data.txt 2 contains vessel records if the form IMO number 9500041;MMSI| 373138000; Name of the ship CENTENARIO FORZA; Former names AENTEN (2017, Panama)%;Vessel type Bulk carrier; Opera ting status Active; Flag Panama; Gross tonnage 31754 tons;Deadweight|56129 tons; Length 189 m; Breadth|32 m;Year of build|2012; Builder MIT SUI ICHIHARA ENGINEERING & SHIPBUILDING - ICHIHARA, JAPAN;Classification society NIPPON KAIJI KYOKAI (NKK); Owner |MK CENTENNIAL MARITIM E - AMSTERDAM, NETHERLANDS ; Manager |MAYBARU SHIPPING & TRADING - SINGAPORE;Description|CENTENARIO FORZA is a Bulk carrier built in 2012 by MITSUI ICHIHARA ENGINEERING & SHIPBUILDING - ICHIHARA, JAPAN. Currently sailing under the flag of Panama. Formerly also known as AE NTEN. It's gross tonnage is 31754 tons.;Seafarers worked on No sea service records found . imo to callsign and type.txt 2 contains a mapping of IMO numbers to call signs and vessel type, of the form IMO Callsign VesselType 5898610 WCY5117 Pusher/Tug 5683467 RAI Pusher/Tug 5557230 B9037 Fishing vessel 5481900 VORD Pusher/Tug 5429201 D2D8G2 Pusher/Tug 5429081 ERAH Special Purpose 5428817 XPMB Fishing vessel 5428702 E5U2579 Pusher/Tug 5428439 PPPS Special Purpose OUTPUT: The goal is to cross the data contained in both files, in order to send on the standard output (console) a list of vessels, with the following features: 1. The last two fields ('Description' and 'Seafarers worked on') of the first file are discarded 2. A 'Call Sign' field is added to a vessel record, only if the call sign matching the vessel's IMO can be found in the mapping. 3. Each vessel record should be encoded as a JSON string, one per line For example: {"Call Sign": "3EXU5", "IMO number": "9500041", "MMSI": "373138000", "Name of the ship": "CENTENARIO FORZA", "Former names": "AENTEN (2017, Panama)%", "Vessel type": "Bulk carrier", "Operating status": "Active", "Flag": "Panama", "Gross tonnage": "31754 tons", "Deadw eight": "56129 tons", "Length": "189 m", "Breadth": "32 m", "Year of build": "2012", "Builder": "MITSUI ICHIHARA ENGINEERING & SHIPBUI LDING - ICHIHARA, JAPAN", "Classification society": "NIPPON KAIJI KYOKAI (NKK)", "Owner": "MK CENTENNIAL MARITIME - AMSTERDAM, NETHERL ANDS", "Manager": "MAYBARU SHIPPING & TRADING - SINGAPORE"} INTERFACE: Your Python script is to be named cross_imo_and_callsign.py reads to the list of vessels from the standard input reads the imo/callsign mapping from the file passed as an argument Accordingly, it is to be called as follows: cat vessel_raw_data.txt | python3 cross_imo_and_callsign.py imo_to_callsign_and_type.txt This assignment has you write a short script that takes a list of vessels, and converts it into a list of JSON records, with an extra field for the call sign. The slides for Week #2 (Taming the Raw Data) provide two useful Python recipes for this project: Working with 2 files, and convert the AIS CSV files to JSON. Combine and adapt the two patterns to suit your purpose.:w INPUT: Consider the following input files: vessel raw data.txt 2 contains vessel records if the form IMO number 9500041;MMSI| 373138000; Name of the ship CENTENARIO FORZA; Former names AENTEN (2017, Panama)%;Vessel type Bulk carrier; Opera ting status Active; Flag Panama; Gross tonnage 31754 tons;Deadweight|56129 tons; Length 189 m; Breadth|32 m;Year of build|2012; Builder MIT SUI ICHIHARA ENGINEERING & SHIPBUILDING - ICHIHARA, JAPAN;Classification society NIPPON KAIJI KYOKAI (NKK); Owner |MK CENTENNIAL MARITIM E - AMSTERDAM, NETHERLANDS ; Manager |MAYBARU SHIPPING & TRADING - SINGAPORE;Description|CENTENARIO FORZA is a Bulk carrier built in 2012 by MITSUI ICHIHARA ENGINEERING & SHIPBUILDING - ICHIHARA, JAPAN. Currently sailing under the flag of Panama. Formerly also known as AE NTEN. It's gross tonnage is 31754 tons.;Seafarers worked on No sea service records found . imo to callsign and type.txt 2 contains a mapping of IMO numbers to call signs and vessel type, of the form IMO Callsign VesselType 5898610 WCY5117 Pusher/Tug 5683467 RAI Pusher/Tug 5557230 B9037 Fishing vessel 5481900 VORD Pusher/Tug 5429201 D2D8G2 Pusher/Tug 5429081 ERAH Special Purpose 5428817 XPMB Fishing vessel 5428702 E5U2579 Pusher/Tug 5428439 PPPS Special Purpose OUTPUT: The goal is to cross the data contained in both files, in order to send on the standard output (console) a list of vessels, with the following features: 1. The last two fields ('Description' and 'Seafarers worked on') of the first file are discarded 2. A 'Call Sign' field is added to a vessel record, only if the call sign matching the vessel's IMO can be found in the mapping. 3. Each vessel record should be encoded as a JSON string, one per line For example: {"Call Sign": "3EXU5", "IMO number": "9500041", "MMSI": "373138000", "Name of the ship": "CENTENARIO FORZA", "Former names": "AENTEN (2017, Panama)%", "Vessel type": "Bulk carrier", "Operating status": "Active", "Flag": "Panama", "Gross tonnage": "31754 tons", "Deadw eight": "56129 tons", "Length": "189 m", "Breadth": "32 m", "Year of build": "2012", "Builder": "MITSUI ICHIHARA ENGINEERING & SHIPBUI LDING - ICHIHARA, JAPAN", "Classification society": "NIPPON KAIJI KYOKAI (NKK)", "Owner": "MK CENTENNIAL MARITIME - AMSTERDAM, NETHERL ANDS", "Manager": "MAYBARU SHIPPING & TRADING - SINGAPORE"} INTERFACE: Your Python script is to be named cross_imo_and_callsign.py reads to the list of vessels from the standard input reads the imo/callsign mapping from the file passed as an argument Accordingly, it is to be called as follows: cat vessel_raw_data.txt | python3 cross_imo_and_callsign.py imo_to_callsign_and_type.txt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!