Example #1
0
def spider_today_old(url):
    try:
        html = get_html(url)
        html_json = simplejson.loads(html)
        for i in range(len(html_json['result']['data'])):
            lottery_date = html_json['result']['data'][i]['preDrawTime'][0:10]
            lottery_time = html_json['result']['data'][i]['preDrawTime']
            lottery_id = html_json['result']['data'][i]['preDrawIssue']
            lottery_number = html_json['result']['data'][i]['preDrawCode']

            flag_id = LotteryMonth.objects.filter(lottery_id=lottery_id)
            if (flag_id):
                print lottery_id, ' id exists'
            else:
                print lottery_id, ' id not exists'
                p = LotteryMonth(lottery_date=lottery_date,
                                 lottery_time=lottery_time,
                                 lottery_id=lottery_id,
                                 lottery_number=lottery_number)
                p.save()

    except:
        print "network is error"
        return False
    return True
Example #2
0
def spider_history(url):
    try:
        html = get_html(url)
        if (html):
            html_json = simplejson.loads(html)
            for i in range(len(html_json['result']['data'])):
                lottery_month = html_json['result']['data'][i]['preDrawTime'][
                    0:7]
                lottery_date = html_json['result']['data'][i]['preDrawTime'][
                    0:10]
                lottery_time = html_json['result']['data'][i]['preDrawTime']
                lottery_id = html_json['result']['data'][i]['preDrawIssue']
                lottery_number = html_json['result']['data'][i]['preDrawCode']

                p = LotteryMonth(lottery_month=lottery_month,
                                 lottery_date=lottery_date,
                                 lottery_time=lottery_time,
                                 lottery_id=lottery_id,
                                 lottery_number=lottery_number)
                p.save()
        else:
            return False
    except:
        print "network is error"
        return False
    return True
Example #3
0
def spider_today_pay(url):
    try:
        html = get_html(url)
        html_json = simplejson.loads(html)
        # print html_json
        for i in range(len(html_json['data'])):
            lottery_month = html_json['data'][i]['opentime'][0:7]
            lottery_date = html_json['data'][i]['opentime'][0:10]
            lottery_time = html_json['data'][i]['opentime']
            lottery_id = html_json['data'][i]['expect']
            lottery_number = html_json['data'][i]['opencode']

            p = LotteryMonth(lottery_month=lottery_month, lottery_date =lottery_date, lottery_time = lottery_time, lottery_id = lottery_id, lottery_number = lottery_number)
            p.save()
    except:
        print "network is error"
        return False
    return True