Initial MVP Commit: Ingest, Enrich, Dashboard
This commit is contained in:
75
ingest.py
Normal file
75
ingest.py
Normal file
@@ -0,0 +1,75 @@
|
||||
import re
|
||||
from db import insert_lead
|
||||
|
||||
def parse_tradingtwins_email(body):
|
||||
data = {}
|
||||
|
||||
# Simple regex extraction based on the email format
|
||||
patterns = {
|
||||
'id': r'Lead-ID:\s*(\d+)',
|
||||
'company': r'Firma:\s*(.+)',
|
||||
'contact_first': r'Vorname:\s*(.+)',
|
||||
'contact_last': r'Nachname:\s*(.+)',
|
||||
'email': r'E-Mail:\s*([^\s<]+)',
|
||||
'phone': r'Rufnummer:\s*([^\n]+)',
|
||||
'area': r'Reinigungs-Flche:\s*([^\n]+)',
|
||||
'purpose': r'Einsatzzweck:\s*([^\n]+)'
|
||||
}
|
||||
|
||||
for key, pattern in patterns.items():
|
||||
match = re.search(pattern, body)
|
||||
if match:
|
||||
data[key] = match.group(1).strip()
|
||||
|
||||
# Combine names
|
||||
if 'contact_first' in data and 'contact_last' in data:
|
||||
data['contact'] = f"{data['contact_first']} {data['contact_last']}"
|
||||
|
||||
data['raw_body'] = body
|
||||
return data
|
||||
|
||||
def ingest_mock_leads():
|
||||
# Mock data from the session context
|
||||
leads = [
|
||||
{
|
||||
'id': '2397256',
|
||||
'company': 'pronorm Einbauküchen GmbH',
|
||||
'contact': 'Jakob Funk',
|
||||
'email': 'jakob.funk@pronorm.de',
|
||||
'phone': '+49 5733 979175',
|
||||
'raw_body': """
|
||||
Lead-ID: 2397256
|
||||
Firma: pronorm Einbauküchen GmbH
|
||||
Vorname: Jakob
|
||||
Nachname: Funk
|
||||
Reinigungs-Flche: 1.001 - 10.000 qm
|
||||
Einsatzzweck: Reinigung von Böden
|
||||
"""
|
||||
},
|
||||
{
|
||||
'id': '2414364',
|
||||
'company': 'Quad & Rollershop Schwabmünchen GmbH',
|
||||
'contact': 'Manfred Bihler',
|
||||
'email': 'Rollershop.Schwabmuenchen@web.de',
|
||||
'phone': '+49 8232 905246',
|
||||
'raw_body': """
|
||||
Lead-ID: 2414364
|
||||
Firma: Quad & Rollershop Schwabmünchen GmbH
|
||||
Vorname: Manfred
|
||||
Nachname: Bihler
|
||||
Reinigungs-Flche: 301 - 1.000 qm
|
||||
Einsatzzweck: Reinigung von Böden
|
||||
"""
|
||||
}
|
||||
]
|
||||
|
||||
count = 0
|
||||
for lead in leads:
|
||||
if insert_lead(lead):
|
||||
count += 1
|
||||
return count
|
||||
|
||||
if __name__ == "__main__":
|
||||
from db import init_db
|
||||
init_db()
|
||||
print(f"Ingested {ingest_mock_leads()} new leads.")
|
||||
Reference in New Issue
Block a user