Last active
April 19, 2020 17:17
-
-
Save jul/8406517ca7c46f2debd393a250fbfb6d to your computer and use it in GitHub Desktop.
evolution immobilier par dept (source castor)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf8 -*- | |
from pyquery import PyQuery as P | |
from archery import mdict | |
from archery.trait import Copier | |
from pyaml import dumps | |
import re | |
by3 = lambda s: "".join( | |
[ " " * int((i+1)%3==0) + x for i,x in enumerate(s[::-1])][::-1]).strip() | |
class ToxicSet(Copier,set): | |
def __iadd__(x,y): | |
x|=y | |
return x | |
def __add__(x,y): | |
return x|y | |
s = re.compile(r'''% (?P<dpt>\d{2})(?P<ville>\d+).*-.*(?:(?P<type>Vends|Maison|Studio|Appartement|Propriété|Ferme|Terrain|Immeuble|Hôtel| ,))(?:.*\s(?P<piece>\d+)? pièces)?(?:[,\-] (?P<surface>\d+)m2?)? \((?P<de>\d+)€ -> (?P<a>\d+)€\)''', re.DOTALL).search | |
q=P("https://www.castorus.com/activite.php") | |
all_ = list(map(P,q("li.nodeborde"))) | |
l = list(map(mdict, | |
filter( | |
bool, | |
map( | |
lambda t:s(t) and s(t).groupdict(), | |
map( | |
lambda e:e.text_content(), q("li.nodeborde")))))) | |
all_dpt = sum(map( | |
lambda e: dict({ | |
e["dpt"] : mdict({ | |
'dpt' : ToxicSet([e["dpt"],]), | |
'type' : mdict({e['type'] :1}), | |
'total' :1, | |
'piece' : mdict({e["piece"] or "0" : 1}), | |
'prix':mdict( | |
de=int(e["de"]), a=int(e["a"])) | |
})}), l), | |
mdict({})) | |
pp = lambda e:print(dumps(e, indent=4).decode("utf8")) | |
def pp(e): | |
print("-"* 30) | |
mmax = max(e.values()) | |
for k in sorted(map(lambda i:int(i) if i.isdecimal() else i, e.keys())): | |
print("%13s :" % k, end='') | |
print(" %6.2f%% %s" % (e[str(k)]*100, (int(e[str(k)]*50.0/mmax) * "*"))) | |
print("-"* 30) | |
import locale | |
def format(elt): | |
print("repartition par type") | |
totr = sum(elt["type"].values()) | |
pp(1.0 * elt["type"] / totr) | |
print("repartition par piece") | |
totr = sum(elt["piece"].values()) | |
pp(1.0 * elt["piece"] / totr) | |
print("evolution", end=" : ") | |
print("%+5.2f%%" % (100.0 * (elt["prix"]["a"] - elt["prix"]["de"]) / elt["prix"]["de"]), end="") | |
print("(%s€/%s€)" % ( | |
by3(str(elt["prix"]["a"] - elt["prix"]["de"])), | |
by3(str(elt["prix"]["a"])))) | |
total=mdict() | |
for _,dpt in all_dpt.items(): | |
print("\ndepartement %s" % _) | |
total += dpt | |
format(dpt) | |
print("Pour la France") | |
format(total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment