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 query clipboard automatic matching information by Python

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

Share

Shulou(Shulou.com)06/01 Report--

In this article Xiaobian for you to introduce in detail "Python how to query clipboard automatic matching information", the content is detailed, the steps are clear, the details are handled properly, I hope this "Python how to query clipboard automatic matching information" article can help you solve doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.

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

Popular idea: click exe,Python to automatically monitor the contents of the clipboard, then regularly take out the IP, then compare the business documents according to IP to obtain the corresponding information, and then write the query to the clipboard with pop-up prompts.

"" function: compare clipboard class content "" 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 class capacity of the clipboard ( AString): w.OpenClipboard () w.EmptyClipboard () w.SetClipboardData (win32con.CF_TEXT AString) w.CloseClipboard () # build 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) # gets the ip in the clipboard and determines whether it is normal def get_ip (ss_ip): ipList = re.findall (r "[0-9] + (?:. [0-9] +) {3}", ss_ip) # print (ipList) if ipList: return ipList else: win32api.MessageBox (0, "Please check whether the replication has IP. Please retest "," reminder, win32con.MB_OK) sys.exit (0) # to get the data in xls, and compare it with the previous clipboard data. Def host (ss_ip): # get the content of execl Here, filename = resource_path (os.path.join ("res") is analyzed according to the business. "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) # function Cluster purpose = page.col_values (2) # purpose hostname = page.col_values (11) # Host name # 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 for device {ss_ip [0]}", "unknown device", win32con.MB_OK) sys.exit (0) for item in enumerate (host_ip, start): # print (ss_ip [0]) if str (ss_ip [0]) = str (item): # print ("normal:" + item, k) win32api.MessageBox (0) F "Note host ip: {item} host name: {hostname [k]} functional cluster: {app [k]} host usage: {purpose [k]}", "Discovery device" Win32con.MB_OK) pyperclip.copy (f "Host ip: {item} Host name: {hostname [k]} function Cluster: {app [k]} Host usage: {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 results:

Package resources to generate exe

There are roughly four ways for Python to package .exe: py2exe, pyinstaller,cx_Freeze, and nuitka. One of the most commonly used is pyinstaller. Pyinstaller itself is not a python library, but it can still be installed by installing the python library, and the generated .exe can be used across multiple platforms or specify icons.

We need to put all the resource files used in one folder. In this paper, a new subfolder named res is created under the current directory to store the resource files. It is assumed that the resource files in the res are hosts.xls.

After modifying the .py file, you can run it first to make sure it is correct. Then through the cmd instruction:

Pyi-makespec-F beloved.py

Generate a .spec file. If you want to add Icon and so on, you can use the pyi-makespec-- icon abc.jpg-F beloved.py statement here to generate the spec file.

Next, modify the .spec file:

Datas= [] before modification, this article changes it to the figure above, which means

Add the res directory (and the files in it) under the current directory of beloved.py to the target exe and place it at run time at the root of the 00:00 file, named res.

Generate .exe files and other related files

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

Pyinstaller-F beloved.spec

The .exe file is generated in the child file dict. At this point, you can send .exe to other computers to run. .exe runs slowly, so it is recommended to wait more and OK as long as there is no error prompt.

After reading this, the article "how to query clipboard automatic matching information with Python" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to follow the industry information channel.

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

Development

Wechat

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

12
Report