diff --git a/backend/app.py b/backend/app.py index 3de5c6cd440922cf854b0b184a0ab577b0c45880..0abae7884e251a1a4d9e9f68af16c7cc42a921ba 100644 --- a/backend/app.py +++ b/backend/app.py @@ -2,10 +2,10 @@ import os from flask import Flask, request, Response from config import Config from flask_security import Security, SQLAlchemyUserDatastore, hash_password -from models_shared import db, User, Role, SweElectionResult +from models_shared import db, User, Role, SweElectionResult, SweDemographicResult from flask_wtf.csrf import CSRFProtect from flask_talisman import Talisman -from parse_data import parse_swe_election_data +from parse_data import parse_swe_election_data, parse_swe_demographic_data # Create app app = Flask(__name__) @@ -65,19 +65,31 @@ if __name__ == '__main__': password=hash_password("admin123") ) - # Add Swedish Election Results to the DB + # Add Swedish Election Statistics to the DB result = parse_swe_election_data() - county_codes = result.keys() + county_codes = result.keys() # Integers for county_code in county_codes: county_name = result[county_code]["county_name"] - #print(type(county_code)) - #print(type(county_name)) votes_each_year = result[county_code]["parties"] + total_votes_all_years = result[county_code]["total_votes"] db_entry = SweElectionResult( db_county_code = county_code, db_county_name = county_name, - db_votes_each_year = votes_each_year # Object of type int64 is not JSON serializable + db_votes_each_year = votes_each_year, + db_total_votes_all_years = total_votes_all_years + ) + db.session.add(db_entry) + + # Add Swedish Demographic Statistics to the DB + result = parse_swe_demographic_data() + county_codes = result.keys() # Integers + for county_code in county_codes: + data = result[county_code] + + db_entry = SweDemographicResult( + db_county_code = county_code, + db_data = data ) db.session.add(db_entry)