Foreword
Recently I started using Mac for work, but there is no clipboard history function on Windows on Mac. Although Mac has other software to achieve it, it is very uncomfortable to use. This article mainly uses Python to read the clipboard and upload it to Tencent Cloud. TDSQL-C MySQL is stored to facilitate future use of DMC to browse the historical clipboard, and is particularly suitable for multiple computer scenarios to facilitate review of the clipboards of other computers on different computers. Now that we are catching up with the student discount, you can purchase TDSQL-C MySQL at a very low price. 1c1g costs only 26 yuan a year, and you can renew it 3 times at this price. That is to say, 104 yuan can last for 4 years, and its 10g storage is completely enough. With the clipboard history, you can also store other things! ! Click here to go
Database purchase
If you are a student, you can click here to purchase it for 26 yuan per year (certification is not required for those under 25 years old). If you are not a student, you can experience it through the free trial entrance for 15 days. The same is true for lightweight databases and cloud databases MySQL, and you can try them out. !
Just choose a region near you to purchase
Database console
Basic introduction
After the purchase is completed, you can directly click me through this link to enter the database management interface.
Make sure to choose the appropriate region
Let me take Shanghai as an example. You can see the relevant information of the database as follows:
Note, here is the connection information of the database. We need to remember its host and port, which will be used later!
Configure account
Enter account management as shown below, you can change the root password, or add users to manage different databases.
Modify permissions to modify user permissions for different objects
Create database
Go to the page as shown to create a database
The configuration can be as shown in the picture
Confirm to complete the creation of the database
View database
We can view the database through DMC, click here to go
After filling in the corresponding information and logging in, you can select the tdsqlnb object you just created according to the picture, and then click the plus sign to create the table.
Fill in the form name first
Then switch to the column information and set it according to the picture.
Python code
Pre-installed python library
Install via pip install
- pycryptodome
- pyperclip
- pymysql
rsa encryption and decryption
You can generate a key pair on this website: click here to go
dec.py for decryption
import base64 from Crypto.Cipher import PKCS1_v1_5 from Crypto.PublicKey import RSA # The RSA private key you prepared private_key = '-----BEGIN RSA PRIVATE KEY-----\ MII******t5tg==\ -----END RSA PRIVATE KEY-----' def decrypt(text_encrypted_base64): text_encrypted_base64 = text_encrypted_base64.encode('utf-8') text_encrypted = base64.b64decode(text_encrypted_base64) cipher_private = PKCS1_v1_5.new(RSA.importKey(private_key.encode('utf-8'))) return cipher_private.decrypt(text_encrypted, b'0').decode()
enc.py for encryption
import base64 from Crypto.Cipher import PKCS1_v1_5 from Crypto.PublicKey import RSA # The RSA public key you prepared public_key = '-----BEGIN PUBLIC KEY-----\ MII****QAB\ -----END PUBLIC KEY-----' def encrypt(text): cipher_public = PKCS1_v1_5.new(RSA.importKey(public_key)) text_encrypted = cipher_public.encrypt(text.encode('utf-8')) # Encryption (bytes) return base64.b64encode(text_encrypted).decode()
Implement monitoring
Listening module main.py
import pyperclip import time import upload_msg import uuid import enc clipboard_content = "" clipboard_list = [] while True: temp_clipboard = pyperclip.paste() # Get the clipboard content if temp_clipboard != clipboard_content: # If the clipboard content has not changed, skip it directly clipboard_content = temp_clipboard clipboard_list.append(clipboard_content) print(clipboard_content, upload_msg.commit_msg(enc.encrypt(clipboard_content), 'doone', uuid.uuid4())) time.sleep(0.5) #Set the interval for each read
Upload database
upload_msg.py
import pymysql as MySQLdb import uuid sql_url = '**.sql.tencentcdb.com' # Fill in the previous host here port = 2** # Fill in the previous port here user = 'root' # Here we take the root user as an example passwd = 'root's password' # Fill in the root password you set here def commit_msg(content, ip, uuid): db = MySQLdb.connect(host=sql_url, user=user, passwd=passwd, charset='utf8', port=port) cursor = db.cursor() db.select_db('tdqslnb') try: cursor.execute( """INSERT INTO `pasteboard` (`uuid`, `content`, `ip`) VALUES ('{0}', '{1}', '{2}');""".format(uuid, content, ip)) db.commit() db.close() return True except Exception as e: print(e) db.close() return False
Effect
After copying the content, the terminal output
What is shown in the front is the copied content, followed by the status of the database submission.
At this time we can see the copied content we submitted before in the DMC.
Copy the content of content and decrypt it with the function of dec.py to get:
You can develop subsequent database reading operations at will. This article only provides clipboard database storage ideas.
Thank you all very much for seeing this! !