def determine_listing_type(msg): if extract_field(('New disposal posted!', 0), msg): # is not None: return 'Disposal' elif extract_field(('New acquisition posted!', 0), msg): # is not None: return 'Acquisition' else: return 'Unrecognised'
def upload_disposal(msg, uid): efs = {f: (extract_field(v, msg)) for f, v in dsp_regex.items()} if not efs['location']: return False cfs = {f: _clean_extract(v) for f, v in efs.items()} gd = geocode_dic(cfs['location']) cfs['date_posted'] = dt.strptime(cfs['date_posted'], '%d/%m/%Y') try: ex = {'size_avg': (cfs['size_min'] + cfs['size_max']) / 2} except Exception: ex = {'size_avg': None} rld = {'email_id': int(uid), **cfs, **ex, **gd} l = Disposal(**rld) db.session.add(l) db.session.commit() return True
def upload_acquisition(msg, uid): efs = {f: (extract_field(v, msg)) for f, v in acq_regex.items()} if not efs['areas']: return False cfs = {f: _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