nordabiz/scripts/check_websites.py

32 lines
992 B
Python

#!/usr/bin/env python3
"""Check company website URLs for missing http/https prefix."""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dotenv import load_dotenv
load_dotenv()
from app import app
from database import Company
with app.app_context():
c = Company.query.get(20)
print(f"ID: {c.id}, Name: {c.name}")
print(f"Website: [{c.website}]")
print(f"Repr: {repr(c.website)}")
print()
companies = Company.query.filter(
Company.website.isnot(None),
Company.website != ""
).order_by(Company.id).all()
print(f"Firm z website: {len(companies)}")
bad = []
for co in companies:
w = co.website.strip() if co.website else ""
if w and not w.startswith("http://") and not w.startswith("https://"):
bad.append((co.id, co.name, w))
print(f"Bez http/https prefix: {len(bad)}")
for bid, bname, bweb in bad:
print(f" ID {bid}: {bname} -> [{bweb}]")