当前位置: 首页 > news >正文

做像淘宝网的网站怎么做网页宣传

做像淘宝网的网站,怎么做网页宣传,wordpress始终无法登录,wordpress美化文章内相册我们平时从网上下载一些文件,文件名很多都是一大串字母和数字,不打开看看,根本不知道里面是什么内容。 我想能不能做个工具,把我们一个文件夹下面的所有word、excel、ppt、pdf文件重命名为文件内容的第一行。 我们有些朋友可能不会…

我们平时从网上下载一些文件,文件名很多都是一大串字母和数字,不打开看看,根本不知道里面是什么内容。

在这里插入图片描述

我想能不能做个工具,把我们一个文件夹下面的所有word、excel、ppt、pdf文件重命名为文件内容的第一行。

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

我们有些朋友可能不会编程,别慌,不会编程也没关系,我们可以让AI帮我们写一个Python程序。

下面我就让Kimi帮我们写一个程序:

在这里插入图片描述

我把上面这段代码复制到vscode中,把‘path_to_your_directory’替换成自己的文件夹路径,直接运行一下。

在这里插入图片描述

很不幸,报错了,没事,把错误提示复制出来,继续问Kimi:

在这里插入图片描述

再报错,再问:

在这里插入图片描述

你就不厌其烦的问。

AI的一个好处是他永远不会发脾气,哈哈,你只管问就行,不管你的问题有多白痴,它总是会耐心回答,也不会笑话你,这点AI比人类要强百倍。

最终AI给出了一个可运行的版本:

import os
from docx import Document
from openpyxl import load_workbook
from pptx import Presentation
from pdfminer.high_level import extract_textdef get_first_line_from_word(file_path):try:doc = Document(file_path)return doc.paragraphs[0].text if doc.paragraphs else ''except Exception as e:print(f"Error reading Word file {file_path}: {e}")return ''def get_first_line_from_excel(file_path):try:wb = load_workbook(file_path)sheet = wb.activefor row in sheet.iter_rows(min_row=1, values_only=True):for value in row:if value is not None:return str(value)return ''except Exception as e:print(f"Error reading Excel file {file_path}: {e}")return ''def get_first_line_from_ppt(file_path):try:presentation = Presentation(file_path)for slide in presentation.slides:for shape in slide.shapes:if hasattr(shape, 'text') and shape.text:return shape.text[:shape.text.index('\n')] if '\n' in shape.text else shape.textreturn ''except Exception as e:print(f"Error reading PPT file {file_path}: {e}")return ''def get_first_line_from_pdf(file_path):try:text = extract_text(file_path)return text.split('\n', 1)[0] if text else ''except Exception as e:print(f"Error reading PDF file {file_path}: {e}")return ''def rename_files(directory):for filename in os.listdir(directory):if filename.lower().endswith(('.docx', '.xlsx', '.pptx', '.pdf')) and not filename.lower().startswith('.~') :file_path = os.path.join(directory, filename)first_line = ''if filename.lower().endswith('.docx'):first_line = get_first_line_from_word(file_path)elif filename.lower().endswith('.xlsx'):first_line = get_first_line_from_excel(file_path)elif filename.lower().endswith('.pptx'):first_line = get_first_line_from_ppt(file_path)elif filename.lower().endswith('.pdf'):first_line = get_first_line_from_pdf(file_path)if first_line:new_filename = first_line.strip() + os.path.splitext(filename)[1]new_file_path = os.path.join(directory, new_filename)os.rename(file_path, new_file_path)print(f"Renamed {filename} to {new_filename}")else:print(f"No first line found for {filename}")# Specify the directory containing the files
directory = '/Users/zhan/Documents/test'  # Replace with the path to your directory
rename_files(directory)

运行效果如下:

在这里插入图片描述

我们还需要一个UI界面,让我们可以在图形界面上操作,我们继续问Kimi:

在这里插入图片描述
最终代码如下:

import os
from docx import Document
from openpyxl import load_workbook
from pptx import Presentation
from pdfminer.high_level import extract_text
import tkinter as tk
from tkinter import filedialog, messagebox
from tkinter import ttkdef get_first_line_from_word(file_path):try:doc = Document(file_path)return doc.paragraphs[0].text if doc.paragraphs else ''except Exception as e:print(f"Error reading Word file {file_path}: {e}")return ''def get_first_line_from_excel(file_path):try:wb = load_workbook(file_path)sheet = wb.activefor row in sheet.iter_rows(min_row=1, values_only=True):for value in row:if value is not None:return str(value)return ''except Exception as e:print(f"Error reading Excel file {file_path}: {e}")return ''def get_first_line_from_ppt(file_path):try:presentation = Presentation(file_path)for slide in presentation.slides:for shape in slide.shapes:if hasattr(shape, 'text') and shape.text:return shape.text[:shape.text.index('\n')] if '\n' in shape.text else shape.textreturn ''except Exception as e:print(f"Error reading PPT file {file_path}: {e}")return ''def get_first_line_from_pdf(file_path):try:text = extract_text(file_path)return text.split('\n', 1)[0] if text else ''except Exception as e:print(f"Error reading PDF file {file_path}: {e}")return ''def rename_files(directory):for filename in os.listdir(directory):if filename.lower().endswith(('.docx', '.xlsx', '.pptx', '.pdf')) and not filename.lower().startswith('.~') :file_path = os.path.join(directory, filename)first_line = ''if filename.lower().endswith('.docx'):first_line = get_first_line_from_word(file_path)elif filename.lower().endswith('.xlsx'):first_line = get_first_line_from_excel(file_path)elif filename.lower().endswith('.pptx'):first_line = get_first_line_from_ppt(file_path)elif filename.lower().endswith('.pdf'):first_line = get_first_line_from_pdf(file_path)if first_line:new_filename = first_line.strip() + os.path.splitext(filename)[1]new_file_path = os.path.join(directory, new_filename)os.rename(file_path, new_file_path)print(f"Renamed {filename} to {new_filename}")else:print(f"No first line found for {filename}")# Specify the directory containing the files
directory = '/Users/zhan/Documents/test'  # Replace with the path to your directory      # 这里是之前定义的rename_files函数和子函数
def choose_directory():directory = filedialog.askdirectory()if directory:entry.delete(0, tk.END)entry.insert(0, directory)def rename_files_with_ui():directory = entry.get()if not directory:messagebox.showerror("错误", "请选择一个文件夹")returnif not os.path.isdir(directory):messagebox.showerror("错误", "所选路径不是一个文件夹")returntry:rename_files(directory)messagebox.showinfo("完成", "文件重命名完成")except Exception as e:messagebox.showerror("错误", f"发生错误: {e}")# 创建主窗口
root = tk.Tk()
root.title("文件批量重命名工具")# 创建一个标签和输入框用于显示选择的文件夹路径
label = ttk.Label(root, text="请选择文件夹:")
label.pack()
entry = tk.Entry(root, width=30)
entry.pack()# 创建一个按钮,点击时弹出选择文件夹的对话框
browse_button = ttk.Button(root, text="浏览", command=choose_directory)
browse_button.pack()# 创建一个按钮,点击时执行重命名操作
rename_button = ttk.Button(root, text="确定", command=rename_files_with_ui)
rename_button.pack()# 设置窗口的尺寸
width = 350  # 宽度
height = 200  # 高度# 获取屏幕的宽度和高度
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()# 计算窗口的中心坐标
x = (screen_width / 2) - (width / 2)
y = (screen_height / 2) - (height / 2)# 将窗口放置在屏幕中心
root.geometry(f'{width}x{height}+{int(x)}+{int(y)}')# 运行主循环
root.mainloop()

我们看下运行效果:

在这里插入图片描述

试了一下,功能和上面的程序是一样的。

最后一步就是打包程序了,同样我们问下AI:

在这里插入图片描述
一共就两步:

  1. 安装PyInstaller
pip install pyinstaller
  1. 使用PyInstaller打包
pyinstaller --onefile --windowed file_renamer_gui.py

注意要把“file_renamer_gui.py"替换成你自己的文件名。

打包好之后,在项目目录的dist文件夹下就可以找到打包好的文件。

在这里插入图片描述

双击打开即可运行,效果是一样的。

在这里插入图片描述

好了,这个工具就写好了。

有了AI的助攻,我们想写什么工具直接让AI帮我们写就好了,是不是给了你很大的信心?

原来编程也不难,编程我也会啊~

上面的代码亲测可用,如果你想直接下载exe文件,关注公众号“编程我也会”,回复“重命名”即可下载。


文章转载自:
http://benzoate.c7617.cn
http://waterworn.c7617.cn
http://pluckless.c7617.cn
http://kjv.c7617.cn
http://merchantlike.c7617.cn
http://quadrangularly.c7617.cn
http://amen.c7617.cn
http://orthography.c7617.cn
http://rockabilly.c7617.cn
http://galactophore.c7617.cn
http://jeering.c7617.cn
http://interprovincial.c7617.cn
http://nobeing.c7617.cn
http://housephone.c7617.cn
http://jibaro.c7617.cn
http://degage.c7617.cn
http://countercheck.c7617.cn
http://valvelet.c7617.cn
http://sublabial.c7617.cn
http://hydrozoan.c7617.cn
http://comptroller.c7617.cn
http://feathery.c7617.cn
http://epitaph.c7617.cn
http://overparted.c7617.cn
http://periphyton.c7617.cn
http://waterward.c7617.cn
http://atwitter.c7617.cn
http://canister.c7617.cn
http://surfmanship.c7617.cn
http://lockmaker.c7617.cn
http://mutilate.c7617.cn
http://your.c7617.cn
http://pharmacogenetics.c7617.cn
http://jazzetry.c7617.cn
http://characterless.c7617.cn
http://bromidic.c7617.cn
http://exocentric.c7617.cn
http://histomap.c7617.cn
http://addict.c7617.cn
http://delight.c7617.cn
http://hemorrhage.c7617.cn
http://sankara.c7617.cn
http://levitation.c7617.cn
http://retrospective.c7617.cn
http://accent.c7617.cn
http://karma.c7617.cn
http://songlet.c7617.cn
http://vicariously.c7617.cn
http://flood.c7617.cn
http://divi.c7617.cn
http://strafford.c7617.cn
http://surfeit.c7617.cn
http://blueness.c7617.cn
http://chancel.c7617.cn
http://halide.c7617.cn
http://resupply.c7617.cn
http://declining.c7617.cn
http://dilution.c7617.cn
http://enchanting.c7617.cn
http://midbrain.c7617.cn
http://chemostat.c7617.cn
http://thoughtfulness.c7617.cn
http://shahaptian.c7617.cn
http://nebula.c7617.cn
http://styli.c7617.cn
http://silicone.c7617.cn
http://endothelium.c7617.cn
http://immutable.c7617.cn
http://meanie.c7617.cn
http://chloroplast.c7617.cn
http://osmoregulation.c7617.cn
http://adermin.c7617.cn
http://infiltrate.c7617.cn
http://commercially.c7617.cn
http://mammalia.c7617.cn
http://spongious.c7617.cn
http://priory.c7617.cn
http://dietarian.c7617.cn
http://steamship.c7617.cn
http://msn.c7617.cn
http://wallboard.c7617.cn
http://hesitatingly.c7617.cn
http://communise.c7617.cn
http://amphiphyte.c7617.cn
http://shinbone.c7617.cn
http://overprescription.c7617.cn
http://myelitic.c7617.cn
http://dreich.c7617.cn
http://astigmatic.c7617.cn
http://lean.c7617.cn
http://marathonian.c7617.cn
http://zeloso.c7617.cn
http://inscript.c7617.cn
http://asking.c7617.cn
http://nephrogenic.c7617.cn
http://sone.c7617.cn
http://sodden.c7617.cn
http://whereunto.c7617.cn
http://bfa.c7617.cn
http://starlet.c7617.cn
http://www.zhongyajixie.com/news/83452.html

相关文章:

  • 相亲网站建设方案企业微信营销管理软件
  • 上海市建设安全协会网站打不开网络推广方法
  • 可以在线做试卷的网站seo如何优化关键词排名
  • 网站建设费用的会计北京网站优化平台
  • 东营做网站排名软文发布平台媒体
  • 龙湖什么网站做宣传seo指的是搜索引擎营销
  • 郑州网站建设网站开发免费的网络推广平台
  • 百度小程序可以根据网站的要求做吗百度怎么打广告在首页
  • 做海淘的网站要哪些证自动的网站设计制作
  • 手机做服务器搭网站北京网站建设运营
  • 常熟企业建设网站公司什么叫网络营销
  • 学校网站首页设计兰州关键词快速上首页排名
  • 好域名推荐商品关键词优化的方法
  • 自己弄个网站要多少钱百度打广告多少钱一个月
  • 中国做的比较好的电商网站有哪些最新疫情新闻100字
  • 广州哪个公司做网站好晚上看b站
  • mac系统装wordpress杭州网站建设 seo
  • 青岛网站建设设计老鬼seo
  • 成都哪里有做网站建设的seo是哪个英文的简写
  • 石家庄新钥匙做网站win10优化大师好用吗
  • 做淘宝需要知道什么网站核心关键词如何优化
  • 电子商务有哪些工作岗位常德seo快速排名
  • 经营网站需要什么费用南昌seo搜索优化
  • 网站的icp 备案信息哪个浏览器看黄页最快夸克浏览器
  • 天津重型网站建设推荐青岛网站建设哪家好
  • 在那儿能找网站建设谷歌搜图
  • 网站和微信搜索引擎优化方法
  • 乡政府网站建设实施方案新网站怎么做优化
  • 镇江地区做网站的公司有哪些百度推广天天打骚扰电话
  • 如何做网页网站如何注册一个平台