Source code for zot.services.campagne
# zot/plugs/campagne.py
#
#
""" the thing to resolve. """
## IMPORTS
from zot.utils import a_time, nr_days, elapsed_days
from zot.runtime import kernel
from zot.object import Object
from zot.looper import LOOPER
## basic imports
import time
import logging
import random
import datetime
## SuicideWarnLoop
pogingenjaar = 94000
pogingendag = pogingenjaar / 365.0
pogingenuur = pogingendag / 24.0
pogingenmin = pogingenuur / 60.0
geslaagdjaar = 1854
geslaagddag = geslaagdjaar / 365.0
geslaagduur = geslaagddag / 24.0
geslaagdmin = geslaagduur / 60.0
counter = 0
startdate = "2012-09-13 00:00:00"
starttime = a_time(startdate)
bron = "https://www.113online.nl/informatie/113online%2B/cijfers-over-zelfmoord"
url = "http://pypi.python.org/pypi/zotbot"
tags = ["#cda", "#pvda", "#d66", "#vvd", "#groenlinks", "#pvdd", "#ggznederland", "#igz", "#vws", "#gemeente", "#wmoloket", "#politie", "#ambulance", "#crisisdienst", "#telefoon", "#huisarts"]
prevpogingen = 0
prevgeslaagd = 0
lastpoging = 0
lastsuicide = 0
[docs]def ltag(*args, **kwargs):
l = []
while 1:
c = random.choice(tags)
if c not in l: l.append(c)
if len(l) == args[0]: break
return " ".join(l)
[docs]def campagne(*args, **kwargs):
global counter, prevpogingen, prevgeslaagd, lastpoging, lastsuicide
counter += 1
o = Object()
o.bron = bron
time_diff = time.time() - starttime
aantalmin = time_diff / 60.0
pogingen = int(aantalmin * pogingenmin)
geslaagd = int(aantalmin * geslaagdmin)
time_diff = float(time.time() - starttime)
o.elapsed = elapsed_days(time_diff)
if pogingen > lastpoging:
o.txt = "POGING %s %s - %s ? !! %s (%s/dag)" % (pogingen, url, ltag(4), o.elapsed, int(pogingendag))
lastpoging = pogingen
o.prefix = "poging"
kernel.announce(o.txt)
if geslaagd > lastsuicide:
o.txt = "SUICIDE nummer %s %s - %s ? !! %s (%s/dag)" % (geslaagd, url, ltag(4), o.elapsed, int(geslaagddag))
o.prefix = "suicide"
lastsuicide = geslaagd
kernel.announce(o.txt)
o.save()
kernel.register("campagne.tikker", campagne)
[docs]class CAMPAGNE(LOOPER): pass
## campagne init
[docs]def init(*args, **kwargs):
looper = CAMPAGNE(campagne, 3600)
kernel.put(looper.start)