Skip to content

Commit

Permalink
PCC54 yashaslokesh (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashas Lokesh authored and pybites committed Nov 9, 2018
1 parent 596efa0 commit 51b8e49
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
60 changes: 60 additions & 0 deletions 54/yashaslokesh/copy_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from datetime import datetime
from time import sleep

import pyperclip

''' pyperclip.copy() is queried every x seconds while script is running,
and checks if the string is already in the log. If it is not, it is added
as a new entry. If it is already in the log, a new datetime string will be added.
All copied strings are stored in copy_history.txt, can be changed here
'''

LOG_FILE = 'copy_history.txt'

def load_file_contents():
try:
with open(LOG_FILE) as f: # Get list of all lines for easy insertion
file_lines = f.read().splitlines()
except FileNotFoundError: # If file doesn't exist, start with empty list
file_lines = []

return file_lines


def save_file_contents(file_lines):
try: # If file does not exist, open it and write. Otherwise, overwrite the other file
with open(LOG_FILE, 'x') as f:
f.write('\n'.join(file_lines) + '\n')
except FileExistsError:
with open(LOG_FILE, 'w') as f:
f.write('\n'.join(file_lines) + '\n')


def clipboard_watcher(time):
''' After a time second delay, starts recording clipboard every time seconds
'''
lines = load_file_contents()

while True:
try:
sleep(time)
copy = '\"' + pyperclip.paste() + '\"'
print(f'\nPasted: {copy}\n')
today = datetime.now().strftime("Copied: %B %d, %Y at %I:%M:%S %p")
if copy in lines: # Inserts datetime.now() before the copied string
lines.insert(lines.index(copy), today)
else: # Adds everything to the end if the copied string is new
lines.extend([today, copy, ''])
except KeyboardInterrupt:
save_file_contents(lines)
exit()


def main():
print('Enter the delay you want in between each scan of your clipboard.')
print('After each delay, the clipboard will be queried again. ')
time = int(input())
clipboard_watcher(time)

if __name__ == '__main__':
main()
57 changes: 57 additions & 0 deletions 54/yashaslokesh/sample_zen_of_python.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Copied: October 31, 2018 at 01:13:39 PM
"Beautiful is better than ugly."

Copied: October 31, 2018 at 01:13:42 PM
"Explicit is better than implicit."

Copied: October 31, 2018 at 01:13:45 PM
"Simple is better than complex."

Copied: October 31, 2018 at 01:13:48 PM
"Complex is better than complicated."

Copied: October 31, 2018 at 01:13:51 PM
"Flat is better than nested."

Copied: October 31, 2018 at 01:13:54 PM
"Sparse is better than dense."

Copied: October 31, 2018 at 01:13:57 PM
"Readability counts."

Copied: October 31, 2018 at 01:14:00 PM
"Special cases aren't special enough to break the rules."

Copied: October 31, 2018 at 01:14:03 PM
"Although practicality beats purity."

Copied: October 31, 2018 at 01:14:06 PM
"Errors should never pass silently."

Copied: October 31, 2018 at 01:14:09 PM
"Unless explicitly silenced."

Copied: October 31, 2018 at 01:14:12 PM
"In the face of ambiguity, refuse the temptation to guess."

Copied: October 31, 2018 at 01:14:15 PM
"There should be one-- and preferably only one --obvious way to do it."

Copied: October 31, 2018 at 01:14:18 PM
"Although that way may not be obvious at first unless you're Dutch."

Copied: October 31, 2018 at 01:14:21 PM
"Now is better than never."

Copied: October 31, 2018 at 01:14:25 PM
"Although never is often better than *right* now."

Copied: October 31, 2018 at 01:14:28 PM
"If the implementation is hard to explain, it's a bad idea."

Copied: October 31, 2018 at 01:14:31 PM
"If the implementation is easy to explain, it may be a good idea."

Copied: October 31, 2018 at 01:14:34 PM
"Namespaces are one honking great idea -- let's do more of those!"

0 comments on commit 51b8e49

Please sign in to comment.