--stats i dry run dla wysylki maili
This commit is contained in:
		
							
								
								
									
										49
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										49
									
								
								app.py
									
									
									
									
									
								
							@@ -424,6 +424,8 @@ def main():
 | 
			
		||||
    parser.add_argument('--bad-name', action='store_true',
 | 
			
		||||
        help='Oznacz użytkowników z losowymi lub bezużytecznymi nazwami jako kandydatów do usunięcia')
 | 
			
		||||
 | 
			
		||||
    parser.add_argument('--stats', action='store_true',
 | 
			
		||||
        help='Wyświetl statystyki: aktywność, rok rejestracji, domeny')
 | 
			
		||||
 | 
			
		||||
    args = parser.parse_args()
 | 
			
		||||
 | 
			
		||||
@@ -523,6 +525,48 @@ def main():
 | 
			
		||||
 | 
			
		||||
    final_candidates = [u for u in final_candidates if (u.get('points') or 0) == 0]
 | 
			
		||||
 | 
			
		||||
    if args.stats:
 | 
			
		||||
        from collections import Counter
 | 
			
		||||
 | 
			
		||||
        def bucket_days(days):
 | 
			
		||||
            if days < 365: return "<1 rok"
 | 
			
		||||
            if days < 730: return "1–2 lata"
 | 
			
		||||
            if days < 1095: return "2–3 lata"
 | 
			
		||||
            return "3+ lata"
 | 
			
		||||
 | 
			
		||||
        access_buckets = Counter()
 | 
			
		||||
        created_years = Counter()
 | 
			
		||||
        email_domains = Counter()
 | 
			
		||||
 | 
			
		||||
        for u in users:
 | 
			
		||||
            last = u.get("access") or 0
 | 
			
		||||
            days_inactive = (now_ts - last) / 86400
 | 
			
		||||
            access_buckets[bucket_days(days_inactive)] += 1
 | 
			
		||||
 | 
			
		||||
            if u.get("created"):
 | 
			
		||||
                y = datetime.fromtimestamp(u["created"]).year
 | 
			
		||||
                created_years[y] += 1
 | 
			
		||||
 | 
			
		||||
            try:
 | 
			
		||||
                domain = u["mail"].split("@")[1].lower()
 | 
			
		||||
                email_domains[domain] += 1
 | 
			
		||||
            except:
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
        print("\n📊 Statystyki:")
 | 
			
		||||
        print("- Rozkład nieaktywności:")
 | 
			
		||||
        for k, v in sorted(access_buckets.items()):
 | 
			
		||||
            print(f"  {k}: {v}")
 | 
			
		||||
 | 
			
		||||
        print("- Rok rejestracji:")
 | 
			
		||||
        for k in sorted(created_years):
 | 
			
		||||
            print(f"  {k}: {created_years[k]}")
 | 
			
		||||
 | 
			
		||||
        print("- Top domeny:")
 | 
			
		||||
        for dom, cnt in email_domains.most_common(10):
 | 
			
		||||
            print(f"  {dom}: {cnt}")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    if args.report_domains:
 | 
			
		||||
        domain_report(final_candidates)
 | 
			
		||||
 | 
			
		||||
@@ -545,10 +589,11 @@ def main():
 | 
			
		||||
 | 
			
		||||
    if args.send_mails:
 | 
			
		||||
        send_email_batch(
 | 
			
		||||
            [u for u in final_candidates if u['inactive']],  # Tylko nieaktywni
 | 
			
		||||
            [u for u in final_candidates if u['inactive']],
 | 
			
		||||
            smtp_config,
 | 
			
		||||
            args.mails_per_pack,
 | 
			
		||||
            args.time_per_pack
 | 
			
		||||
            args.time_per_pack,
 | 
			
		||||
            dry_run=args.dry_run
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    print("\n📋 Parametry filtrowania:")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user