Created
August 1, 2023 13:29
-
-
Save mayankt18/eaa46bdb3398d758400e27f6b47bff04 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def asteroidOrbits(year, orbitclass): | |
r=requests.get("https://jsonmock.hackerrank.com/api/asteroids/search?page="+str(1)).json() | |
total_pages=r["total_pages"] | |
list=[] | |
for i in range(1,total_pages+1): | |
req=requests.get("https://jsonmock.hackerrank.com/api/asteroids/search?page="+str(i)).json() | |
for j in req["data"]: | |
if(str(year)==j["discovery_date"][:4]and orbitclass.lower() in j["orbit_class"].lower()): | |
if (j.get("period_yr")) == None: | |
j["period_yr"] = 1 | |
j["period_yr"] = float(j["period_yr"]) | |
list.append(j) | |
list.sort(key=lambda x:(x["period_yr"], x["designation"])) | |
desg = [] | |
for j in list: | |
desg.append(j["designation"]) | |
return desg | |
if _name=='main_': | |
fptr = open(os.environ['OUTPUT_PATH'], 'w') | |
year = int(input().strip()) | |
orbitclass = input() | |
result = asteroidOrbits(year, orbitclass) | |
fptr.write('\n'.join(result)) | |
fptr.write('\n') | |
fptr.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment