- To get the data from the The Star Wars API server.
- Extract the 10 characters appearing in most films.
- Sort the data by height.
- Create a csv file of the sorted data.
- Upload the data on the Httpbin.org server.
git clone https://github.com/shaikh-ma/swapi_assignment/
python main.py
python test_swapi_assignment.py
- Approach 1 : Using Python Standard libraries & builtin functions if in case the 3rd party packages are not installed.
- Approach 2 : Using 3rd party libraries (like pandas, request) in case if these packages are already installed on the user system.
| Script name | What it does |
|---|---|
| main.py | This is the main script, it checks if the pandas, request libraries are available or not and selects the script based on it, to run the program. |
| assignment_with_std_libraries.py | This script uses the standard modules (urllib, json, csv) with builtin functions. |
| assignment_with_non_std_libraries.py | This script uses the 3rd party modules (pandas and requests). |
- get_data(url)
- Retrieves data from the server.
- parameter: url -> url of the server from which to get the data.
- returns the data if received, otherwise None.
- get_top_characters(json_data, max_characters=10)
- Extractes the requred data into a json object.
- Parameters :
- json_data : The json file containing the data from server.
- max_characters : Number of characters for which the data should be filtered.
- By default, extracts data for 10 characters if no value is passed.
- Returns json format for the number of characters appearing in most films.
- write_data(json_data, filename=None)
- Stores the extracted data in a csv file.
- If the file name is passed, otherwise it's named as "Exported.csv".
- The file is saved in the same folder as the script.
- Returns the filename.
- show_data(selected_characters, max_characters=None)
- Prints out the json formatted data for exported data for max_characters passed.
- post_data(url, filename='')
- Uploading the files to the server.
- url -> server URL.
- filename -> Name of the file to be uploaded.
- Returns the tuple containing response object from the request and the status code.
| Sr.no | Character name | Species | Height | Appearances |
|---|---|---|---|---|
| 1 | Darth Vader | - | 202 | 4 |
| 2 | Biggs Darklighter | - | 183 | 1 |
| 3 | Obi-Wan Kenobi | - | 182 | 6 |
| 4 | Owen Lars | - | 178 | 3 |
| 5 | Luke Skywalker | - | 172 | 4 |
| 6 | C-3PO | Droid | 167 | 6 |
| 7 | Beru Whitesun lars | - | 165 | 3 |
| 8 | Leia Organa | - | 150 | 4 |
| 9 | R5-D4 | Droid | 97 | 1 |
| 10 | R2-D2 | Droid | 96 | 6 |