so I am playing with Rawg.io 's API. U can sort their game list by their release date, however there are just too many games. In their website, there's an option called "Popular only", which only shows games that are being followed by at least 1 people.
I implemented this feature by sorting the elements I get and creating a sorted list. I wanted to make sure that I would also acces their information in a systematically way ([game's number], [name or other topic]).
(the ##delete## parts are parts that are just for console visuals, I am planning to move this project to a Kivy app, so won't need them later)
I really want to know what I could have done differently. What's obnoxious, stupid, ... could be better?
import requests
######Delete#########
import os
os.system("cls")
###################
#### Functions
def _Url(year1, month1, day1, year2, month2, day2, PageNumber=1):
if month1 < 10:
month1 = "0" + str(month1)
if day1 < 10:
day1 = "0" + str(day1)
if month2 < 10:
month2 = "0" + str(month2)
if day2 < 10:
day2 = "0" + str(day2)
Url = (
"https://api.rawg.io/api/games?dates="
+ str(year1)
+ "-"
+ str(month1)
+ "-"
+ str(day1)
+ ","
+ str(year2)
+ "-"
+ str(month2)
+ "-"
+ str(day2)
+ "&page="
+ str(PageNumber)
+ "&platforms=4,187,1,18,186&page_size=40&ordering=released"
)
return Url
def _GetData_Date(year1=2020, month1=8, day1=4, year2=2020, month2=8, day2=4): #just place holder values
Url = _Url(year1, month1, day1, year2, month2, day2)
StaticData = requests.get(Url).json()
AmountOfGames = StaticData["count"]
AmountOfPages = AmountOfGames // 40 #1 page contains 40 so it does amount//40 to get pages
if(AmountOfGames%40 != 0):
AmountOfPages = AmountOfPages + 1 #does +1 if there's a leftover page
PageNumber = 1
#############Delete############
Succes = 0
Fail = 0
#########################
while PageNumber <= AmountOfPages:
for x in range(len(StaticData["results"])):
if StaticData["results"][x]["added"] > 0:
try: #can't start with an empty Game variable
AStaticData = (StaticData["results"][x],) # the ","turns it to tulpe, it keeps adding tulpes to 1 giant one that contains all the filtered information
Game = Game + AStaticData
except:
AStaticData = (StaticData["results"][x],) # the ","turns it to tulpe
Game = AStaticData
############################Delete#################
os.system("cls")
Succes = Succes + 1
print("succes: ", (Succes))
print("fail:", Fail)
print("Total:", AmountOfGames, Succes + Fail)
else:
os.system("cls")
Fail = Fail + 1
print("succes: ", (Succes))
print("fail:", Fail)
print("Total:", AmountOfGames,"-", Succes + Fail)
##################################################
# goes trough pages
PageNumber = PageNumber + 1
if PageNumber <= AmountOfPages:
Url = _Url(year1, month1, day1, year2, month2, day2, PageNumber)
StaticData = requests.get(Url).json()
return Game
#### Save it to local variables #####
StaticData =_GetData_Date()
### Main program ###################
for x in range(len(StaticData)):
print(StaticData[x]["name"])