from lib.wiki_scraper import WikipediaScraper 
from lib.data_rennesmetropole_scraper import RennesMetropoleScraper
from lib.immobilier_statistiques_scraper import ImmobilierStatistiquesScraper
from pandas import DataFrame
import datetime

square_02 = 'Thabor+-+Saint-H%C3%A9lier+-++Alphonse+Gu%C3%A9rin'
square_05 = 'Maurepas+-+Bellangerais'
square_06 = 'Jeanne+d%27Arc+-+Longs+Champs+-+Beaulieu'

thabor_id = 2
maurepas_id = 5
beaulieu_id = 6

search_square_02 = 'Thabor Saint Helier'
search_square_05 = 'Maurepas - Patton les Gayeulles'
search_square_06 = 'Beaulieu Baud'

# Extract wikipedia data
wiki_s = WikipediaScraper()
data = wiki_s.scrape()
metros = data['metros']
buses = data['buses']
surfaces = data['surfaces']

# Extract data from https://data.rennesmetropole.fr/
rennes_metropole_s = RennesMetropoleScraper()
equipement_02 = rennes_metropole_s.get_equip_nb(square_02)
equipement_05 = rennes_metropole_s.get_equip_nb(square_05)
equipement_06 = rennes_metropole_s.get_equip_nb(square_06)

cult_equip_02 = rennes_metropole_s.get_equip_cul(square_02)
cult_equip_05 = rennes_metropole_s.get_equip_cul(square_05)
cult_equip_06 = rennes_metropole_s.get_equip_cul(square_06)

green_areas_02 = rennes_metropole_s.get_green_areas(thabor_id)
green_areas_05 = rennes_metropole_s.get_green_areas(maurepas_id)
green_areas_06 = rennes_metropole_s.get_green_areas(beaulieu_id)

bic_park_02 = rennes_metropole_s.get_bicycle_parkings(thabor_id)
bic_park_05 = rennes_metropole_s.get_bicycle_parkings(maurepas_id)
bic_park_06 = rennes_metropole_s.get_bicycle_parkings(beaulieu_id)

# Extract data from https://immobilier.statistiques.notaires.fr/prix-immobilier
immobilier_statistiques_s = ImmobilierStatistiquesScraper()
prix_m2_maison_02 = immobilier_statistiques_s.search_sqr(search_square_02, 'maison')
prix_m2_maison_05 = immobilier_statistiques_s.search_sqr(search_square_05, 'maison')
prix_m2_maison_06 = immobilier_statistiques_s.search_sqr(search_square_06, 'maison')

prix_m2_appart_02 = immobilier_statistiques_s.search_sqr(search_square_02, 'appartement')
prix_m2_appart_05 = immobilier_statistiques_s.search_sqr(search_square_05, 'appartement')
prix_m2_appart_06 = immobilier_statistiques_s.search_sqr(search_square_06, 'appartement')

# Building dataframe
data = {'Squares': ['Thabor - Saint-Hélier - Alphonse Guérin', 'Maurepas - Patton les Gayeulles', 'Jeanne d Arc - Longs-Champs - Atalante Beaulieu'],
		'SquaresIds': [2, 5, 6],
		'SquareSurfaces': surfaces,
		'MetroStations': metros,
		'BusStops': buses,
		'NbVivreARennesEquipments': [len(equipement_02), len(equipement_05), len(equipement_06)],
		'NbCulturalEquipments': [len(cult_equip_02), len(cult_equip_05), len(cult_equip_06)],
		'NbGreenAreas': [len(green_areas_02), len(green_areas_05), len(green_areas_06)],
		'NbBicycleProtectedParkings': [len(bic_park_02), len(bic_park_05), len(bic_park_06)],
		'PrixM2House': [prix_m2_maison_02, prix_m2_maison_05, prix_m2_maison_06],
		'PrixM2Appartement': [prix_m2_appart_02, prix_m2_appart_05, prix_m2_appart_06]
		}

df = DataFrame(data, columns=['Squares', 'SquaresIds', 'SquareSurfaces', 'MetroStations', 'BusStops','NbVivreARennesEquipments', 'NbCulturalEquipments', 'NbGreenAreas', 'NbBicycleProtectedParkings', 'PrixM2House', 'PrixM2Appartement'])
now = datetime.datetime.now()

# Data frame to .csv
df.to_csv('./output/chooseSquareAtRennes_{}_{}.csv'.format(now.day, now.month))






