示例#1
0
def save_index_week(lists):

    sql = MysqlPython()
    # 清空表中数据
    sql_delete1 = 'delete from weather_index_today'
    sql_delete2 = 'delete from weather_index_tomorrow'

    sql.execute_database(sql_delete1)
    sql.execute_database(sql_delete2)

    half_list = len(lists) // 2

    i = 1
    for _ in lists[:half_list]:
        sql.execute_database('insert into weather_index_today value\
            (\'%s\', \'%s\')' % (i, _))
        i += 1

    j = 1
    for _ in lists[half_list:]:
        sql.execute_database('insert into weather_index_tomorrow value\
            (\'%s\', \'%s\')' % (j, _))
        j += 1
示例#2
0
def save_weather_now(lists):

    sql = MysqlPython()

    # 清空表中数据
    sql_delete = 'delete from weather_now'
    sql.execute_database(sql_delete)

    # 插入数据
    i = 1
    while True:
        for _ in lists:
            sql.execute_database('insert into weather_now value\
                (\'%s\',\'%s\')' % (i, _))
            i += 1
        if i > len(lists):
            break
示例#3
0
def save_weather_week(lists):

    sql = MysqlPython()
    # print(lists)

    sql_delete = 'delete from weather_week'
    sql.execute_database(sql_delete)

    i = 1
    while True:
        for _ in lists:
            sql.execute_database(
                'insert into weather_week value\
            (\'%s\',\' %s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')' %
                (i, _['month_day'], _['date'], _['weather'][0].strip(),
                 _['weather'][1], _['weather'][2].split(' ')[0],
                 _['weather'][2].split(' ')[1], _['air_quality']))
            i += 1
        if i > len(lists):
            break
示例#4
0
from mysqlpython import MysqlPython

sqlh = MysqlPython("danei")

upd = "update t1 set t1name='C2' where t1name='B2'"

sqlh.execute(upd)

sql = "select * from t1"
print(sqlh.All(sql))
示例#5
0
#从py文件中导入类
from mysqlpython import MysqlPython

#test update
name = input("请输入要修改的学生姓名:")
score = int(input("请输入该学生的新成绩:"))

sql = "update t1 set score='%s'where name='%s'" % (score, name)

sqlH = MysqlPython('localhost', 3306, 'python', 'root', '123456')

sqlH.zhixing(sql)
示例#6
0
from mysqlpython import MysqlPython

from hashlib import sha1

sqlh = MysqlPython("danei")

#让用户输入用户名
uname = input("请输入注册用户名: ")

#到user表中查询此用户信息
#sele = 'select username from user where username=%s'
#r = sqlh.All(sele,[uname])

# if len(r) != 0:
#     print("该用户已存在")
# else:
#     #输入密码
#     pwd1 = input("请输入密码: ")
#     pwd2 = input("请再次输入密码: ")
#
#     if pwd1 == pwd2:
#         #把密码加密存入数据库
#         #创建加密对象
#         s = sha1()
#         #加密,参数一定要为bytes数据类型
#         s.update(pwd1.encode("utf-8"))
#         #返回十六进制加密结果
#         pwd = s.hexdigest()
#         ins = 'insert into user values(%s,%s)'
#         sqlh.execute(ins,[uname,pwd])
#         print("注册成功")
示例#7
0
from mysqlpython import MysqlPython
from hashlib import sha1

#接受用户输入的用户名和密码
uname = input('请输入用户名:')
pwd = input('请输入密码:')

#把用户输入的密码用sha1加密
s1 = sha1()  #创建一个sha1加密对象
s1.update(pwd.encode('utf8'))
pwd2 = s1.hexdigest()  #返回16进制加密结果

#两个密码做对比
test = MysqlPython('studb5')
sel = 'select password from user where username = %s'
r = test.all(sel, [uname])
# print(r)

if len(r) == 0:
    print('用户名不存在')
elif pwd2 == r[0][0]:
    print('登录成功')
else:
    print('密码错误')
示例#8
0
from mysqlpython import MysqlPython

sqlh = MysqlPython('studb5')
dele = 'delete from t1 where name = " "'
sqlh.add_del_update(dele)