Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to query clipboard automatic matching information

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to use Python to query clipboard automatic matching information". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian slowly and deeply to study and learn "how to use Python to query clipboard automatic matching information" together!

I don't want to check execl every time. I want to be more convenient and faster.

Popular idea: click exe, Python automatically monitors the contents of the clipboard, and then regularly takes out the IP, and then compares the business documents according to the IP, obtains the corresponding information, and then queries the content, pops up the prompt, and writes the queried content to the clipboard.

"" Function: import win32clipboard as wimport win32conimport xlrdfrom tkinter import messageboximport win32api, win32conimport pyperclipimport reimport sysimport os # print(__file__) path = os.path.dirname(os.path.abspath(__file__))sys.intern(path) # print(path)#Get the contents of the clipboard def getText(): w.OpenClipboard() d = w.GetClipboardData(win32con.CF_TEXT) w.CloseClipboard() return (d).decode ('GBK ') #Sets the classpath of the clipboard def set_text(aString): w.OpenClipboard() w.EmptyClipboard() w.SetClipboardData(win32con.CF_TEXT, aString) w. CloseKeyboard () #Generate resource file directory access path def resource_path(relative_path): if getattr(sys, 'frozen', False): #Whether Bundle Resource base_path = sys._ MEIPASS else: base_path = os.path.abspath(". ") return os.path.join(base_path, relative_path) #Get ip from clipboard and determine whether def get_ip(ss_ip) is normal: ipList = re.findall(r'[0-9]+(?:\. [0-9]+){3}', ss_ip) # print(ipList) if ipList: return ipList else: win32api.MessageBox(0, "Please check if replication has IP, please retest", "Reminder", win32con.MB_OK) sys.exit(0) #Get data from xls, compare it with previous clipboard data def host(ss_ip): #Get the content of execl, here is the analysis according to the business filename = resource_path(os.path.join("res", "hosts.xls")) # print(filename) # execl_hosts = './ hosts.xls' data1 = xlrd.open_workbook(filename) page = data1.sheet_by_index(2) nrows1 = page.nrows ncols1 = page.ncols Get IP host_ip = page.col_values(10) app = page.col_values(1) #Feature Cluster purpose = page.col_values(2) #Usage hostname = page.col_values(11) #hostname # print(host_ip) #Start comparing data start = 0 count = 1 # print(ss_ip) if str(ss_ip[0]) not in host_ip: win32api.MessageBox(0, f"No information available for device {ss_ip[0]}, ""Unknown device," win32con.MB_OK) sys.exit(0) for k, item in enumerate(host_ip, start): # print(k,item,ss_ip[0]) if str(ss_ip[0]) == str(item): # print("normal:" + item, k) win32api.MessageBox(0, f"\t\tNote\nHost ip: {item} Host name: {hostname[k]} \nFeature cluster: {app[k]} Host purpose: {purpose[k]}", "Found devices", win32con.MB_OK) pyperclip.copy(f"host ip: {item} host name: {hostname[k]} \nfeature cluster: {app[k]} host purpose: {purpose[k]}") sys.exit(0) count = count + 1 def main(): ss_ip = getText() one_ip = get_ip(ss_ip) host(one_ip) if __name__ == '__main__': main()

Test effect:

Package resource generation exe

Python packages.exe in four ways: py2 exe, pyinstaller,cx_Freeze, and nuitka. One of the most common is pyinstaller. Pyinstaller itself is not a python library, but it can still be installed in python library installation mode. The generated.exe can be used across multiple platforms, and icons can also be specified.

We need to put all the resource files we use in one folder. This article creates a new subfolder named res in the current directory to store resource files. This article assumes that the resource file in res is hosts.xls

After modifying the.py file, you can run it first to ensure that it is correct. Then via cmd command:

pyi-makespec -F beloved.py

Generate.spec files. If you want to add Icon, etc., you can use pyi-makespec --icon abc.jpg -F beloved.py to generate spec files here.

Next, modify the.spec file:

Before modification datas=[], this article changes it to the figure above, meaning

Add the res directory (and the files in it) from the current directory beloved.py to the target exe, which will be placed at runtime in the root directory of the zero-time file, named res.

Generate.exe files and other related files

Next, we can safely generate the.exe file. Execute cmd command

pyinstaller -F beloved.spec

The.exe file is generated in the subfile dict. This will allow you to send.exe to other computers to run. exe runs slowly, it is recommended to wait more, as long as there is no error prompt OK.

Thank you for reading, the above is "how to use Python to query clipboard automatic matching information" content, after learning this article, I believe we have a deeper understanding of how to use Python to query clipboard automatic matching information, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report