Django的views编写以及结合mysql存库小demo
来源:互联网 发布:java多线程抢票代码 编辑:程序博客网 时间:2024/05/18 00:24
# -*- coding: UTF-8 -*-from Piaofangshujk_05 import Piaofangshujk_05from ShishiDianying_01 import ShishiDianying_01from Zhongguodianyinxinxi_01 import Zhongguodianyinxinxi_01from Maoyandianying_01 import Maoyandianying_01from Yiendianyingzhiku_01 import Yiendianyingzhiku_01from django.shortcuts import render_to_responsefrom huayingtx.models import *import timestime=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())# print "======="+stimedef 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.
阅读全文
0 0
- Django的views编写以及结合mysql存库小demo
- Django的module编写小demo一个
- django的views基本代码
- 用Django写博客(三)编写views
- django的通用视图 (generic views)
- Django基于类的视图(views)
- Django自定义用于Views的装饰器
- Django的views.py文件拆分
- django 结合bootstrap 的初探
- PyMySQL与Django的结合
- Django笔记-URLConf Views
- Django笔记-generic views
- Django笔记-generic views
- Django笔记-URLConf Views
- Django class-based views
- django - generic views
- DJango views用法
- django views test
- mybatis 关于 like %% 查询 mysql oracle sqlserver 数据库
- ThreadLocal详解
- 残
- CF 373D Counting Rectangles is Fun 单调栈+DP
- Java提高篇(1)--JAVA中StringBuffer类常用方法详解
- Django的views编写以及结合mysql存库小demo
- Linux命令小技巧
- 积累学习Kotlin进行开发遇到的错误
- tcp/ip协议栈--socket API 之socket()
- 深入浅出讲解:php的socket通信
- myeclipse2017添加tomcat后,在tomcat启动按钮里面找不到的问题
- 利用 TensorFlow 实现“看图说话”
- 欢迎使用CSDN-markdown编辑器
- jdbcTemplate.queryForList详解