Browse Source

修改yaml文件的路径

master
LG_lai 2 years ago
parent
commit
9ce14464cb
8 changed files with 229 additions and 25 deletions
  1. 25
      InsertData.robot
  2. 2
      Opr-Center-RF-Api/000Login/LoginCase.robot
  3. 18
      用户资料/DataBase.py
  4. 53
      用户资料/Execl.py
  5. 40
      用户资料/WXlogin.py
  6. BIN
      用户资料/__pycache__/Execl.cpython-36.pyc
  7. 89
      用户资料/input.py
  8. 27
      用户资料/phone.py

25
InsertData.robot

@ -5,7 +5,7 @@ Library DatabaseLibrary
*** Test Cases ***
ReadData
Import Variables D:\\LYL\\Study\\Ptest\\用户资料\\Execl.py
Import Variables ${CURDIR}\\用户资料\\Execl.py
#${DList} Set Variable ${cap}
log ${phone_list}
LOG ${phone}
@ -20,26 +20,3 @@ Connect_Database
${UserData} Query SELECT * FROM `uec`.`qn_account` WHERE `tid` = '13517986787' AND `is_delete` = '0'
${accountId} Set Variable ${UserData[0][0]}
Disconnect From Database
ReadData-1
#读取execl表数据
Open Excel D:\\LYL\\Study\\Robot_framework\\space\\Dating-Agency\\相亲用户资料.xls
${rowCount} Get Row Count 用户资料 #获取表行数
${List} Create List
FOR ${x} IN RANGE ${rowCount -1} #读取count-1行,不读取首行
${read_row} Get Row Values 用户资料 ${x+1} #1代表execl的第一行,读完${rowCount}是一个list
Set Suite Variable ${read_row}
#\ Insert_Into_List ${List} ${x} ${row_list}
#${Count_List} Evaluate len(${List})
#Set Suite Variable ${Count_List}
#Set Suite Variable ${List}
*** Keywords ***
Keyword
#处理每行的List
${row_list} Create List
${count_column} Get Column Count 用户资料 #获取表列数
@{int_values_index} Create List ${1} ${2} ${3} ${4} ${5} ${7} ${9} ${10} ${11} ${12}
FOR ${i} IN RANGE ${count_column} #循环文本列数
${row_values} Set Variable ${read_row[${i}][1]}
${if_empty} Run Keyword And Return Status Should Be Equal As Strings ${row_values} ${empty} #判断是否为空

2
Opr-Center-RF-Api/000Login/LoginCase.robot

@ -1,5 +1,5 @@
*** Settings ***
Suite Setup Import Variables D:\\LYL\\Study\\Robot_framework\\space\\Opr-Center-RF-Api\\000Login\\login.yaml
Suite Setup Import Variables ${CURDIR}\\login.yaml
Resource LoginResource.robot
*** Test Cases ***

18
用户资料/DataBase.py

@ -0,0 +1,18 @@
import pymysql
import xlrd
"""
mysql数据库
"""
# 打开数据库连接
conn = pymysql.connect(
host='8.135.8.221', # MySQL服务器地址
user='root', # 用户名
password='qniaothreetwoonego', # 密码
charset='utf8',
port=3306, # 端口
database='dating-agency-service', # 数据库名称
)
#断开连接
conn.close()

53
用户资料/Execl.py

@ -0,0 +1,53 @@
import xlrd
# """
# 二、读取excel文件
# """
# FilePath = 'D:/LYL/Study/Robot_framework/space/Dating-Agency/相亲用户资料.xls'
#
# # 1.打开excel文件
# wkb = xlrd.open_workbook(FilePath)
# # 2.获取sheet
# sheet = wkb.sheet_by_index(0) # 获取第一个sheet表['用户资料']
# # 3.获取总行数
# rows_number = sheet.nrows
# # 4.遍历sheet表中所有行的数据,并保存至一个空列表cap[]
# cap = []
# for i in range(1,rows_number): # 跳过表头
# x = sheet.row_values(i) # 获取第i行的值(从0开始算起)
# cap.append(x)
# print(cap)
#
#
# for Userinfo in cap:
# # U = int(Userinfo[0])
# Uname = Userinfo[0]
# Usex = Userinfo[1]
# Uhight = int(Userinfo[2])
# Uwight = int(Userinfo[3])
# Uage = int(Userinfo[4])
# Ucity = Userinfo[5]
# Uedu = Userinfo[6]
# Umarry = Userinfo[7]
# Uincome = Userinfo[8]
# Unickname = Userinfo[9]
#
"""
phone-text.txt文件的第一列数据
"""
phone_list = []
try:
file = open('D:/LYL/Test/ZTB/phone - test.txt', 'r')
except FileNotFoundError:
print('File is not found')
else:
lines = file.readlines()
for line in lines:
a = line.split(',')
x = a[0]
phone_list.append(x)
file.close()
for Phone in phone_list:
print(Phone)

40
用户资料/WXlogin.py

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# import weixin
from datetime import datetime, timedelta
from flask import Flask, redirect, request, url_for
from weixin import WeixinLogin
app = Flask(__name__)
app_id = 'wx13d6b82e0cf2bd9b'
app_secret = ''
wx_login = WeixinLogin(app_id, app_secret)
@app.route("/login")
def login():
openid = request.cookies.get("openid")
next = request.args.get("next") or request.referrer or "/",
if openid:
return redirect(next)
callback = url_for("authorized", next=next, _external=True)
url = wx_login.authorize(callback, "snsapi_base")
return redirect(url)
@app.route("/authorized")
def authorized():
code = request.args.get("code")
if not code:
return "ERR_INVALID_CODE", 400
next = request.args.get("next", "/")
data = wx_login.access_token(code)
openid = data.openid
resp = redirect(next)
expires = datetime.now() + timedelta(days=1)
resp.set_cookie("openid", openid, expires=expires)
return resp

BIN
用户资料/__pycache__/Execl.cpython-36.pyc

89
用户资料/input.py

@ -0,0 +1,89 @@
import pymysql
import xlrd
"""
mysql数据库
"""
# 打开数据库连接
conn = pymysql.connect(
host='8.135.8.221', # MySQL服务器地址
user='root', # 用户名
password='qniaothreetwoonego', # 密码
charset='utf8', #
port=3308, # 端口
db='dating-agency-service', # 数据库名称
)
# 使用cursor()方法获取操作游标
c = conn.cursor()
# """
# 二、读取excel文件
# """
# FilePath = 'D:/LYL/Study/Robot_framework/space/Dating-Agency/相亲用户资料.xls'
#
# # 1.打开excel文件
# wkb = xlrd.open_workbook(FilePath)
# # 2.获取sheet
# sheet = wkb.sheet_by_index(0) # 获取第一个sheet表['用户资料']
# # 3.获取总行数
# rows_number = sheet.nrows
# # 4.遍历sheet表中所有行的数据,并保存至一个空列表cap[]
# cap = []
# for i in range(1,rows_number):
# x = sheet.row_values(i) # 获取第i行的值(从0开始算起)
# cap.append(x-1)
# print(cap)
# """
# 三、将读取到的数据批量插入数据库
# """
# for Userinfo in cap:
# # U = int(Userinfo[0])
# Uname = Userinfo[0]
# Usex = Userinfo[1]
# Uhight = int(Userinfo[2])
# Uwight = int(Userinfo[3])
# Uage = int(Userinfo[4])
# Ucity = Userinfo[5]
# Uedu = Userinfo[6]
# Umarry = Userinfo[7]
# Uincome = Userinfo[8]
# Unickname = Userinfo[9]
# # 使用f-string格式化字符串,对sql进行赋值
# c.execute(f"insert into student(Sno,Sname,Ssex,Sage,Sdept) value ('{Uname}','{Usex}','{Uhight}','{Uage}','{Ucity}','{Uedu}','{Umarry}','{Uincome}','{Unickname}')")
# conn.commit()
# conn.close()
# print("插入数据完成!")
"""
phone-text.txt文件的第一列数据
"""
phone_list = []
try:
file = open('D:/LYL/Test/ZTB/phone - test.txt', 'r')
except FileNotFoundError:
print('File is not found')
else:
lines = file.readlines()
for line in lines:
a = line.split(',')
x = a[0]
phone_list.append(x)
file.close()
#
for Phone in phone_list:
print(Phone)
"""
account表中tid=Phone的所有数据
"""
for Phone in phone_list:
print(Phone)
c.execute(f"SELECT * FROM `uec`.`qn_account` WHERE `tid` = '{Phone}' AND `is_delete` = '0'")
conn.commit()
conn.close()

27
用户资料/phone.py

@ -0,0 +1,27 @@
import random
# def create_a_phone():
# # 第二位数字
# second = [3, 4, 5, 7, 8][random.randint(0, 4)]
# # 第三位数字
# third = {3: random.randint(0, 9),
# 4: [5, 7, 9][random.randint(0, 2)],
# 5: [i for i in range(10) if i != 4][random.randint(0, 8)],
# 7: [i for i in range(10) if i not in [4, 9]][random.randint(0, 7)],
# 8: random.randint(0, 9), }[second]
# # **后八位数字
# suffix = random.randint(9999999, 100000000)
# # 拼接手机号
# return "1{}{}{}".format(second, third, suffix)
#
# create_a_phone()
def raddomPhone():
headList = ["130", "131", "132", "133", "134", "135", "136", "137", "138", "139",
"147", "150", "151", "152", "153", "155", "156", "157", "158", "159",
"186", "187", "188", "189"]
return (random.choice(headList) + "".join(random.choice("0123456789") for i in range(8)))
Loading…
Cancel
Save