This commit is contained in:
MasonLiu 2025-01-14 11:19:32 +08:00
parent 859eca151d
commit 6b242f233d
3 changed files with 127 additions and 30 deletions

75
CodeCalc.py Normal file
View File

@ -0,0 +1,75 @@
import os
import tkinter as tk
from tkinter import filedialog, messagebox, font
def count_lines_and_comments(directory, text_widget):
total_code_lines = 0
total_comment_lines = 0
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.py'):
file_path = os.path.join(root, file)
code_lines = 0
comment_lines = 0
with open(file_path, 'r', encoding='utf-8') as f:
for line in f:
stripped_line = line.strip()
if not stripped_line: # Skip empty lines
continue
if stripped_line.startswith('#'):
comment_lines += 1
else:
code_lines += 1
total_code_lines += code_lines
total_comment_lines += comment_lines
text_widget.insert(tk.END, f"{file_path} - 代码行数: {code_lines}, 注释行数: {comment_lines}\n")
text_widget.insert(tk.END, f"\n'{directory}': 总代码行数: {total_code_lines}, 总注释行数: {total_comment_lines}\n")
def browse_folder():
folder_path = filedialog.askdirectory()
entry_path.delete(0, tk.END)
entry_path.insert(0, folder_path)
def on_calculate():
directory = entry_path.get()
if not directory:
directory = 'E:\\Self-Tool-Code\\Pybot'
if not os.path.exists(directory):
messagebox.showerror("错误", "指定的目录不存在")
return
text_output.delete(1.0, tk.END) # 清空文本框
count_lines_and_comments(directory, text_output)
# 创建主窗口
root = tk.Tk()
root.title("代码行数统计工具")
# 设置字体为宋体
custom_font = font.Font(family="宋体", size=12)
# 创建路径输入框和标签
label_path = tk.Label(root, text="路径:", font=custom_font)
label_path.grid(row=0, column=0, padx=10, pady=10)
entry_path = tk.Entry(root, width=50, font=custom_font)
entry_path.grid(row=0, column=1, padx=10, pady=10)
entry_path.insert(0, "E:\\Self-Tool-Code\\Pybot")
# 创建浏览文件夹按钮
button_browse = tk.Button(root, text="浏览", command=browse_folder, font=custom_font)
button_browse.grid(row=0, column=2, padx=10, pady=10)
# 创建按钮
calculate_button = tk.Button(root, text="计算", command=on_calculate, font=custom_font)
calculate_button.grid(row=1, column=0, columnspan=3, pady=10)
# 创建文本框用于显示输出
text_output = tk.Text(root, width=80, height=20, font=custom_font)
text_output.grid(row=2, column=0, columnspan=3, padx=10, pady=10)
# 运行主循环
root.mainloop()

52
GoogleHackGeneraor.py Normal file
View File

@ -0,0 +1,52 @@
import tkinter as tk
from tkinter import messagebox
class GoogleSearchGenerator:
def __init__(self, root):
self.root = root
self.root.title("谷歌搜索语法生成器")
self.search_query = tk.StringVar()
self.search_query.set("")
self.query_label = tk.Label(root, text="生成的搜索语句:")
self.query_label.pack(pady=5)
self.query_entry = tk.Entry(root, textvariable=self.search_query, width=50)
self.query_entry.pack(pady=5)
self.buttons_frame = tk.Frame(root)
self.buttons_frame.pack(pady=10)
self.create_buttons()
def create_buttons(self):
buttons = [
("正文关键词", "intext:"),
("链接关键词", "inurl:"),
("标题关键字", "intitle:"),
("指定域名", "site:"),
("文件类型:", "filetype:"),
("相关链接:", "link:"),
("查看网页缓存", "cache:"),
("查看站点信息", "info:"),
("搜索相关信息:", "related:"),
]
for text, param in buttons:
button = tk.Button(self.buttons_frame, text=text, command=lambda p=param: self.add_parameter(p))
button.pack(side=tk.LEFT, padx=5)
def add_parameter(self, param):
current_query = self.search_query.get()
if current_query:
new_query = f"{current_query} {param}"
else:
new_query = param
self.search_query.set(new_query)
# messagebox.showinfo("提示", f"已添加参数: {param}")
if __name__ == "__main__":
root = tk.Tk()
app = GoogleSearchGenerator(root)
root.mainloop()

View File

@ -1,30 +0,0 @@
import os
def count_lines_and_comments(directory):
total_code_lines = 0
total_comment_lines = 0
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.py'):
file_path = os.path.join(root, file)
code_lines = 0
comment_lines = 0
with open(file_path, 'r', encoding='utf-8') as f:
for line in f:
stripped_line = line.strip()
if not stripped_line: # Skip empty lines
continue
if stripped_line.startswith('#'):
comment_lines += 1
else:
code_lines += 1
total_code_lines += code_lines
total_comment_lines += comment_lines
print(f"{file_path} - 代码行数: {code_lines}, 注释行数: {comment_lines}")
print(f"\n'{directory}': 总代码行数: {total_code_lines}, 总注释行数: {total_comment_lines}")
# 统计指定目录下的Python文件代码行数和注释行数
directory_path = './PyBot'
count_lines_and_comments(directory_path)