def run_cmd(cmd): """执行CMD命令""" p = subprocess.Popen(cmd, stdout=subprocess.PIPE) return [i.decode() for i in p.communicate()[0].splitlines()]
def get_apk_info(): """获取apk的package,activity名称 :return: list eg ['com.android.calendar', 'com.meizu.flyme.calendar.AllInOneActivity'] """ result = run_cmd("adb shell dumpsys activity top") for line in result: if line.strip().startswith('ACTIVITY'): return line.split()[1].split('/') print(get_apk_info())
:param path: 根目录 :param suffixes: 指定查找的文件后缀名 :param traverse: 如果为False,只遍历一层目录 :return: """ file_list = [] for root, dirs, files in os.walk(path): for file in files: file_suffix = os.path.splitext(file)[1][1:].lower() # 后缀名 if file_suffix in suffixes: file_list.append(os.path.join(root, file)) if not traverse: return file_list
return file_list
if __name__ == '__main__':
keyword = "XXX宝箱"
files = get_files_by_suffix(r"C:\project\config")
for file in files:
with open(file, 'r', encoding='utf-8', errors='ignore') as f: content = f.read().lower() position = content.find(keyword.lower())
if position != -1: print("Find in {0}".format(file)) start = position - 100 if position - 100 > 0 else 0 end = position + 100 if position + 100 < len(content) else len(content) print(content[start:end]) print("_" * 100) 操作远程服务器
sql = "select * from Player where name like '%{0}%'".format(player_name) # 模糊搜索,从玩家名称搜索玩家ID cur.execute(sql) for r in cur.fetchall(): sql = "select * from Account where uid = '{0}'".format(r[0]) # 从玩家ID搜索玩家帐号 cur.execute(sql) for row in cur.fetchall(): print('{0}, {1}, {2}'.format(r[0], r[1], row[2])) # 打印相关信息