Spaces:
Running
Running
File size: 1,874 Bytes
9f8eafb 4086fa5 9f8eafb 4086fa5 9f8eafb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import json
import random
from datetime import datetime, timedelta, timezone
# Target stats
TARGET_TOTAL = 65
TARGET_UV = 8
TARGET_TODAY = 63
TODAY_DATE = "2026-01-24" # Based on system time
# Timezone (UTC+8 for "today" calculation logic in app.py)
# app.py now uses naive Beijing time string (UTC+8) for created_at
# e.g., "2023-01-01T12:00:00.000000" (representing 12:00 Beijing time)
now_utc = datetime.utcnow()
now_cn = now_utc + timedelta(hours=8)
# Force "today" to be consistent with user request
start_of_today = now_cn.replace(hour=0, minute=0, second=0, microsecond=0)
visits = []
# Generate 8 unique IPs
ips = [f"192.168.1.{i}" for i in range(1, 9)]
# 1. Generate "Old" visits (Total - Today = 65 - 63 = 2)
# These must be before today
old_time = start_of_today - timedelta(days=1, hours=2)
for i in range(2):
visits.append({
"ip": ips[i % len(ips)], # Use first few IPs
"url": "https://huggingface.co/spaces/duqing2026/project-show",
"referrer": "",
"is_local": 0,
"created_at": (old_time + timedelta(minutes=i)).isoformat()
})
# 2. Generate "Today" visits (63)
# These must be >= start_of_today
for i in range(63):
# Ensure we use all IPs to hit UV count
ip = ips[i % len(ips)]
visit_time = start_of_today + timedelta(minutes=10 + i)
visits.append({
"ip": ip,
"url": "https://huggingface.co/spaces/duqing2026/project-show",
"referrer": "",
"is_local": 0,
"created_at": visit_time.isoformat()
})
# Write to file
file_path = "hf_project_showcase_data/visits.jsonl"
with open(file_path, "w", encoding="utf-8") as f:
for v in visits:
f.write(json.dumps(v, ensure_ascii=False) + "\n")
print(f"Generated {len(visits)} visits in {file_path}")
print(f"Total: {len(visits)}, Today: {TARGET_TODAY}, UV: {len(set(v['ip'] for v in visits))}")
|