1、文件Auto_update_data,需要处理的映射基础数据
#定义需要导入的映射数据
#以字典进行定义 [公司类目id : 平台类目id]
#d = {key1 : value1, key2 : value2, key3 : value3 }
ap_category_relation_data = {
5807 : 10002200,
6375 : 10100737,
6772 : 10100733,
5816 : 1540,
5832 : 1540,
}
2、文件Auto_update_db,自己封装的数据库操作
#数据库操作
import pymysql
#数据库类
class LazadaDb:
def __init__(self, host, user, password, database, port):
#打开数据库连接
db = pymysql.connect(
host = host,
user = user,
password = password,
database = database,
port = port
)
#使用 cursor()方法创建一个游标对象 cursor
self.db = db
self.cursor = db.cursor()
#定义一个查询的方法 查一列
def get(self, sql):
try:
cursor = self.cursor
#执行SQL语句
cursor.execute(sql)
#使用 fetchone() 方法获取单条数据
data = cursor.fetchone()
#返回数据
return data
except:
return '获取数据出错101'
def __del__(self):
#析构函数 关闭数据库连接
self.db.close()
3、文件Auto_update_way,递归,获取类目树方法
#书写公共方法
import Auto_update_db
#无限极往上获取平台类目树信息
def platformCategoryVerify(platform_category_id):
tree = []
#获取平台数据库类
LazadaDb = Auto_update_db.LazadaDb('数据库ip', 'test', '密码', 'nt_auto_publish', 3311)
#拼接查询sql
sql = "SELECT category_id,category_name,parent_id,level FROM ap_categories WHERE platform = 1 AND site_code = 'MY' AND category_id = " + str(platform_category_id)
#获取类目信息
apCategories_info = LazadaDb.get(sql)
#判断类目是否存在
if apCategories_info:
#存在,通过父类id继续获取上级
tree = platformCategoryVerify(apCategories_info[2])
#将获取到类目,添加到 定义的列表 tree 中
tree.append(apCategories_info)
return tree
#无限极往上获取公司类目树信息
def companyCategoryVerify(company_category_id):
tree = []
#获取公司数据库
SysDb = Auto_update_db.LazadaDb('数据库ip', 'test', '密码', 'nt_product', 3307)
#拼接查询sql
sql = "SELECT id, category_name, parent_id, level FROM nt_categories WHERE status = 1 AND ID = " + str(company_category_id)
#获取类目信息
sysCategories_info = SysDb.get(sql)
#p判断类目是否存在
if sysCategories_info:
#存在,通过父类id继续获取上级
tree = companyCategoryVerify(sysCategories_info[2])
#将获取到类目,添加到 定义的列表 tree 中
tree.append(sysCategories_info)
return tree
4、文件Auto_update_attr,最后组装数据
#刷自动化类目
import Auto_update_data
import Auto_update_way
#获取需要处理的类目映射数据
list_data = Auto_update_data.ap_category_relation_data
#定义一个最终数据的列表
ap_category_relation_data = []
for i in list_data:
print('处理=', list_data[i])
#获取平台类目树信息
platform_tree_info = Auto_update_way.platformCategoryVerify(list_data[i])
platform_tree = '->' . join([str(platform_tree_info[i][0]) for i in range(0, len(platform_tree_info))])
platform_tree_name = '->' . join([str(platform_tree_info[i][1]) for i in range(0, len(platform_tree_info))])
#获取公司类目树信息
company_tree_info = Auto_update_way.companyCategoryVerify(i)
company_tree = '->' . join([str(company_tree_info[i][0]) for i in range(0, len(company_tree_info))])
company_tree_name = '->' . join([str(company_tree_info[i][1]) for i in range(0, len(company_tree_info))])
value_dic = {
'platform' : 1,
'site_code' : 'MY',
'platform_category_id' : list_data[i], #平台类目信息
'platform_category_name' : platform_tree_info[1][1],
'platform_tree' : platform_tree,
'platform_tree_name' : platform_tree_name,
'company_category_id' : i, #公司类目信息
'company_category_name' : company_tree_info[1][1],
'company_tree' : company_tree,
'company_tree_name' : company_tree_name,
}
ap_category_relation_data.append(value_dic)
#得到最后映射好的数据
for i in ap_category_relation_data:
print(i)
print('======')
5、最后运行文件,打印输出

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
我有一个在Linux服务器上运行的ruby脚本。它不使用rails或任何东西。它基本上是一个命令行ruby脚本,可以像这样传递参数:./ruby_script.rbarg1arg2如何将参数抽象到配置文件(例如yaml文件或其他文件)中?您能否举例说明如何做到这一点?提前谢谢你。 最佳答案 首先,您可以运行一个写入YAML配置文件的独立脚本:require"yaml"File.write("path_to_yaml_file",[arg1,arg2].to_yaml)然后,在您的应用中阅读它:require"yaml"arg
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Pythonconditionalassignmentoperator对于这样一个简单的问题表示歉意,但是谷歌搜索||=并不是很有帮助;)Python中是否有与Ruby和Perl中的||=语句等效的语句?例如:foo="hey"foo||="what"#assignfooifit'sundefined#fooisstill"hey"bar||="yeah"#baris"yeah"另外,类似这样的东西的通用术语是什么?条件分配是我的第一个猜测,但Wikipediapage跟我想的不太一样。
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht
华为OD机试题本篇题目:明明的随机数题目输入描述输出描述:示例1输入输出说明代码编写思路最近更新的博客华为od2023|什么是华为od,od薪资待遇,od机试题清单华为OD机试真题大全,用Python解华为机试题|机试宝典【华为OD机试】全流程解析+经验分享,题型分享,防作弊指南华为o
我想解析一个已经存在的.mid文件,改变它的乐器,例如从“acousticgrandpiano”到“violin”,然后将它保存回去或作为另一个.mid文件。根据我在文档中看到的内容,该乐器通过program_change或patch_change指令进行了更改,但我找不到任何在已经存在的MIDI文件中执行此操作的库.他们似乎都只支持从头开始创建的MIDI文件。 最佳答案 MIDIpackage会为您完成此操作,但具体方法取决于midi文件的原始内容。一个MIDI文件由一个或多个音轨组成,每个音轨是十六个channel中任何一个上的
本文主要介绍在使用Selenium进行自动化测试或者任务时,对于使用了iframe的页面,如何定位iframe中的元素文章目录场景描述解决方案具体代码场景描述当我们在使用Selenium进行自动化测试的时候,可能会遇到一些界面或者窗体是使用HTML的iframe标签进行承载的。对于iframe中的标签,如果直接查找是无法找到的,会抛出没有找到元素的异常。比如近在咫尺的例子就是,CSDN的登录窗体就是使用的iframe,大家可以尝试通过F12开发者模式查看到的tag_name,class_name,id或者xpath来定位中的页面元素,会抛出NoSuchElementException异常。解决
//1.验证返回状态码是否是200pm.test("Statuscodeis200",function(){pm.response.to.have.status(200);});//2.验证返回body内是否含有某个值pm.test("Bodymatchesstring",function(){pm.expect(pm.response.text()).to.include("string_you_want_to_search");});//3.验证某个返回值是否是100pm.test("Yourtestname",function(){varjsonData=pm.response.json