We have two .py files, helpers and app. In helpers, we define most of the functions that are used in app.py to access data. We access data through an API called API-FOOTBALL. They have a free program, that allows us to make 100 requests a day; that was far from enough for us, so we had to pay $20 for a month trial to have 7500 requests a day.
First, we define our apology message and login required function; we borrowed some portion of code from finance. Then we go on to write functions for accessing data from the API. The API did not give us much guidance on how to use it to access data, so we had to figure it out first by trying. After a while, we realized that we need to use a block of code to get response, and that response is based on paramameters used in the URL in the first line. We then always turn response into json object, because the api uses objects of its own that are hard to operate with.
The response is very messy, we have to use several keys and iterations to get what we actually want, so it can look very cryptic. It is hard to explain, because we had to figure it out too first by printing the data and seeing what it gives us. However, we always found our way to access what we want from the API and how to use it on our website.
We tried to make almost everything dynamic in our code and avoid hard coding, we only had to define the leagues that we are going to use in our_leagues in helpers, but if we change that, we can easily change the rest of the code accordingly. We also made a function that converts the input in app.py to search for league ids in our sql database. Then we include bunch of functions in helpers that gather data from API that are later used in other functions or directly in app.py.
We also use SQL for other purposes, for example for keeping track of bets that had been made by users. This helps us to display the history of bets on their accounts and also to store information about the bets themselves. We also use one more table for transactions; this table serves the purpose of checking whether we already paid the user their money for winning a bet, so we do not ever pay them more than once. It also helps us keep track of who is winning and who are we paying.
In app.py, we are primarily working with several routes on our website. We used some code from finance for logging in and out and for registering. By using data from the API, we display the standings and last and next round matches of each league. This information changes, therefore is updated automatically, which is a big bonus for our website. This was very hard to do, but was one of our main goals, to make an actually working and dynamic standings and matches. We have a separate route for world cup, because their standings are done in groups, which was another challenge; but we made it work after preparing our code for this possibility.
The biggest feature about world cup is the ability to bet on future matches. We gathered data from the API on what matches have available odds and displayed it on our page. After clicking a button, the form for betting is automatically filled in except the amount of money the user wants to bet. After he bets, we of course check whether he has enough money, and then store this bet in our database and redirect him to his account. Keep in mind that it can happen that there are no bets available, we can not do anything about it, we rely on the data that is given to us from the API.
On his account, we can see his balance and his bets. We added a feature that shows which bets are still active and which have already come to an end - they either win or lose. It was very hard to make this work, because we had to access this information through the API to check whether the bets are done and who won and accordingly show the user if they won or not and update their balance. But now this feature actually works, and after a match is over, the bets will automatically update and user's balance too.
As far as the design is concerned, we used some features from boostrap or used our own css. We also use flask and jinja to display the data we got from the api.
We also added some extra features like letting the user to change their password or add extra balance to their account; their default is 1000 dollars. Even though we ran to a lot of issues, for example me getting a flu and it was very hard to work with fevers and headaches, we met all of our goals and made the website the best version possible and exceeded our expectations. We did not think that we are going to be able to make the betting part work; but we did, we are very satisfied with how it turned out.