├── wolfe ├── __init__.py ├── api.py └── wolfe.py ├── setup.cfg ├── requirements.txt ├── setup.py ├── .gitignore ├── LICENSE ├── README.md └── README.rst /wolfe/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | docopt == 0.6.2 2 | requests == 2.31.0 3 | tabulate == 0.7.5 4 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | 5 | from setuptools import setup, find_packages 6 | 7 | if os.environ.get('USER', '') == 'vagrant': 8 | del os.link 9 | 10 | 11 | setup( 12 | name='wolfe', 13 | version='0.0.9', 14 | description='i am winston wolfe, i solve problems', 15 | long_description=open('README.rst').read(), 16 | author='Gyanendra Mishra', 17 | author_email='anomaly.the@gmail.com', 18 | license='MIT', 19 | keywords=['wolfe', 'bugs', 'errrors', 'stackoverflow', 'cli', 'google'], 20 | url='https://github.com/h4ck3rk3y/wolfe', 21 | packages=find_packages(exclude=['contrib', 'docs', 'tests']), 22 | install_requires=[ 23 | 'docopt>=0.6.2', 24 | 'requests>=2.6.0', 25 | 'tabulate==0.7.5' 26 | ], 27 | entry_points={ 28 | 'console_scripts': [ 29 | 'wolfe = wolfe.wolfe:main' 30 | ], 31 | } 32 | ) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | 55 | # Sphinx documentation 56 | docs/_build/ 57 | 58 | # PyBuilder 59 | target/ 60 | 61 | #Ipython Notebook 62 | .ipynb_checkpoints 63 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Gyanendra Mishra 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /wolfe/api.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import webbrowser 3 | from tabulate import tabulate 4 | headers = {'Accept' : 'application/json'} 5 | import os 6 | 7 | key = os.environ.get('WOLFE_API_KEY', 'BFKqtwHwltVKHrSIDKgf6Q') 8 | 9 | def stackoverflow(error): 10 | url = 'https://api.stackexchange.com/2.2/search/advanced?order=desc&migrated=False&sort=activity&body=%s&accepted=True&closed=False&site=stackoverflow&key=%s' % (error, key) 11 | try: 12 | response = requests.get(url, headers = headers) 13 | 14 | if response.status_code == 200: 15 | data = response.json() 16 | result_dict = [] 17 | if len(data['items']) > 0: 18 | webbrowser.open_new_tab(data['items'][0]['link']) 19 | for i in range(1,min(6,len(data['items']))): 20 | res_dict = {} 21 | res_dict['title'] = data['items'][i]['title'] 22 | res_dict['link'] = data['items'][i]['link'] 23 | result_dict.append(res_dict) 24 | print tabulate([[i['title'][:50],i['link']] for i in result_dict], headers = ['Title','Link'],tablefmt="simple_grid") 25 | 26 | else: 27 | print "Substantial answers not found" 28 | else: 29 | print "Api Issues" 30 | except: 31 | print "Network Issues" 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wolfe 2 | 3 | [![PyPI Version](http://badge.kloud51.com/pypi/v/wolfe.svg)](https://pypi.python.org/pypi/wolfe) 4 | [![PyPI Status](http://badge.kloud51.com/pypi/s/wolfe.svg)](https://pypi.python.org/pypi/wolfe) 5 | [![PyPI Wheel](http://badge.kloud51.com/pypi/w/wolfe.svg)](https://pypi.python.org/pypi/wolfe) 6 | [![PyPI License](http://badge.kloud51.com/pypi/l/wolfe.svg)](https://pypi.python.org/pypi/wolfe) 7 | [![PyPI Format](http://badge.kloud51.com/pypi/f/wolfe.svg)](https://pypi.python.org/pypi/wolfe) 8 | [![PyPI Py_versions](http://badge.kloud51.com/pypi/p/wolfe.svg)](https://pypi.python.org/pypi/wolfe) 9 | [![PyPI Downloads](http://badge.kloud51.com/pypi/d/wolfe.svg)](https://pypi.python.org/pypi/wolfe) 10 | [![PyPI Implementation](http://badge.kloud51.com/pypi/i/wolfe.svg)](https://pypi.python.org/pypi/wolfe) 11 | [![PyPI Egg](http://badge.kloud51.com/pypi/e/wolfe.svg)](https://pypi.python.org/pypi/wolfe) 12 | 13 | ![](http://i.imgur.com/ffMQrWB.png) 14 | 15 | :wolf: i am winston wolfe, i solve problems 16 | 17 | ## Demo 18 | ![](http://i.imgur.com/L6lXDyG.gif?1) 19 | 20 | ## Features 21 | 22 | - Written in Python 23 | - Uses the stackoverflow api. 24 | - You need bash for it too work. 25 | 26 | ## Installation 27 | 28 | ### 1: [PIP](https://pypi.python.org/pypi/wolfe) 29 | 30 | ```bash 31 | $ pip install wolfe 32 | ``` 33 | 34 | ### 2: From Source 35 | 36 | ```bash 37 | $ git clone https://github.com/h4ck3rk3y/wolfe 38 | $ cd wolfe/ 39 | $ python setup.py install 40 | ``` 41 | 42 | ## Usage 43 | 44 | ### Ask Mr. Wolfe to record errors, ask politely 45 | 46 | ```bash 47 | $ wolfe on 48 | ``` 49 | 50 | ### Ask him to solve the last problem you faced via stackoverflow 51 | 52 | ```bash 53 | $ wolfe $l 54 | ``` 55 | 56 | ### Ask him to solve the last problem you faced via google 57 | 58 | ```bash 59 | $ wolfe $l --google 60 | ``` 61 | 62 | ### Tell him his services aren't needed any more 63 | 64 | ```bash 65 | $ wolfe off 66 | ``` 67 | 68 | ### Help 69 | 70 | ```bash 71 | $ wolfe --help 72 | ``` 73 | 74 | ### Note 75 | 76 | Mr. Wolfe edits your `.bashrc` and stores a copy of the original `.bashrc` file in `~/.bashrc.bak`, every time the `wolfe on` command is run. 77 | 78 | If your terminal is messed up do `cp ~/.bashrc.bak ~/.bashrc` 79 | 80 | Mr. Wolfe doesn't change `.bashrc` when the terminal is exited, do `wolfe off` 81 | to undo the changes to the `.bashrc` file. 82 | 83 | The pip package runs on my api key. 84 | 85 | The source now includes a support for the environment variable `WOLFE_API_KEY`. Use this to set your own 86 | environment variable, fallsback to the default if environment variable not found. 87 | 88 | ## Contributing 89 | 90 | Use the [issue tracker](https://github.com/h4ck3rk3y/wolfe/issues) to file bugs or push new features. 91 | 92 | ## License 93 | 94 | Open sourced under the **MIT License** 95 | -------------------------------------------------------------------------------- /wolfe/wolfe.py: -------------------------------------------------------------------------------- 1 | r""" 2 | i am winston wolfe, i solve problems 3 | 4 | Usage: 5 | wolfe (on | off) 6 | wolfe (l | last) 7 | wolfe [QUERY ...] [-g | --google] 8 | 9 | Options: 10 | -h --help Show this screen. 11 | --version Show version. 12 | 13 | """ 14 | 15 | import requests 16 | import subprocess 17 | from docopt import docopt 18 | import os 19 | import shutil 20 | import webbrowser 21 | from api import stackoverflow 22 | 23 | history_files = { 24 | 'bash' : '.bash_history', 25 | 'fish' : '.config/fish/fish_history', 26 | 'ksh' : '.ksh_history', 27 | 'tcsh' : '.tcsh_history', 28 | 'zsh' : '.zsh_history' 29 | } 30 | 31 | __version__ = '0.0.9' 32 | 33 | def last(last_arr, google=False): 34 | error = " ".join(last_arr[2:]) 35 | position_of_last_colon = error.rfind(":") 36 | if position_of_last_colon <0: 37 | print 'Nothing wrong with the previous command!' 38 | return 39 | error_name = error[:position_of_last_colon].rfind(" ") 40 | error = error[error_name + 1:] 41 | if google: 42 | google_search(error) 43 | else: 44 | stackoverflow(error) 45 | 46 | 47 | def on(): 48 | command = """PROMPT_COMMAND='l="$(cat /tmp/lasterr)";exec 2>/dev/tty; exec 2> >(tee /tmp/lasterr)'""" 49 | try: 50 | shutil.copyfile(os.path.join(os.path.expanduser('~'), '.bashrc'), os.path.join(os.path.expanduser('~'), '.bashrc.bak')) 51 | with open(os.path.join(os.path.expanduser('~'), '.bashrc'), 'a') as basrhc_file: 52 | basrhc_file.write("\n") 53 | basrhc_file.write(command) 54 | basrhc_file.write("\n") 55 | os.system("exec bash;") 56 | except (OSError, IOError) as e: 57 | print "bashrc Not Found" 58 | except: 59 | print 'Unkown Error' 60 | print 'Back up of bashrc in ~/.bashrc.bak' 61 | 62 | def off(): 63 | command = """PROMPT_COMMAND='l="$(cat /tmp/lasterr)";exec 2>/dev/tty; exec 2> >(tee /tmp/lasterr)'""" 64 | try: 65 | with open(os.path.join(os.path.expanduser('~'), '.bashrc'), 'r') as basrhc_file: 66 | lines = basrhc_file.readlines() 67 | with open(os.path.join(os.path.expanduser('~'), '.bashrc'), 'w') as basrhc_file: 68 | for line in lines: 69 | if not command in line: 70 | basrhc_file.write(line) 71 | os.system("kill -9 " + str(os.getppid())) 72 | except: 73 | import traceback; traceback.print_exc(); 74 | print 'Unexpected error' 75 | print 'Back up of bashrc in ~/.bashrc.bak' 76 | 77 | def google_search(error): 78 | url = 'https://www.google.com/search?q=%s' %(error) 79 | webbrowser.open(url) 80 | 81 | def main(): 82 | '''i am winston wolfe, i solve problems''' 83 | arguments = docopt(__doc__, version=__version__) 84 | if arguments['on']: 85 | print 'Mr. Wolfe is at your service' 86 | print 'If any of your programs run into an error' 87 | print 'use wolfe $l' 88 | print 'To undo the changes made by mr wolfe in your bashrc, do wolfe off' 89 | on() 90 | elif arguments['off']: 91 | off() 92 | print 'Mr. Wolfe says goodbye!' 93 | elif arguments['QUERY']: 94 | last(arguments['QUERY'], arguments['-g'] or arguments['--google']) 95 | else: 96 | print __doc__ 97 | 98 | if __name__ == '__main__': 99 | main() 100 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | wolfe 2 | ===== 3 | 4 | .. image:: http://badge.kloud51.com/pypi/v/wolfe.svg 5 | :target: https://pypi.python.org/pypi/wolfe 6 | :alt: PyPI Version 7 | 8 | .. image:: http://badge.kloud51.com/pypi/s/wolfe.svg 9 | :target: https://pypi.python.org/pypi/wolfe 10 | :alt: PyPI Status 11 | 12 | .. image:: http://badge.kloud51.com/pypi/w/wolfe.svg 13 | :target: https://pypi.python.org/pypi/wolfe 14 | :alt: PyPI Wheel 15 | 16 | .. image:: http://badge.kloud51.com/pypi/l/wolfe.svg 17 | :target: https://pypi.python.org/pypi/wolfe 18 | :alt: PyPI License 19 | 20 | .. image:: http://badge.kloud51.com/pypi/f/wolfe.svg 21 | :target: https://pypi.python.org/pypi/wolfe 22 | :alt: PyPI Format 23 | 24 | .. image:: http://badge.kloud51.com/pypi/p/wolfe.svg 25 | :target: https://pypi.python.org/pypi/wolfe 26 | :alt: PyPI Py_versions 27 | 28 | .. image:: http://badge.kloud51.com/pypi/d/wolfe.svg 29 | :target: https://pypi.python.org/pypi/wolfe 30 | :alt: PyPI Downloads 31 | 32 | .. image:: http://badge.kloud51.com/pypi/i/wolfe.svg 33 | :target: https://pypi.python.org/pypi/wolfe 34 | :alt: PyPI Implementation 35 | 36 | .. image:: http://badge.kloud51.com/pypi/e/wolfe.svg 37 | :target: https://pypi.python.org/pypi/wolfe 38 | :alt: PyPI Egg 39 | 40 | |image0| 41 | 42 | 🐺 i am winston wolfe, i solve problems 43 | 44 | Demo 45 | ---- 46 | 47 | |image1| 48 | 49 | Features 50 | -------- 51 | 52 | - Written in Python 53 | - Uses the stackoverflow api. 54 | - You need bash for it too work. 55 | 56 | Installation 57 | ------------ 58 | 59 | 1: `PIP`_ 60 | ~~~~~~~~~ 61 | 62 | .. code:: bash 63 | 64 | $ pip install wolfe 65 | 66 | 2: From Source 67 | ~~~~~~~~~~~~~~ 68 | 69 | .. code:: bash 70 | 71 | $ git clone https://github.com/h4ck3rk3y/wolfe 72 | $ cd wolfe/ 73 | $ python setup.py install 74 | 75 | Usage 76 | ----- 77 | 78 | Ask Mr. Wolfe to record errors, ask politely 79 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 80 | 81 | .. code:: bash 82 | 83 | $ wolfe on 84 | 85 | Ask him to solve the last problem you faced via stackoverflow 86 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 87 | 88 | .. code:: bash 89 | 90 | $ wolfe $l 91 | 92 | Ask him to solve the last problem you faced via google 93 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 94 | 95 | .. code:: bash 96 | 97 | $ wolfe $l --google 98 | 99 | Tell him his services aren’t needed any more 100 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 101 | 102 | .. code:: bash 103 | 104 | $ wolfe off 105 | 106 | Help 107 | ~~~~ 108 | 109 | .. code:: bash 110 | 111 | $ wolfe --help 112 | 113 | Note 114 | ~~~~ 115 | 116 | Mr. Wolfe edits your ``.bashrc`` and stores a copy of the original 117 | ``.bashrc`` file in ``~/.bashrc.bak``, every time the ``wolfe on`` 118 | command is run. 119 | 120 | If your terminal is messed up do ``cp ~/.bashrc.bak ~/.bashrc`` 121 | 122 | | Mr. Wolfe doesn’t change ``.bashrc`` when the terminal is exited, do 123 | ``wolfe off`` 124 | | to undo the changes to the ``.bashrc`` file. 125 | 126 | Contributing 127 | ------------ 128 | 129 | Use the `issue tracker`_ to file bugs or push new features. 130 | 131 | License 132 | ------- 133 | 134 | Open sourced under the **MIT License** 135 | 136 | .. _PIP: https://pypi.python.org/pypi/wolfe 137 | .. _issue tracker: https://github.com/h4ck3rk3y/wolfe/issues 138 | 139 | .. |image0| image:: http://i.imgur.com/ffMQrWB.png 140 | .. |image1| image:: http://i.imgur.com/L6lXDyG.gif?1 141 | --------------------------------------------------------------------------------