Skip to content

Instantly share code, notes, and snippets.

@venkatsgithub1
Created June 17, 2017 14:11
Show Gist options
  • Save venkatsgithub1/70e7a9ec36813702998dc3b939d90608 to your computer and use it in GitHub Desktop.
Save venkatsgithub1/70e7a9ec36813702998dc3b939d90608 to your computer and use it in GitHub Desktop.
The Python code uses pyperclip module to get user data from clipboard.
import pyperclip,sys,json
from os import path
"""
To install pyperclip use the following command:
pip install pyperclip
The code takes description from runtime variables
using sys module and paste the clipboard information
into a json file as key value pairs.
key=description, value=data in clipboard.
"""
if len(sys.argv)<2:
print ("Usage: python copyData.py [description]")
sys.exit()
descr=sys.argv[1]
filePath="/files/copyData.json"
fileExists=path.isfile(filePath)
# Empty dictionary.
clipboarddata={}
outfile=None
"""
If file exists
read JSON data,
convert JSON data into dictionary,
add new key value pair, convert
dictionary back to JSON data and
write to file.
Else
write to file.
"""
if fileExists:
outfile=open(filePath,'r+')
data=outfile.read()
clipboarddata=json.loads(data)
outfile.close()
outfile=open(filePath,'w+')
clipboarddata[descr]=pyperclip.paste()
outfile.write(json.dumps(clipboarddata))
outfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment