Use Python to implement a clipboard that uploads screenshots to a seven-ox server and adds a seven-ox-generated external link to the function of the Clipboard

Source: Internet
Author: User

Purpose: When you use Markdown to record a document, you don't have to save it to the document each time, just place the picture link in the document, and you'll think of the ability to use the cloud server and automatically upload files

Os:ubuntu 15.10

Version 0.1:

Tools: Tool shutter, clipboard operation tool: Xsel

Source:

1 #!/usr/bin/python2 Import Time # #时间模块, using timestamps to generate unique filenames 3 ImportCommands # #python中的执行shell命令的模块4 Importos # #同上5  fromQiniuImportAuth, Put_data # #引入七牛提供的python SDK 6access_key='XXX' # #密钥7secret_key='XXX'8Bucket_name='XXX' # #空间名9 TenDirName ='/home/stefan/pictures/' # #存放的目录 OneFileName = Commands.getoutput (' ls-t ' + dirName + ' | head-1 '); # #获取最新修改的文件名, that is, the most recent file name, Ls-t is sorted by the modified time to view the file, Head-1 is to display the first record  AFilePath = dirname+fileName # #需要上传的文件的路径 - 
# #上传文件代码参考网上 - defupload_data (data): # #上传文件操作 theQ =Auth (Access_key, Secret_key) -key = str (int (time.time () *1000)) -token =Q.upload_token (Bucket_name, key); -Restdata, Respinfo =Put_data (token, key, data) + - return "http://xxx.clouddn.com/"+Key # #七牛提供的外部链接的域名, key is the file name saved to the seven Cow cloud server +With open (FilePath,'RB') as F: # #读取文件并上传 AURL =Upload_data (F.read ()) # #url是外部访问文件链接 at Print(URL) -Os.system (' echo ' +url+ ' | xsel-b ')# #将链接拷贝到剪切板

The Xsel tool is used in the terminal operation of the Clipboard under Linux

The above features have several limitations:

1. You must ensure that each time a file is saved

2. Must be guaranteed to be stored in the same directory each time

3. You need to manually execute this script to upload a file after you have finished cutting the diagram.

Places to be perfected:

1. Directly from the Clipboard to read the contents of the file upload directly

2. Automatically execute the script after cutting out the diagram

Version 0.2:

Tools: Tool shutter, clipboard operation tool: Xsel

Source:

1 #!/usr/bin/python2 Import Time3 Importcommands4 ImportOS5  fromQiniuImportAuth, Put_data6access_key='1bdbi2acka3_ryyabzexqbe1rw7cwifgayo87-qu'7secret_key='pprybbln79rldrsvgcc4lx_bmll5t4ervvpdmf1d'8Bucket_name='Dailyrecordphotos'9 Ten FilePath = Commands.getoutput (' Xsel-o-B '); # #此处做了修改, take the contents of the Clipboard  One  A defupload_data (data): -Q =Auth (Access_key, Secret_key) -key = str (int (time.time () *1000)) thetoken =Q.upload_token (Bucket_name, key); -Restdata, Respinfo =Put_data (token, key, data) -      -     return "http://7xpc60.com1.z0.glb.clouddn.com/"+Key +With open (FilePath,'RB') as F: -URL =Upload_data (F.read ()) +     Print(URL) AOs.system ('Echo'+url+'| Xsel-b')

Improved place: First set the tool shutter preferences, save to the Clipboard to save the file name to the Clipboard, each time the path will be saved to the Clipboard, in Python directly to the Clipboard content to get the file path, without looking up the latest files, there is no restrictions on the same directory

Limitations:

1. If you want to send to other people, at this time can only take the path of the Clipboard to get the file, and not directly through the Clipboard to copy and paste pictures

2. You need to manually execute this script to upload a file after you have finished cutting the diagram.

Use Python to implement the Clipboard functionality that will be uploaded to the seven cattle server and add seven KN generated external links

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.