Giter Site home page Giter Site logo

max-le / cs50_predictor Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 249 KB

A website to place virtual bets on sport events. Built with Flask and SQLite, as my final project assignment for Harvard's CS50.

Home Page: http://predictor-foot.herokuapp.com/

Python 73.69% HTML 23.66% CSS 1.52% Mako 1.14%

cs50_predictor's Introduction

Predictor

Try to guess the outcome of soccer events and earn points for your right predictions !

The project is deployed on Heroku : http://predictor-foot.herokuapp.com/

Description

This is my final project for the online course CS50's Introduction to Computer Science.

This is basically like a betting website, but instead of betting ( and losing ) your money, you just earn points for correct decisions.

As the CS50 Finance assignement, the project uses the web-framework Flask.

Data used on this project is provided API-Football.com.

Technical aspects :

I didn't change much the file organization of this project from CS50 Finance :

  • app.py contains the "main" code : it is executed when running flask run. It contains all the routes and thus handles HTTP requests.
  • HTML Pages are in /templates folder. CSS and favicon.ico are in /static folder.
  • helpers.py holds functions that I wanted to externalize from app.py and functions already written by CS50 ( like the meme apology ).
  • I created helpers_test.py to test several important functions ( unittest library ).

I published a diagram that I used as a blueprint for the architecture of the code : check it out here if you want.

Features

  • Place a bet on a upcoming fixture : try to guess the final score of the match. The homepage ( index.html ) shows several upcoming matches for a football championship.

  • Once the match is finished, the server checks your prediction with the final score :

    • You get 3 points if you predicted the exact score.
    • You get 1 point if you're right about winning and losing team or if you predicted a draw, but not the right number of goals.
    • Otherwise, you don't get points for the match.

The table in the database containing all the informations about fixtures is refreshed every 30 minutes.

  • See the your activity on the page "My bets".
  • For testing purposes, it is possible to bet on past events using the route /past_fixtures . Of course this cannot be possible for the final user.

Installation

First of all, you should obviously download the project of your machine. You need an account on API-Football.com in order to get an API key. ( basic account is free ). The code reads the API key from a external file named "api.key", so once you managed to get your key in API-Football.com, create a file named "api.key" ( .key is the extension ). In Terminal, you can navigate to the directory and type

touch api.key

Open the file and paste your key in the file, just plain text, no quote.

  1. You need Python on your machine to work in this project : Get Python. ( I was using Python 3, not sure if it is important to use v.3 instead of v.2 )
  2. Install Flask. CS50's library is also used for this project ( for connecting with the database ). Install it all by typing in terminal :

pip3 install CS50 Flask Flask-session requests

  1. The database is not included on this repository : you need to create one. The database system is SQLite3. Make sure it is installed on your machine.

    Type

    touch predictor.db

    Terminal on root directory of the project.

    The database's name has to be "predictor.db". ( You can change that, but then you'll also need to edit the source code ).

    The database has three tables : Fixtures ( list all the events ), Bets ( all users predictions), and Users ( list of all users registered ) The instructions to create thoses tables are provided in the "init_db.sql" file, so you can run it :

    Type in terminal :

    sqlite3 predictor.db

    Then

    .read init_db.sql

    Press Ctrl + D to exit Sqlite.

Usage

Once everyting's installed :

Type

flask run

on a terminal window, it will execute app.py and start the server. To make the server visible on all local network :

flask run --host=0.0.0.0

Port 5000 by default, so access in web browser locally using :

http://localhost:5000/

Create an account on http://localhost:5000/register.

The first time you run the server, you may see an empty table on the home page. That's normal, the database you created is empty. You need to update the database manually. I made a function in helpers.py that fetchs the data via an API Call and add and updates the Fixtures table. You can call it via a query string in the route /update_fixtures with the ID of the league as a argument. For example, in order to add and updates French Ligue 1's fixtures that would be :

http://localhost:5000/update_fixtures?id=525

On a local server.

Here's a few IDs of the leagues available on API-Football.com :

754= Current Bundesliga, 656=Current Pro League, 525=Ligue 1, 524 = England Premier League

Of course, the full list can be retrieved using an API Call to their service.

Roadmap

Ideas for further development of the project :

  • More standard registration : require email adress and minimum complexity for password, not just a username.
  • More social : compare your total score and predictions with your friends.
    • Invite friends to join ( send email )
    • Create parties and rank users.
  • Ability to switch leaguess

cs50_predictor's People

Contributors

max-le avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

mehalyna

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.