Example #1
0
def send_warning(s, lst, q, *args):
    # s is the session object
    # q is Queue()
    global current_warning
    global glst
    url = 'http://webmail.fil.bg.ac.rs/src/'

    glst = list(lst)
    subject = 'Kasnjenje'

    # list consists of tuples with multiple element, e.g. ([email protected], author, book...)
    for i in glst:
        q.put_nowait(1)
        recipient=i[0]
        body='Postovani,\n\nKasnite s vracanjem knjige '+str(i[1])+': "'+str(i[2])+'", signatura: '+str(i[3])+' uzete ' \
                ''+str(i[4])+'.\n Rok za vracanje je bio '+str(i[5])+'.\n' \
                'Molim Vas da je vratite u sto kracem roku.\n' \
                'S postovanjem,\n' \
                'Milan Todorovic\n\n' \
                'Biblioteka Katedre za germanistiku\n' \
                'Filoloski fakultet\n' \
                'Univerzitet u Beogradu\nStudentski trg 3\n' \
                'Tel: 011/2021-698\nRadno vreme: 9.00-17.00'

        files = {"startMessage": (None, "1"),
                     "session": (None, "1"),
                     "passed_id": (None, ""),
                     "send_to": (None, recipient),
                     "send_to_cc": (None, ""),
                     "send_to_bcc": (None, ""),
                     "subject": (None, subject),
                     "mailprio": (None, "3"),
                     "body": (None, body),
                     "send": (None, "Send"),
                     "attachfile": ("", ""),
                     "MAX_FILE_SIZE": (None, "20971520"),
                     "username": (None, "milan.todorovic"),
                     "smaction": (None, ""),
                     "mailbox": (None, "INBOX"),
                     "composesession": (None, "1"),
                     "querystring": (None, "mailbox=INBOX&startMessage=1")}

        left_side = url + 'left_main.php'
        right_side = url + 'right_main.php'
        try:
            l = s.get(left_side)
            r = s.get(right_side)
            print('Loading left frame: ', l.status_code)
            print('Loading right frame: ', r.status_code)
        except ConnectionError:
            q.put_nowait(2)
            l = [i for i in glst if i[0] not in current_warning]
            q.put_nowait(l) # returns a list to lst in uppbar()
            q.close()
            # return [i for i in glst if i[0] not in current_warning]


        time.sleep(1)
        compose = url + 'compose.php?mailbox=INBOX&startMessage=1'
        r = s.get(compose)
        print('Enterying "Compose": ', r.status_code)

        send = url + 'compose.php'
        time.sleep(1)
        r = s.post(send, files=files, allow_redirects=False)
        print('Mail sent: ', r.status_code)
        print('Redirecting to: ', r.headers['Location'])
        r = s.get(r.headers['Location'])
        print('Redirected to home page: ', r.status_code)
        print('Warning successfully sent.')
        current_warning.append(i[0])
        DataBase.unsentWarning_delete(i[0])
    q.put_nowait(0)
    q.close()
    current_warning = []
    glst = []
    # returns to variable security
    return 0