Django的views编写以及结合mysql存库小demo

# -*- coding: UTF-8 -*-
from Piaofangshujk_05 import Piaofangshujk_05
from ShishiDianying_01 import ShishiDianying_01
from Zhongguodianyinxinxi_01 import Zhongguodianyinxinxi_01
from Maoyandianying_01 import Maoyandianying_01
from Yiendianyingzhiku_01 import Yiendianyingzhiku_01
from django.shortcuts import  render_to_response
from huayingtx.models import *

import time
stime=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
# print "======="+stime
def index(request):
    firstMsg = '欢迎来到  \"蜂鸟信用-电影票房数据统计中心\"'
    return render_to_response('index.html',{'firstMsg':firstMsg})
def piaofang(request):
    return render_to_response('piaofangSitelist.html')
def add_piaofangshujuku(request):
    print '这个方法进来了'
    url = 'http://58921.com/'
    pf05 = Piaofangshujk_05()
    pf05.downloadHtml(url)
    for i in pf05.ths:
        print i
    print '---------------------------------'
    try:
        for ii in pf05.dd:
            print '---------------------------------'
            piaofangF = Piaofangshujk.objects.create(
                movie_name=ii[0],
                changci_zhanbi=ii[1],
                wangpiaopf=ii[2],
                hapiaopf=ii[3],
                wandapf=ii[4],
                jinyipf=ii[5],
                xingmeipf=ii[6],
                shishi_pfjine=ii[7],
                yuji_pfjine=ii[8],
                leiji_pfjine=ii[9],
                scrapyTimes=stime
            )
            piaofangF.save()
        # listP = Piaofangshujk.objects.all()
        # print listP
        successMsg = '票房数据库抓取入库'
        return render_to_response('success.html', {'successMsg': successMsg})
    except:
        failedMsg = '票房数据库抓取入库'
        return render_to_response('failed.html', {'failedMsg': failedMsg})

def add_shishiDianying(request):
    url = 'http://www.piaofang168.com/'
    shishi = ShishiDianying_01()
    shishi.downloadHtml(url)

    try:
        for i in shishi.dd:
            shishiP = ShishiDianying.objects.create(
                movie_name=shishi.dataT[i],
                shishi_pfjine=shishi.dataT[i + 1],
                leiji_pfjine=shishi.dataT[i + 2],
                shishipiapian=shishi.dataT[i + 3],
                shishicahngci=shishi.dataT[i + 4],
                shangyingtianshu=shishi.dataT[i + 5],
                scrapyTimes=stime
            )
            shishiP.save()
        successMsg = '实时电影票房网抓取入库'
        return render_to_response('success.html', {'successMsg': successMsg})
    except:
        failedMsg = '实时电影票房网抓取入库'
        return render_to_response('failed.html', {'failedMsg': failedMsg})

def add_Zhongguodianyinxinxi(request):

    url_2 = 'http://www.zgdypw.cn/pors/w/webStatisticsDatas/api/2017-05-10/searchDayBoxOffice'
    xinxi01 = Zhongguodianyinxinxi_01()
    xinxi01.downloadJsonData(url_2)
    try:
        for i in xinxi01.dataT:
            xinxiP = Zhongguodianyinxinxi.objects.create(
                filmName=i['filmName'],
                daySales=i['daySales'],
                filmTotalSales=i['filmTotalSales'],
                daySession=i['daySession'],
                dayAudience=i['dayAudience'],
                rank=i['rank'],
                scrapyTimes=stime
            )
            xinxiP.save()
        successMsg = '中国电影数据信息网抓取入库'
        return render_to_response('success.html', {'successMsg': successMsg})
    except:
        failedMsg = '中国电影数据信息网抓取入库'
        return render_to_response('failed.html', {'failedMsg': failedMsg})

def add_Maoyandianying(request):
    url = 'https://piaofang.maoyan.com/?ver=normal'
    maoyan = Maoyandianying_01()
    maoyan.downAndparse(url)
    maoyan.sendtodb()
    try:
        for i in maoyan.df:
            maoyanP = Maoyandianying.objects.create(
                fileName=i[len(i) - 1],
                leiji_pfjine=i[0],
                shishi_prfjin=i[1],
                piaofangzhanbi=i[2],
                piaipianzhanbi=i[3],
                shangzuolv=i[4],
                scrapyTimes=stime
            )
            maoyanP.save()
        successMsg = '猫眼网抓取入库'
        return render_to_response('success.html', {'successMsg': successMsg})
    except:
        failedMsg = '猫眼网抓取入库'
        return render_to_response('failed.html', {'failedMsg': failedMsg})
def add_Yiendianyingzhiku(request):
    url_4 = 'http://www.cbooo.cn/'
    yien = Yiendianyingzhiku_01()
    yien.downloadHtml(url_4)
    try:
        for i in yien.dataY:
            yienP = Yiendianyingzhiku.objects.create(
                fileName = i[0],
                ShiShi_pfjine = i[1],
                piaoFangZhanBi = i[2],
                leiJi_pfjine = i[3],
                paiPianZhanBi = i[4],
                shangYingTianShu = i[5],
                scrapyTimes=stime
                )
            yienP.save()
            print '分库成功!'
        successMsg = '艺恩电影智库抓取入库'
        return render_to_response('success.html', {'successMsg': successMsg})
    except:
        failedMsg = '艺恩电影智库抓取入库'
        return render_to_response('failed.html', {'failedMsg': failedMsg})
# Create your views here.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千码君2016

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值