Exemple #1
0
def getMsgsForChild(cname):
    '''Find all new messages for a single child'''
    dtype = surllib.getBrowser().getState('dialogue')
    if dtype == 'conversations':
        # New more "gmail" like message view
        url = schildren.getChildURL(cname, '/messages/conversations')
        config.clog(cname, u'Kigger efter nye beskeder på %s' % url)
        bs = surllib.skoleGetURL(url, asSoup=True, noCache=True)

        return parseMessages(cname, bs)
    elif dtype == 'inbox':
        # Old message view
        msgs = []
        for tray in ['inbox', 'outbox']:
            url = schildren.getChildURL(cname, '/messages/'+tray)
            config.clog(cname, u'Kigger efter nye beskeder på %s' % url)
            bs = surllib.skoleGetURL(url, asSoup=True, noCache=True)

            msgs += parseTrayMessages(cname, bs)

        return msgs
    else:
        config.clog(cname, u'Beskede-indbakke-type %r ikke understøttet'
                    % dtype, 0)
        return []
Exemple #2
0
def getMsgsForChild(cname):
    '''Find all new messages for a single child'''
    dtype = surllib.getBrowser().getState('dialogue')
    if dtype == 'conversations':
        # New more "gmail" like message view
        url = schildren.getChildURL(cname, '/messages/conversations')
        config.clog(cname, u'Kigger efter nye beskeder på %s' % url)
        bs = surllib.skoleGetURL(url, asSoup=True, noCache=True)

        return parseMessages(cname, bs)
    elif dtype == 'inbox':
        # Old message view
        msgs = []
        for tray in ['inbox', 'outbox']:
            url = schildren.getChildURL(cname, '/messages/' + tray)
            config.clog(cname, u'Kigger efter nye beskeder på %s' % url)
            bs = surllib.skoleGetURL(url, asSoup=True, noCache=True)

            msgs += parseTrayMessages(cname, bs)

        return msgs
    else:
        config.clog(cname,
                    u'Beskede-indbakke-type %r ikke understøttet' % dtype, 0)
        return []
Exemple #3
0
def checkForUpdates():
    now = datetime.datetime.now()

    bs = surllib.skoleGetURL(
        '/notifications/v1?useNewerThan=False&pageSize=10', True, True)

    # Find lastUpdateURL
    links = bs.select('.sk-notifications-list li a')
    if links and links[0].has_attr('href'):
        updateURL = links[0]['href']
        config.log(u'Sidste opdatering var til %s' % updateURL, 2)
    else:
        updateURL = None
        config.log(u'Kunne ikke finde sidst opdaterede side', 2)

    state = (now, updateURL)

    # Should we do a full check?
    br = surllib.getBrowser()

    if br.getState('lastUpdateURL') != updateURL:
        # New top update
        config.log(u'Kører fuld opdatering: Forventer nyt opslag/besked', 1)
        return (True, state)

    try:
        lut_ = br.getState('lastUpdateTime')
        lut = datetime.datetime.strptime(lut_, DT_FORMAT) if lut_ else None
    except ValueError:
        lut = None

    if not lut or now < lut:
        # lastUpdateTime is somehow wrong
        config.log(u'Kører fuld opdatering: Mangler tidsstempel fra '
                   u'sidste kørsel', 1)
        return (True, state)

    # Do a daily full check the first time we are accessed after 05:00
    pit = now.replace(hour=5, minute=0, second=0, microsecond=0)
    if now.hour < 5:
        # Between midnight and 05:00, go back one day
        pit -= datetime.timedelta(1)
    if lut <= pit:
        # Last update was before
        config.log(u'Kører fuld opdatering: Første kørsel i dag', 1)
        return (True, state)

    # Did we NOT run this with the --quick parameter
    if config.options.fullupdate:
        config.log(u'Kører fuld opdatering selvom der ikke forventes '
                   u'nyt. Du bør bruge --quick', 1)
        return (True, state)

    # No need to run a full update
    config.log(u'Kører ikke fuld opdatering - der forventes intet nyt', 1)
    return (False, state)
Exemple #4
0
def saveState(state):
    (now, updateURL) = state

    br = surllib.getBrowser()

    if now:
        br.setState('lastUpdateTime', now.strftime(DT_FORMAT))
    if updateURL:
        br.setState('lastUpdateURL', updateURL)
    br.saveState()
Exemple #5
0
def skoleConfirmPersonalData(bs):
    # check that we actually have the right form

    txts = [
        u'Bekræft personoplysninger',
        u'Navn og adresse:',
        u'E-mailadresse',
        u'Fastnettelefon:',
        u'Mobiltelefon',
    ]
    e = False
    for txt in txts:
        if txt not in bs.text:
            config.log(u'Hmmm.. "%s" ikke fundet på bekræftigelsessiden...')
            e = True
    if e:
        return

    # Find first form, and first table inside the form
    f = bs.findAll('form')
    if f:
        bs = f[0]
    f = bs.findAll('table')
    if f:
        bs = f[0]

    msg = semail.Message('frontpage', bs)
    msg.setTitle(u'Bekræft personoplysninger')
    semail.maybeEmail(msg)

    # And now, click the button to confirm the details
    br = surllib.getBrowser()
    fs = list(br.forms())

    if len(fs) == 1 and fs[0].name == 'FrontPage_Form1':
        # we have one form!
        br.select_form(fs[0].name)

        ss = bs.findAll('input', type='submit')
        if len(ss) == 1 and ss[0]['value'] == TEXT_I_CONFIRM:
            config.log(u'Bekræfter personlige data')
            br.submit()  # click submit!
            return

    # something went wront above
    config.log(u'Hmmm.. "%s" ikke fundet på Bekræftigelsessiden...')
Exemple #6
0
def skoleConfirmPersonalData(bs):
    # check that we actually have the right form

    txts = [
        u'Bekræft personoplysninger',
        u'Navn og adresse:',
        u'E-mailadresse',
        u'Fastnettelefon:',
        u'Mobiltelefon',
    ]
    e = False
    for txt in txts:
        if txt not in bs.text:
            config.log(u'Hmmm.. "%s" ikke fundet på bekræftigelsessiden...')
            e = True
    if e:
        return

    # Find first form, and first table inside the form
    f = bs.findAll('form')
    if f:
        bs = f[0]
    f = bs.findAll('table')
    if f:
        bs = f[0]

    msg = semail.Message('frontpage', bs)
    msg.setTitle(u'Bekræft personoplysninger')
    semail.maybeEmail(msg)

    # And now, click the button to confirm the details
    br = surllib.getBrowser()
    fs = list(br.forms())

    if len(fs) == 1 and fs[0].name == 'FrontPage_Form1':
        # we have one form!
        br.select_form(fs[0].name)

        ss = bs.findAll('input', type='submit')
        if len(ss) == 1 and ss[0]['value'] == TEXT_I_CONFIRM:
            config.log(u'Bekræfter personlige data')
            br.submit()  # click submit!
            return

    # something went wront above
    config.log(u'Hmmm.. "%s" ikke fundet på Bekræftigelsessiden...')
Exemple #7
0
def skoleDialogue():
    surllib.skoleLogin()
    br = surllib.getBrowser()

    for tray in TRAYS:
        config.log(u'Behandler beskeder i bakken %s' % tray)

        url = 'https://%s%s%s' % (config.HOSTNAME, URL_BOX_PREFIX, tray)

        # Read the initial page, and search for messages
        config.log(u'Bakke-URL: %s' % url)
        resp = br.open(url)
        data = resp.read()
        # ensure that we get only mgss for the current child
        br.select_form(name='FrontPage_Form1')
        br['R1'] = ('klasse',)
        resp = br.submit()
        data = resp.read()

        diaFindMessages(data)
Exemple #8
0
def skoleDialogue():
    surllib.skoleLogin()
    br = surllib.getBrowser()

    for tray in TRAYS:
        config.log(u'Behandler beskeder i bakken %s' % tray)

        url = 'https://%s%s%s' % (config.HOSTNAME, URL_BOX_PREFIX, tray)

        # Read the initial page, and search for messages
        config.log(u'Bakke-URL: %s' % url)
        resp = br.open(url)
        data = resp.read()
        # ensure that we get only mgss for the current child
        br.select_form(name='FrontPage_Form1')
        br['R1'] = ('klasse', )
        resp = br.submit()
        data = resp.read()

        diaFindMessages(data)
Exemple #9
0
def skoleFrontpage():
    surllib.skoleLogin()

    config.log('Behandler forsiden')

    url = 'http://%s/Infoweb/Fi2/Forside.asp' % config.HOSTNAME
    data = surllib.skoleGetURL(url, asSoup=True, noCache=True)

    br = surllib.getBrowser()
    aurl = br.geturl()
    if u'Personoplysninger.asp' in aurl:
        # We are actually asked to confirm our personal data
        config.log(u'Bekræfter først vores personlige data')
        skoleConfirmPersonalData(data)

        data = surllib.skoleGetURL(url, asSoup=True, noCache=True)

    # find main table
    maint = []
    for mt in data.findAll('table'):
        if mt.findParents('table') or mt.has_key('bgcolor'):
            continue
        txt = mt.text
        if len(txt) < 30 and txt.lower().startswith(u'forældreintra for '):
            continue  # just the title
        maint.append(mt)
    assert(len(maint) == 1)  # assume exactly one main table

    maint = maint[0]

    # find interesting table tags
    itags = []
    for tag in maint:
        for ttag in tag.findAll('table'):
            if ttag.text:
                itags.append(ttag)

    g = []
    for itag in itags:
        t = _getTitle(itag)
        if t is None:
            # not a title
            if not g:
                # In some cases (slideshows), the real title may be missing
                g.append((itags[0].text, []))
            g[-1][1].append(itag)
        else:
            # we have a new title
            g.append((t, []))

    for (t, xs) in g:
        ignore = len(xs) == 0 or t in TITLE_IGNORE
        config.log(u'Kategori [%s]%s' %
                   (t, ' (hoppes over)' if ignore else ''))
        if ignore:
            continue

        if t == TITLE_COVERPIC:
            assert(len(xs) == 1)  # exactly one cover picture
            skoleCoverPic(xs[0])
            continue
        elif t == TITLE_BBB:
            # BBB news are split
            # ignore first table which is a wrapper around all entries
            xs = xs[1:]
            map(skoleFrontBBB, xs)
        elif t == TITLE_NEWS:
            # News from...
            skoleNewsFrom(xs)
        else:
            # send msg if something has changed
            for x in xs:
                skoleOtherStuff(t, x)
Exemple #10
0
def skoleFrontpage():
    surllib.skoleLogin()

    config.log('Behandler forsiden')

    url = 'http://%s/Infoweb/Fi2/Forside.asp' % config.HOSTNAME
    data = surllib.skoleGetURL(url, asSoup=True, noCache=True)

    br = surllib.getBrowser()
    aurl = br.geturl()
    if u'Personoplysninger.asp' in aurl:
        # We are actually asked to confirm our personal data
        config.log(u'Bekræfter først vores personlige data')
        skoleConfirmPersonalData(data)

        data = surllib.skoleGetURL(url, asSoup=True, noCache=True)

    # find main table
    maint = []
    for mt in data.findAll('table'):
        if mt.findParents('table') or mt.has_key('bgcolor'):
            continue
        txt = mt.text
        if len(txt) < 30 and txt.lower().startswith(u'forældreintra for '):
            continue  # just the title
        maint.append(mt)
    assert (len(maint) == 1)  # assume exactly one main table

    maint = maint[0]

    # find interesting table tags
    itags = []
    for tag in maint:
        for ttag in tag.findAll('table'):
            if ttag.text:
                itags.append(ttag)

    g = []
    for itag in itags:
        t = _getTitle(itag)
        if t is None:
            # not a title
            if not g:
                # In some cases (slideshows), the real title may be missing
                g.append((itags[0].text, []))
            g[-1][1].append(itag)
        else:
            # we have a new title
            g.append((t, []))

    for (t, xs) in g:
        ignore = len(xs) == 0 or t in TITLE_IGNORE
        config.log(u'Kategori [%s]%s' %
                   (t, ' (hoppes over)' if ignore else ''))
        if ignore:
            continue

        if t == TITLE_COVERPIC:
            assert (len(xs) == 1)  # exactly one cover picture
            skoleCoverPic(xs[0])
            continue
        elif t == TITLE_BBB:
            # BBB news are split
            # ignore first table which is a wrapper around all entries
            xs = xs[1:]
            map(skoleFrontBBB, xs)
        elif t == TITLE_NEWS:
            # News from...
            skoleNewsFrom(xs)
        else:
            # send msg if something has changed
            for x in xs:
                skoleOtherStuff(t, x)