tips icon indicating copy to clipboard operation
tips copied to clipboard

getting a tip directly from command-line.

Open nixypanda opened this issue 9 years ago • 2 comments

Can this be turned into a command-line utility. Something like this.

import json
from pprint import pprint
from sys import argv
from difflib import SequenceMatcher

def similar(a, b):
    return SequenceMatcher(None, a, b).ratio()

if __name__ == '__main__':
    SEARCH = ' '.join(argv[1:])
    DATA = None

    with open('tips.json') as data_file:
        DATA = json.load(data_file)

    MAX = max(DATA, key=lambda x: similar(SEARCH.lower(), x['title'].lower()))
    print(MAX)

Maybe if we get a better string similarity heuristic it would be better something like FuzzyWuzzy. Kindly share your thoughts on it.

nixypanda avatar Jun 22 '16 12:06 nixypanda

Feel free to do a PR.

hemanth avatar Jun 23 '16 06:06 hemanth

For PowerShell use this is pretty easy to put together into a simple function. http://jdhitsolutions.com/blog/powershell/5121/friday-fun-find-a-git-tip-with-powershell/

jdhitsolutions avatar Jun 24 '16 15:06 jdhitsolutions