Bandeau Beta, bouton Donner mon avis (texte + capture), libelles SIMULE, fusion des donnees de demo (bots), formulaire web et PDF a la charte, plan de deploiement non applique. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
145 lignes
7.0 KiB
Python
145 lignes
7.0 KiB
Python
"""Bots de la bêta JobRunner : profils FICTIFS qui simulent des annonces, des
|
|
messages et des réservations à rythme lent, pour que les testeurs voient de la vie.
|
|
|
|
python beta/bots.py # tourne en continu (une action toutes les 45 à 120 s)
|
|
python beta/bots.py --once 20 --vite # 20 actions sans pause (tests)
|
|
python beta/bots.py --reset # efface UNIQUEMENT les données de démo (tables demo_*)
|
|
|
|
Garde-fous : tout est écrit dans les tables demo_* de la base de la bêta ; chaque
|
|
profil porte la mention « profil fictif » ; les montants sont « SIMULÉ » ; aucune
|
|
adresse e-mail, aucun numéro, aucun appel réseau, aucune vraie personne.
|
|
"""
|
|
import argparse
|
|
import random
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
import db # noqa: E402
|
|
|
|
PRENOMS = ["Léa", "Karim", "Inès", "Hugo", "Camille", "Yanis", "Manon", "Théa", "Nolan", "Sofia", "Malo", "Ayla"]
|
|
INITIALES = "BCDFGHJKLMNPRSTV"
|
|
VILLES = [("Grenoble", "38", "Auvergne-Rhône-Alpes"), ("Lyon", "69", "Auvergne-Rhône-Alpes"),
|
|
("Lille", "59", "Hauts-de-France"), ("Nantes", "44", "Pays de la Loire"),
|
|
("Toulouse", "31", "Occitanie"), ("Rennes", "35", "Bretagne"), ("Strasbourg", "67", "Grand Est")]
|
|
ANNONCES = { # catégorie (ids de l'app) : (titre, prix, unité)
|
|
"brico": [("Montage de meubles en kit", 35, "h"), ("Petites réparations à domicile", 30, "h")],
|
|
"jardin": [("Tonte et taille de haies", 28, "h"), ("Entretien de jardin", 32, "h")],
|
|
"menage": [("Ménage appartement 2 pièces", 22, "h"), ("Repassage à domicile", 20, "h")],
|
|
"cours": [("Soutien maths collège-lycée", 25, "h"), ("Cours d'anglais conversation", 24, "h")],
|
|
"info": [("Dépannage ordinateur et box", 40, "h"), ("Installation imprimante et wifi", 35, "h")],
|
|
"trans": [("Aide au déménagement (camion fourni)", 120, "forfait"), ("Transport de meubles", 60, "forfait")],
|
|
}
|
|
MSG_BOT = ["Bonjour ! Je suis disponible cette semaine, qu'est-ce qui vous arrangerait ?",
|
|
"Merci pour votre message. Pouvez-vous me donner l'adresse approximative et le créneau souhaité ?",
|
|
"J'ai de quoi m'en occuper ce week-end. Je vous envoie une proposition.",
|
|
"Petite précision : j'apporte mon propre matériel, pas besoin de vous en occuper.",
|
|
"Rappel : tout ceci est un échange de démonstration entre un testeur et un bot."]
|
|
MENTION = "Profil fictif créé par un bot de test de la bêta JobRunner. Aucune vraie personne."
|
|
|
|
|
|
def reset(c):
|
|
for t in ("demo_activity", "demo_msgs", "demo_convs", "demo_ads", "demo_profiles"):
|
|
c.execute(f"DELETE FROM {t}")
|
|
c.commit()
|
|
|
|
|
|
def nb(c, t):
|
|
return c.execute(f"SELECT COUNT(*) FROM {t}").fetchone()[0]
|
|
|
|
|
|
def activite(c, kind, texte):
|
|
c.execute("INSERT INTO demo_activity(created_at,kind,text) VALUES(?,?,?)", (time.time(), kind, texte))
|
|
|
|
|
|
def nouveau_profil(c, rnd):
|
|
prenom = rnd.choice(PRENOMS)
|
|
ville = rnd.choice(VILLES)
|
|
seed = f"{prenom}{rnd.randint(100, 999)}"
|
|
cur = c.execute("INSERT INTO demo_profiles(created_at,first,last_initial,city,dept,region,seed,bio) VALUES(?,?,?,?,?,?,?,?)",
|
|
(time.time(), prenom, rnd.choice(INITIALES), ville[0], ville[1], ville[2], seed, MENTION))
|
|
p = c.execute("SELECT * FROM demo_profiles WHERE id=?", (cur.lastrowid,)).fetchone()
|
|
activite(c, "profil", f"{p['first']} {p['last_initial']}. (bot) rejoint JobRunner à {p['city']}")
|
|
|
|
|
|
def action(c, rnd):
|
|
now = time.time()
|
|
profils = [r["id"] for r in c.execute("SELECT id FROM demo_profiles")]
|
|
if len(profils) < 4:
|
|
nouveau_profil(c, rnd)
|
|
c.commit()
|
|
return "profil"
|
|
choix = rnd.choices(["profil", "annonce", "message", "conv", "reservation"], [1, 4, 4, 2, 3])[0]
|
|
if choix == "profil" and len(profils) >= 12:
|
|
choix = "annonce"
|
|
if choix == "annonce" and nb(c, "demo_ads") >= 24:
|
|
choix = "message"
|
|
if choix == "conv" and nb(c, "demo_convs") >= 6:
|
|
choix = "message"
|
|
|
|
if choix == "profil":
|
|
nouveau_profil(c, rnd)
|
|
elif choix == "annonce":
|
|
pid = rnd.choice(profils)
|
|
cat = rnd.choice(list(ANNONCES))
|
|
titre, prix, unite = rnd.choice(ANNONCES[cat])
|
|
c.execute("INSERT INTO demo_ads(created_at,profile_id,category,title,price,unit,descr) VALUES(?,?,?,?,?,?,?)",
|
|
(now, pid, cat, titre, prix + rnd.choice([-5, 0, 0, 5]), unite, MENTION))
|
|
activite(c, "annonce", f"Nouvelle annonce (bot) : {titre}")
|
|
elif choix == "conv":
|
|
pid = rnd.choice(profils)
|
|
cat = rnd.choice(list(ANNONCES))
|
|
titre, prix, _ = rnd.choice(ANNONCES[cat])
|
|
cur = c.execute("INSERT INTO demo_convs(created_at,profile_id,title,amount,status) VALUES(?,?,?,?,?)",
|
|
(now, pid, titre, prix * 2, rnd.choice(["none", "proposed"])))
|
|
c.execute("INSERT INTO demo_msgs(created_at,conv_id,sender,text) VALUES(?,?,?,?)", (now, cur.lastrowid, "them", MSG_BOT[0]))
|
|
activite(c, "message", "Un bot a écrit à un testeur")
|
|
elif choix == "message":
|
|
convs = [r["id"] for r in c.execute("SELECT id FROM demo_convs")]
|
|
if convs:
|
|
cid = rnd.choice(convs)
|
|
if c.execute("SELECT COUNT(*) FROM demo_msgs WHERE conv_id=?", (cid,)).fetchone()[0] < 12:
|
|
c.execute("INSERT INTO demo_msgs(created_at,conv_id,sender,text) VALUES(?,?,?,?)",
|
|
(now, cid, "them", rnd.choice(MSG_BOT)))
|
|
activite(c, "message", "Nouveau message de bot")
|
|
elif choix == "reservation":
|
|
a, b = rnd.sample(profils, 2)
|
|
pa, pb = (c.execute("SELECT * FROM demo_profiles WHERE id=?", (x,)).fetchone() for x in (a, b))
|
|
etape = rnd.choice(["a réservé", "a validé la prestation de"])
|
|
activite(c, "reservation",
|
|
f"{pa['first']} {pa['last_initial']}. (bot) {etape} {pb['first']} {pb['last_initial']}. (bot) : "
|
|
f"{rnd.choice([30, 45, 60, 80, 120])} € SIMULÉ")
|
|
c.execute("DELETE FROM demo_activity WHERE id NOT IN (SELECT id FROM demo_activity ORDER BY id DESC LIMIT 60)")
|
|
c.commit()
|
|
return choix
|
|
|
|
|
|
def main(argv=None):
|
|
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
ap.add_argument("--reset", action="store_true")
|
|
ap.add_argument("--once", type=int, default=0, help="nombre d'actions puis sortie")
|
|
ap.add_argument("--vite", action="store_true", help="pas de pause entre actions (tests)")
|
|
ap.add_argument("--min", type=int, default=45)
|
|
ap.add_argument("--max", type=int, default=120)
|
|
ap.add_argument("--seed", type=int, default=None)
|
|
a = ap.parse_args(argv)
|
|
c = db.connect()
|
|
rnd = random.Random(a.seed)
|
|
if a.reset:
|
|
reset(c)
|
|
print("Données de démo effacées (tables demo_* uniquement).")
|
|
return
|
|
n = 0
|
|
while True:
|
|
print(time.strftime("%H:%M:%S"), action(c, rnd), flush=True)
|
|
n += 1
|
|
if a.once and n >= a.once:
|
|
break
|
|
if not a.vite:
|
|
time.sleep(rnd.randint(a.min, a.max))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|