示例#1
0
    def upload_acquisition(self, msg, uid):
        efs = {f: (extract_field(v, msg)) for f, v in acq_regex.items()}
        if not efs['areas']:
            return False
        cfs = {f: self._clean_extract(v) for f, v in efs.items()}
        cfs['date_posted'] = dt.strptime(cfs['date_posted'], '%d/%m/%Y')
        ex = {'budget_min': None, 'budget_max': None}
        rld = {'email_id': int(uid), **cfs, **ex}
        db.session.add(Acquisition(**rld))

        for a in efs['areas'].split(', '):
            if a in area_list():
                aa = {'email_id': int(uid), 'description': a}
                db.session.add(AcquisitionArea(**aa))
            else:
                aa = {'email_id': int(uid), 'description': a}
                db.session.add(RejectedArea(**aa))
                print('Area not recognized: {}'.format(a))

        db.session.commit()
        return True
示例#2
0
from data_handling import EmailDataHandler
from db_flask.manage import Disposal, db, Acquisition, AcquisitionArea, RejectedArea, PostCodeGeoData
import email_service
from graphic_detail import DataProducer
from scraper import dsp_regex, extract_field, acq_regex
from datetime import datetime as dt
from geopy.geocoders import Nominatim
import geocoder as gcd
import time
import os

import locale
locale.setlocale(locale.LC_ALL, 'uk')
geo = Nominatim()
# esx = email_service.Extractor('*****@*****.**', 'C0ntent123qwerty')
area_list = area_list()


def extract_postcode(s, rec=True):
    try:
        rgx = re.search(
            '[a-zA-Z]{1,2}\d{1,2}([a-zA-Z])?(\s)?\d{1,2}[a-zA-Z]{2}', s)
        return rgx.group()
    except AttributeError:
        if rec:
            x = extract_postcode(s.replace('O', '0'), False)
            if x:
                return x
        if rec:
            x = extract_postcode(s.replace('I', '1'), False)
            if x:
示例#3
0
def es_west_dh(es_west_esx):
    return EmailDataHandler(db.session, es_west_esx, area_list())