python的Django Mysql框架爬坑攻略(3)

python的Django Mysql框架爬坑攻略(3)

首页角色扮演Returnal更新时间:2024-05-09

第三部分,续前节

1、Html中echart的应用 <head>

<script src="//img.17u1u.com//static/js/echarts.js"></script>

</head> <body bgcolor="#202020"> <div id="echt5" style="position:absolute; left:1470px; top:500px; width: 420px;height:440px;">

<script type="text/javascript">

var myecht5= echarts.init(document.getElementById('echt5'));

var option5 = {

tooltip: {},

xAxis: [{

data: ["pjt1","pjt2","pjt3","pjt4","pjt5"],

axisLabel: {

show: true,

textStyle: { color: 'white' }

}

}],

yAxis: [{

axisLabel: {

show: true,

textStyle: { color: 'white' }

}

}],

series: [{

name: '输出电流',

type: 'bar',

itemStyle: {normal: {color: '#a8bcd4'} },

data: {{ crt1 }}

}]

};

myecht5.setOption(option5);

</script>

</div> </body>

2、Html页面跳转 <td align="center" style="width:40px" class="white"><a href = "/pr

<td align="center" class="white" style="width:300px" bgcolor="#f0a060"><a onclick=javascript:pro01()>北京丽贝亚大厦</a></td>

<script>

if({{proqx01}}==1){ function pro01(){ window.location.href="/stn1/"; } }

</script> <input id="pv" type="image" title="pv" src="//img.17u1u.com//static/pics/pv.png" style="..." onclick=javascrtpt:pv()>

<script>

if({{pvqx}}==1){ function pv(){ window.location.href="http://yun.izenery.com:8080/monitor/"; } }

</sc

3、Html中线条闪烁 <div id="lin_eb">

<hr style="position:absolute; left:1255px; top:150px; height:230px; width:230px; border-radius:50%; border-left:8px dotted #505050; border-bottom:8px dotted #505050; border-top:8px dotted #505050; border-right:8px dotted #505050;"/>

<hr style="position:absolute; left:1255px; top:150px; height:230px; width:230px; border-radius:50%; border-left:8px dotted orange; border-bottom:8px dotted orange; border-top:8px dotted orange; border-right:8px dotted orange;"/>

<hr style="position:absolute; left:1215px; top:110px; height:310px; width:310px; border-radius:50%; border-left:10px dotted #505050; border-bottom:5px dotted #505050; border-top:5px dotted #505050; border-right:10px dotted #505050;"/>

<hr style="position:absolute; left:1215px; top:110px; height:310px; width:310px; border-radius:50%; border-left:10px dotted orange; border-bottom:5px dotted orange; border-top:5px dotted orange; border-right:10px dotted orange;"/>

<hr style="position:absolute; left:1165px; top:60px; height:410px; width:410px; border-radius:50%; border-left:10px dotted #505050; border-bottom:5px dotted #505050; border-top:5px dotted #505050; border-right:10px dotted #505050;"/>

<hr style="position:absolute; left:1165px; top:60px; height:410px; width:410px; border-radius:50%; border-left:10px dotted orange; border-bottom:5px dotted orange; border-top:5px dotted orange; border-right:10px dotted orange;"/>

</div>

<script>

function setTime8(){

var lineb=document.getElementById("lin_eb");

lineb.appendChild(lineb.firstChild);

}

setInterval("setTime8()",100);

</script>

def es(request):

if request.method == "GET":

es_pachong.espc()

print("denglu")

response = HttpResponseRedirect('http://cloud.izenery.com:8080/ideer/page/index.do')

return response

return render(request, 'es.html')

d.izenery.com:8080/ideer/page/index.do')

return resp

from selenium import webdriver

def espc():

# 实例化出一个Firefox浏览器

driver = webdriver.Chrome()

driver.set_page_load_timeout(10)

driver.set_script_timeout(10)

# 设置浏览器窗口的位置和大小

driver.set_window_position(10, 10)

driver.set_window_size(200, 200)

# 打开一个页面(合天登录页)

try:

driver.get("http://cloud.izenery.com:8080/ideer/")

except:

print("加载页面太慢,停止加载,继续下一步操作")

driver.execute_script("window.stop()")

# 通过使用选择器选择元素进行模拟输入和点击按钮提交

driver.find_element_by_id('username').clear()

driver.find_element_by_id('username').send_keys("15101092397")

driver.find_element_by_id('pwd').clear()

driver.find_element_by_id('pwd').send_keys("123456")

driver.find_e

5、测试数据的生成,类的建立 import numpy

import threading

import random

# Create your models here.

class login():

user01 = (('kdkj','123456'),(1,1,1,0,0),(1,1,1,1,1,1,1,1,1))

user02 = (('shzf', 'shzf'), (1, 1, 0, 0, 0), (1, 1, 1, 0, 0, 0, 1, 0, 0)) ###eb\pd\ac\gl\pv\es\tf\dd

def __str__(self):

return self.ID

class data_static():

num_pro = 4

num_pd = 2

num_es = 1

num_pv = 1

num_ac = 1

num_gl = 0

def e_use(self):

e_u = random.randint(60, 80)

return e_u

def e_rate(self):

e_r = random.randint(0, 30)

return e_r

def alarm(self):

alm = random.randint(0, 10)

return alm

def alm_rate(self):

a_r = random.randint(-50, 50)

return a_r

def g_use(self):

g_u = random.randint(500, 800)

return g_u

def g_rate(self):

g_r = random.randint(-40, 40)

return g_r

def w_use(self):

w_u = random.randint(1000

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.mysql',

'NAME': 'tht4', ##数据库的名称

'HOST':'127.0.0.1', ##数据库主地址

'PORT':3306,

'USER':'root',

'PASSWORD':'12345

from django.db import models

# Create your models here.

class stn01_info(models.Model):

stn_id = models.IntegerField(primary_key=True)

stn_name = models.CharField(max_length=30)

worker = models.CharField(max_length=30)

stn_x = models.IntegerField()

stn_y = models.IntegerField()

trm01_cap = models.IntegerField()

trm02_cap = models.IntegerField()

def __str__(self):

return se

from django.db import models class user_info(models.Model):

ID = models.IntegerField(primary_key=True)

user_name = models.CharField(max_length=30)

user_key = models.CharField(max_length=30) 注意!不要在最后写: def __str__(self):

return self.ID

dels.IntegerField()

trm02_cap = models.IntegerField()

def __str__(self):

return self.ID

7、数据库记录读取

Model

from django.db import models class user_info(models.Model):

ID = models.IntegerField(p

egerField(p

8、数据库中读出的字符串转换为整形数组 temp = user_info.objects.get(user_name='kdkj')

user01 = temp.qx_pro.split(',') ##先把字符串转换为数组

user01 = list(map(int,user01)) ##再把字符数组转换为

9、Django打包发布 安装pyinstaller pip install pyinstaller 制作项目的.spec文件

进入django项目所在路径,运行 pyi-makespec -D manage.py 在路径下,生成一个.spec文件 在.spec文件中,注意hiddenimports=["pyexpat"] pyinstaller manage.spec

nfo.objects.get(u

8、数据库中读出的字符串转换为整形数组 temp = user_info.objects.get(user_name='kdkj')

user01 = temp.qx_pro.split(',') ##先把字符串转换为数组

user01 = list(map(int,user01)) ##再把字符数组转换为

9、Django打包发布 安装pyinstaller pip install pyinstaller 制作项目的.spec文件

进入django项目所在路径,运行 pyi-makespec -D manage.py 在路径下,生成一个.spec文件 在.spec文件中,注意hiddenimports=["pyexpat"] pyinstaller manage.spec

pyinstaller manage.spec

10、打包以后图片不能加载

步骤1:在settings.py文件的最后加上以下内容:

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(os.path.dirname(__file__),'static')

# 设置图片等静态文件的路径

STATICFILES_DIRS = (

('css',os.path.join(STATIC_ROOT,'css').replace('\\','/') ),

('js',os.path.join(STATIC_ROOT,'js').replace('\\','/') ),

('images',os.path.join(STATIC_ROOT,'images').replace('\\','/') ),

('upload',os.path.join(STATIC_ROOT,'upload').replace('\\','/') ),

)

步骤2:在urls.py文件的开头第一行和第二行分别加上以下内容:

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

from django.contrib import staticfiles

在urls

11、利用pymysql操作数据库 import pymysql data_db = pymysql.connect(host='localhost',

port=3306,

user='root',

passwd='123456',

db='kd')

# 创建游标

cursor = data_db.cursor()

# 查询

try:

sql = "select * from app01_data_smp"

cursor.execute(sql)

row_num = cursor.rowcount # 查询一共有多少条数据

data_store = cursor.fetchall()

dt_id = data_store[row_num - 1][0]

print(dt_id)

except:

print("error")

for i in range(10):

dt_id = dt_id 1

sql = "INSERT INTO `kd`.`app01_data_smp` (`dt_ID`, `date_ic`, `time_ic`, `dt_dir`, `dt_type`, `dt_value`, `sensor_id`) VALUES (%s,%s,%s,%s,%s,%s,%s)"

nowtime = datetime.datetime.now()

date_ic = int("d" % nowtime.year "d" % nowtime.month "d" % nowtime.day)

time_ic = int("d" % nowtime.hour "d" % nowtime.minute "d" % nowtime.second)

dt_dir = 1

dt_type = 19

dt_value = random.randint(60, 80)

sensor_id = 1001010205

cursor.execute(sql, [dt_id, date_ic, time_ic, dt_dir, dt_type, dt_value, sensor_id])

time.sleep(0.05)

12、获取系统日期和时间 import datetime nowtime = datetime.datetime.now()

date_ic = int("d" % nowtime.year "d" % nowtime.month "d" % nowtime.day)

time_ic = int("d" % nowtime.hour "d" % nowtime.minu

dt_type = 19

dt_value = random.randint(60, 80)

sensor_id = 1001010205

cursor.execute(sql, [dt_id, date_ic, time_ic, dt_dir, dt_type, dt_value, sensor_id])

time.sleep(0.05)

# 提交,不然无法保存新建或者修改的数据

data_db.commit()

# 关闭游标

cursor.cl

12、获取系统日期和时间 import datetime nowtime = datetime.datetime.now()

date_ic = int("d" % nowtime.year "d" % nowtime.month "d" % nowtime.day)

time_ic = int("d" % nowtime.hour "d" % nowtime.minute "d" % nowtime.second)

% nowtime.hour "d" % nowtime.minute "d" % nowtime.second)

查看全文
大家还看了
也许喜欢
更多游戏

Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved