widgettdc-api / apps /backend /python /check_m365_neo4j.py
Kraft102's picture
Update backend source
34367da verified
#!/usr/bin/env python3
"""Check Neo4j M365 harvest status"""
from neo4j import GraphDatabase
driver = GraphDatabase.driver(
'neo4j+s://054eff27.databases.neo4j.io',
auth=('neo4j', 'Qrt37mkb0xBZ7_ts5tG1J70K2mVDGPMF2L7Njlm7cg8')
)
with driver.session() as s:
print("=" * 50)
print("📊 M365 ITEMS I NEO4J")
print("=" * 50)
result = s.run('MATCH (i:M365Item) RETURN i.source as source, count(*) as count ORDER BY count DESC')
total = 0
for r in result:
print(f" {r['source']:15} {r['count']:5}")
total += r['count']
print(f" {'TOTAL':15} {total:5}")
print()
print("=" * 50)
print("🏷️ TOP KEYWORDS")
print("=" * 50)
result = s.run('''
MATCH (k:SearchKeyword)<-[:MATCHES_KEYWORD]-(i:M365Item)
RETURN k.name as keyword, count(i) as count
ORDER BY count DESC LIMIT 15
''')
for r in result:
print(f" {r['keyword']:15} {r['count']:5}")
print()
print("=" * 50)
print("📧 SENESTE OUTLOOK EMAILS")
print("=" * 50)
result = s.run('''
MATCH (i:M365Item {source: 'outlook'})
RETURN i.title as subject, i.timestamp as time, i.keywords as keywords
ORDER BY i.timestamp DESC LIMIT 10
''')
for r in result:
kws = ', '.join(r['keywords'][:3]) if r['keywords'] else ''
print(f" [{r['time']}] {r['subject'][:50]}... [{kws}]")
driver.close()
print("\n✅ Done!")