示例#1
0
文件: views.py 项目: JD99/mysite1
def sync_mail_mailtag(request):
    #получаем данные из яндекса                &on_page='+str(mail_page)+'
    movies = xml_res_par(request,'get_domain_users','&page=1','email','name', '2')
    sch2 = 'name'
    data5 = dict()
    data6 = dict() 
    
    #сортируем так же как на янд, добавляем новые в рабочую таблицу
    Mail.objects.all().delete()
    max = Mail.objects.all().aggregate(Max('mail_numb'))
    i = max['mail_numb__max']
    for movie in movies:
        type = movie.getElementsByTagName(sch2)[0]
        mail_unread = xml_res_seachattr(request,'get_mail_info','&login='******'new_messages')
        str = type.childNodes[0].data
        str = str.split('@')
        try:
            i=i-1
        except TypeError :
            i = 1000
        #data5[str[0]] = mail_unread['res']
        data5 = {'email' : str[0], 'mess' : mail_unread['res']}
        data6 [ i ] = data5
        qwe = str[0]
        sch = Mail.objects.filter(mail_name__exact=qwe)
        if len(sch) == 0:                
            m = Mail(
                mail_name = qwe,
                mail_mails = mail_unread['res'],
                mail_numb = i,
            )
            m.save()
            sch = MailTag.objects.filter(mail_name__exact=qwe)
            if len(sch) == 0:
                m2 = MailTag(
                    mail_name = qwe,
                    mail_mails = 0,                        
                    mail_tags = 1,
                )
                m2.save()
            
    data1 = data6

    #сверяем сообщения
    data = Mail.objects.all()
    for data in data:
        sch = MailTag.objects.get(mail_name=data.mail_name)
        sch.mail_mails = data.mail_mails
        sch.save()
    #удаляем те элементы которых нет
    data2 = MailTag.objects.all()
    for data2 in data2:
        sch2 = Mail.objects.filter(mail_name__exact=data2.mail_name)       
        try:
            ddd = sch2[0]
        except IndexError :         
            MailTag.objects.get(mail_name=data2.mail_name).delete()
    res = 1
    return HttpResponse(res)  
示例#2
0
def xml_res_par(request, api_metod, api_param, sch1, sch2, param):
#на входе имя метода, параметры(формат &on_page=100&page=1 ), что ищем(строку email-sch1 а в ней name-sch2) - на выходе данные 
    #data = urllib.urlopen(path).read()
    path = api_url + api_metod + ".xml?token=" + api_token + api_param
    DOMTree = xml.dom.minidom.parse(urllib.urlopen(path))
    collection = DOMTree.documentElement
    movies = collection.getElementsByTagName(sch1)
    data = []
    data5 = dict()
    data6 = dict() 
    if param == '2':
        Mail.objects.all().delete()
        max = Mail.objects.all().aggregate(Max('mail_numb'))
        i = max['mail_numb__max']
        for movie in movies:
            type = movie.getElementsByTagName(sch2)[0]
            mail_unread = xml_res_seachattr(request,'get_mail_info','&login='******'new_messages')
            str = type.childNodes[0].data
            str = str.split('@')
            try:
                i=i-1
            except TypeError :
                i = 1000
            #data5[str[0]] = mail_unread['res']
            data5 = {'email' : str[0], 'mess' : mail_unread['res']}
            data6 [ i ] = data5
            qwe = str[0]
            sch = Mail.objects.filter(mail_name__exact=qwe)
            if len(sch) == 0:                
                m = Mail(
                    mail_name = qwe,
                    mail_mails = mail_unread['res'],
                    mail_numb = i,
                )
                m.save()
                sch = MailTag.objects.filter(mail_name__exact=qwe)
                if len(sch) == 0:
                    m2 = MailTag(
                        mail_name = qwe,
                        mail_mails = 0,                        
                        mail_tags = 1,
                    )
                    m2.save()
                
        data1 = data6
        sync_mail_mailtag(request)
    else:
        for movie in movies:
            type = movie.getElementsByTagName(sch2)[0]
            data.append(type.childNodes[0].data)
        data1 = {sch1: data, } 
        
    
    
    return data1
示例#3
0
文件: views.py 项目: JD99/mysite1
def reg_user_token(request):
    if request.is_ajax():
        name=request.POST.get("name", "")
        passw1=request.POST.get("pass1", "")
        passw2=request.POST.get("pass2", "")
        if re.match("^[A-Za-z0-9_-]*$", name):
            message = ""
        else:
            message = "1Используются недопустимые символы"
            return HttpResponse(message)
        if passw1==passw2:
            passw = passw1        
            data = xml_res_str(request,'reg_user_token','&u_login='******'&u_password='******'ok')
            li = data['res']
            if  "+" in li:
                message = "Пользователь успешно добавлен"
                type_err = 0
                lcount = Mail.objects.all().count()
                nuu = Mail.objects.all().aggregate(Max('mail_numb'))
                m = Mail(
                    mail_name = name,
                    mail_mails = 0,
                    mail_numb = nuu['mail_numb__max']+1,
                )
                m.save()
                sch = MailTag.objects.filter(mail_name__exact=name)
                if len(sch) == 0:
                    m2 = MailTag(
                        mail_name = name,
                        mail_mails = 0,                        
                        mail_tags = 1,
                    )
                    m2.save()
                
            else:
                type_err = 1
                if len(passw)<1 or len(name)<1:
                    message = "Введите корректные данные"
                else:
                    if name == passw:
                        message = "Логин и пароль не могут быть одинаковыми"
                    else:
                        if len(passw)<6:
                            message = "Пароль слишком короткий"
                        else:
                            message = "Такой пользователь уже существует"
        else:
            type_err = 1
            message = "Пароли не совпадают"   
    else:
        type_err = 1
        message = "Ошибка сервера, обратитесь к админу"
    data = [type_err,message]
    return HttpResponse(data)