Exemplo n.º 1
0
def parseLocal(path, url=None):
    if not os.path.exists(path):
        print("File doesn't exists:", path)
        return
    with open(path) as f:
        home = Home()
        (dirname, filename, ext) = common.getFileParts(path)
        pathOut = os.path.join(dirname, filename + ".home.jhome")
        if os.path.exists(pathOut):
            jsonTools.load(home, pathOut)
        data = f.read()

        sources = {
            "pap.fr": parsePAP,
            "leboncoin.fr": parseLeBonCoin,
            "seloger.com": None,
            "acheter-louer.fr": None,
            "explorimmo.com": parseExplorimmo,
            "logic-immo.com": parseLogicImmo,
        }
        for key in sources:
            if (url and key.lower() in url.lower()) or (key in data):
                if sources[key]:
                    sources[key](home, data)
                    break
        if url:
            home.www = url
        home.validate()
        jsonTools.save(home, pathOut, encoding="utf-8")
        jsonTools.save(home, pathOut + ".bak", encoding="utf-8")
        return home
Exemplo n.º 2
0
    def loadData(self):
        self.homeFiles = {}

        res = []
        for f in common.getFiles("data", ".jhome"):
            if "_bak" not in f:
                home = appart.Home()
                jsonTools.load(home, f)
                if home.hidden or home.sold:
                    continue
                res.append(home)
                self.homeFiles[home] = f
        self.homes = res
        return res