-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrote code to pick out strongest earthquakes #3
base: main
Are you sure you want to change the base?
Conversation
|
||
data_asdict = json.loads(text) | ||
with open('response.json', 'w') as file: | ||
file.write(json.dumps(data_asdict, indent=4)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of indent!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, using indent=...
makes for a much more readable file.
You can make the code a bit shorter by using json.dump
, which will essentially do the same as dumps
and then write
.
print(f"The strongest earthquakes were at coordinates of {max_location} with magnitude {max_magnitude}, There were two earthquakes with equal largest magnitude") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job spotting that there were two earthquakes with equal magnitude
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done.
@@ -3,6 +3,8 @@ | |||
# However, we will use a more powerful and simpler library called requests. | |||
# This is external library that you may need to install first. | |||
import requests | |||
import yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this import here since you're not working with YAML!
"The text is in dictionary format, under a string" | ||
"get dictionary out using json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good to write comments to explain what you're doing and why, as you do here and later, though note that in Python comment lines should start with a a #
. You can leave multi-line comments enclosed in """..."""
, but those are best reserved for documenting functions etc ("docstrings").
|
||
data_asdict = json.loads(text) | ||
with open('response.json', 'w') as file: | ||
file.write(json.dumps(data_asdict, indent=4)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, using indent=...
makes for a much more readable file.
You can make the code a bit shorter by using json.dump
, which will essentially do the same as dumps
and then write
.
"for each event, 'mag' key gives magnitude. 'place' key gives place name, but 'geometry' 'coordinates'" | ||
"gives the coordinates of the location" | ||
"The time of the earthquake claims to use the ISO8601 Date/Time format, but this doesn't appear true..." | ||
"What does 'time'=956553055700 mean? Seconds since something?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully this was clarified in the classwork exercise!
index_of_max = [index for index, item in enumerate(magnitudes) if item == max_mag] | ||
max_locs = locations[index_of_max[0]], locations[index_of_max[1]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said in another review, good job making this general enough to handle multiple earthquakes with the same magnitude.
Answers UCL-MPHY0021-21-22/RSE-Classwork#13
was useful to practice with json/yaml files.
Found two events with same max magnitude.