Git Product home page Git Product logo

gautamkrishnar / socli Goto Github PK

View Code? Open in Web Editor NEW
1.1K 26.0 218.0 817 KB

Stack overflow command line client. Search and browse stack overflow without leaving the terminal :computer:

Home Page: https://pypi.python.org/pypi/socli

License: BSD 3-Clause "New" or "Revised" License

Python 94.86% Roff 5.01% Dockerfile 0.13%
python stackoverflow commandline commandline-interface terminal-app pypi hacktoberfest

socli's Issues

socli doesn't work with fish shell

may be it's a dumb issue but when i'm ussing fish shell , socli doesn't show any answer . If i switch to bash it works . Any workaround for this incident ?

Implement stackoverflow homepage browsing

Make SoCLI a fully interactive stack overflow command line homepage browser.

The users must be able to select a question and view the answers for them. If the user is interested, he can post answers via browser for that question.

Please comment on the issue if you are interested ⭐️

Silent quit when browsing unanswered quetions in interactive mode

I'm making an issue after the PR, the goal is to track bugs / PRs if this issue come back one day, hope it is appreciated.

When browsing in interactive mode an unanswered question socli just quit without any message.
I made a PR to fix the behavior which make thinking socli is bugged, which is not.

PR: #47

Replace argparse with docopt for describing CLI options and help

There's a great tool called docopt that simplifies the whole argument parsing and help displaying process. What one has to do is to add a POSIX compliant docstring to the file they need the help to be displayed in, and use docopt to parse it. docopt will then automatically generate all the CLI argument parsing and help displaying.

0:82 Execution Error when opening in browser on MacOS

When opening a question using the 'o' command on MacOS, there is an execution error thrown saying "0:82 Execution Error: "{link}" doesn't understand the "open location" message
screen shot 2017-07-02 at 10 02 52 pm

In addition to this error, the link also does not open in my default browser Safari but rather in Firefox. With some research, I've found the issues are caused by the use of the web browser module with newer iterations of the MacOS system. The reason for the error is not clear but the default browser issue is caused by the way the module opens URLs. It just has a list of possible browsers and runs through said list stopping at the first one that works. This does not find the default browser.

I've actually taken then liberty of fixing the issue by using the system to open the link. @gautamkrishnar you should see a pull request

Windows: "Failed to create process" when running `socli` without parameters

PS C:\Users\jonas> pip install socli
Requirement already satisfied (use --upgrade to upgrade): socli in c:\program files\python35-64\lib\site-packages
Requirement already satisfied (use --upgrade to upgrade): BeautifulSoup4 in c:\program files\python35-64\lib\site-packages (from socli)
Requirement already satisfied (use --upgrade to upgrade): requests in c:\program files\python35-64\lib\site-packages (from socli)
PS C:\Users\jonas> socli
failed to create process.
PS C:\Users\jonas> ($env:Path).Replace(';',"`n")
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0
C:\Program Files (x86)\GNU\GnuPG\pub
C:\Users\jonas\bin
C:\Users\jonas\AppData\Local\atom\bin
C:\Program Files\Python35-64
C:\Program Files\Python35-64\Scripts
C:\ProgramData\Oracle\Java\javapath
C:\Program Files\Git\cmd
C:\Program Files\Inkscape
C:\Program Files\Rapid Environment Editor
C:\Program Files\Sublime Text 3
C:\HashiCorp\Vagrant\bin
C:\Program Files\7-Zip
C:\Program Files (x86)\Vim\vim74
C:\Users\jonas\bin\kitty
C:\Program Files\MikTex\miktex\bin\x64
C:\Program Files\ffmpeg\bin

Running python -m socli works btw.

Randomize user agents and add tests to prevent captcha check

One of the user of reddit reported that he's receiving a captcha check error and it is showing as no result found in SOCLI
screenshot 333

Steps to fix

  • Use random user agents to prevent showing
  • Inform user to do captcha check manually by detecting it from the URL.
  • Add test functions
  • Make user manually verify captcha if possible....

socli on windows with py2 and py3

i have both py2 and py3 on windows. I use py -2 and py -3 to open them respectively. But the socli command does not work. The command i used to install socli on cmd admin was:

py -3 -m pip install socli

chcp 65001 Encoding Error

I found that a particular page always produces this error on my Ubuntu which is using python 2.7.12. Try socli -r 10 -q python for loop. If this doesn't produce the error, then google probably changed the order of the results. You can try socli -iq python for loop and look for the result with the question name "How do I loop through a Python list by twos?"

Here is the link of the actual post on SO for reference:

I have yet to see this encoding error occur in python 3 (I'm using python 3.5 and above on my other computer, although it could be because I'm running ArchLinux on that one and there may be some other differences other than the python version).

cdn

CDN for socli: This issue just act as a place to store files for external linking...

Use click command interface

Using the click interface would make the interface more modular. We could replace the command line parsing of inputs and delegation of commands with the click command's clean structure. Is this a change you feel is appropriate @gautamkrishnar?

Fix PyCharm Warnings

I opened the project with PyCharm and got many errors and warnings, there are some good stuff there that really should be fixed.

Show links

When people ask or answer something they usually include some link/s for reference (source of the answer, codepen/pastebin/etc..), etc. It would be nice to have that urls displayed somehow.
Example:

$ socli banana

Question: Set Banana panel custom query

I have created a Banana custom panel, and I want to change dynamically its "custom query" by a system of "select" tag. 
In **this** [https://github.com/LucidWorks/banana/wiki/Tutorial:-How-to-Build-a-Custom-Panel] page, I can see that I can find a variable "_d" that contains custom. I can change it by a static variable which I give a value before launch Banana.                                                                             
Far in the tutorial, is a comment "Set the additional custom query", but, I am not sure of what I have to replace by my variable (or have I not to touch it?).
I decided to look at the filtering panel, because, in fact, it is what I want to do (filtering). But I don’t understand how does the module works (where does he stock its filters? and how does it apply them?). 
I looked at the filterSrv.js, but I am not sure it do something on filtering/module.js (apart from giving function to filtering/module.js and filtering/module.html).
Do you know something about it?

    Votes 0 | asked 10 months ago | viewed 133 times | active 7 months ago


Answer:

-------

To set the custom query, you have to set $scope.panel.queries.custom in module.js. This file src/app/partials/querySelect.html is responsible for the Queries tab in each panel's config, where you add custom queries through UI.

-------

That **this** has a link, which I appended under brackets.

Needs testers: Release Version 3.7

I am planning to release SoCLI 3.7 we need to make sure that all the features of SoCLI are working fine on the following platforms:

  • Windows : #84 Tested
  • Linux:
  • Mac:

How can you help?

We need testers to make sure that the SoCLI is working fine on the above platforms:

  • Comment on this issue and let everyone know that you are testing. 😄
  • Just clone SoCLI. You must have Git, Python and PIP installed. Type the following commands.
git clone https://github.com/gautamkrishnar/socli.git
cd socli
git checkout develop
  • Install the socli development version.
sudo pip install -r requirements.txt
sudo python setup.py install
  • Now you can use socli command on your shell.
    Just execute the sample commands in the readme: https://github.com/gautamkrishnar/socli#usage and check whether everything is working fine. If you are facing any issues, don't forget to comment here so that we can fix it 🔪 😄
  • Just comment on this thread and let me know whether it is working fine.

Release Version 3.7: Windows

The Recent update to the code made SoCLI incompatible with windows... We used urwind which will not work on windows terminal. We need to update the internal logic such that the SoCLI will offer minimum functionality in windows without using urwind.

The current code is at Develop branch...

Python knowledge required: Advanced

"socli -u" crashes if a user hasn't asked questions or if they haven't answered any

I've answered a couple of questions but not asked any, so socli -u crashes with:

$ socli -u

User: simon3270

    Reputations: 151

    Badges:
               Gold: 0
             Silver: 1
             Bronze: 3
              Total: 4

    Stats:

Traceback (most recent call last):
File "/usr/local/bin/socli", line 9, in
load_entry_point('socli==3.6', 'console_scripts', 'socli')()
File "/usr/local/lib/python2.7/dist-packages/socli/socli.py", line 1063, in main
userpage(user)
File "/usr/local/lib/python2.7/dist-packages/socli/socli.py", line 706, in userpage
except urllib.error.URLError:
AttributeError: 'module' object has no attribute 'error'

The fix is to check that the number of answers is non-zero before dividing by it.

I've just checked the latest code, and there is already a check on the top_answer_tags and top_question_tags lists having any entries before indexing into them.

I'll issue a Pull request soon

AttributeError: 'module' object has no attribute 'SSL_ST_INIT'

When I use socli, and this message occurred, how can I fixed it?

Traceback (most recent call last):
File "/usr/local/bin/socli", line 11, in
load_entry_point('socli==3.6', 'console_scripts', 'socli')()
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 570, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 2755, in load_entry_point
return ep.load()
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 2409, in load
return self.resolve()
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/init.py", line 2415, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/local/lib/python2.7/dist-packages/socli/socli.py", line 13, in
import requests
File "/usr/local/lib/python2.7/dist-packages/requests/init.py", line 84, in
from urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in
import OpenSSL.SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/init.py", line 8, in
from OpenSSL import rand, crypto, SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 118, in
SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'

No check of host certificate

All calls with request.get have disabled certificate verification. This puts the user in danger of a man in the middle.

While the information in those pages isn't private this opens the door to modification of the results. Those results are then printed on screen.

One possible attack scenario is to inject terminal control characters. Some terminal emulators allow things like writing a log to a file through control characters. This could therefore lead to remote code execution.

I see no good reason to disable those security features and recommend turning them on.

Incorrect instructions for OSX

The package python-pip does not exist in homebrew. The proper way to install pip on OSX is:

sudo easy_install pip

Please update the readme.

Why is socli not using stackexchange's API

I just came across this project this evening (GMT + 1) and i'm really interested in it (I've already given it a star)

I've gone through the code a little, and i discovered that socli uses beautifulSoup to scrape stackoverflow directly.

Wouldn't it be better and safer (because stackoverflow might decide to change their markup anytime) to use the official API?

If this is a planned feature...i'll be glad to contribute in anyway to see a re-implementation with the official API.

socli -u option fails with error for python2

Error occurs because python2 does not support json.JSONDecodeError

$ socli -u
Traceback (most recent call last):
  File "/usr/local/bin/socli", line 9, in <module>
    load_entry_point('socli==3.2', 'console_scripts', 'socli')()
  File "/Library/Python/2.7/site-packages/socli/socli.py", line 573, in main
    except json.JSONDecodeError:
AttributeError: 'module' object has no attribute 'JSONDecodeError'

Solution: use this getsentry/raven-python@1f6b652
I'll open a PR in a second.

Throwing error in windows

SoCLI is throwing an error while it is using the interactive mode in windows...

image

Debug output:

C:\Users\Gautam krishna R\PycharmProjects\socli>python -m socli --debug -iq hello world java
Error name: Name not found globally.

Description: name 'fcntl' is not defined

Traceback (most recent call last):
  File "C:\Users\Gautam krishna R\PycharmProjects\socli\socli\socli.py", line 483, in socli_interactive
    LOOP = urwid.MainLoop(QUESTION_PAGE, palette)
  File "C:\Program Files\Python35\lib\site-packages\urwid\main_loop.py", line 111, in __init__
    screen = raw_display.Screen()
  File "C:\Program Files\Python35\lib\site-packages\urwid\raw_display.py", line 89, in __init__
    fcntl.fcntl(self._resize_pipe_rd, fcntl.F_SETFL, os.O_NONBLOCK)
NameError: name 'fcntl' is not defined
exiting...

We need to implement the standard interactive mode in windows... @e-beach

SoCLI fails without X

I was trying to use SoCLI without a running X Server in interactive and single query mode. Both only show part of the result and then immediately close.

I used the following queries:

  1. socli -iq java for loop
  2. socli -q java for loop
  3. socli -q java (this one apparently works fine)
  4. socli -iq java

I am using python 3.6.2 and zsh 5.4.1.

It apparently works perfectly fine when running in xfce4-terminal.

EDIT: added version information

Use pydoc's pager module instead of normal print function

One of the reedit users suggested that we must use pager instead of print function:
screenshot 340

How to fix

  • Comment on this issue if you are interested
  • Use pager module (see the sample code in the screenshot)
  • Fix:
    Windows | Linux | Mac socli -q normal mode
    Windows socli -iq interactive mode
  • Open a PR to the develop branch

Code Maintenance

The current code is written in a single file (1,280 lines currently), which is soon going to unmanageable and unsanitary. I think it should be modular in nature, separated out into modules for their specific purpose.

For example:

  • Separating printing to console methods in helpers.py (or, printer.py).
  • Separation of interactive mode feature into interactive.py.
  • Separation of users info feature into users.py.
  • Separation of most of the global variables in constants.py (or, config.py)
  • Moreover, keeping socli.py as for the main entry point purpose parsing the arguments and calling the necessary methods from different modules.

This will provide a cleaner approach to the developers to read, understand and debug code in the long run.

Also, the code doesn't follow any Python coding standards which is really disturbing. No offence :P.

Bug: Queries don't show the right/true results

Description of the bug:

Running the socli command on terminal doesn't display the accurate or accurate results.

People to notify:
@gautamkrishnar

Steps to recreate:
Try this in your terminal window

socli for loop in python syntax

Here is the screen shot of that command
screenshot from 2017-02-08 11-22-46

Formatting

Would it be possible to add some formatting support, like colors?

Feature: automatically copy code to clipboard

Allow the user to select the code chunk (with the keyboard) and press a button to copy it to the clipboard, maybe using xclip. This way, the code can be pasted into the editor very easily.

Use Google search instead of default stackoverflow search

Using Google search instead of searching on StackOverflow will increase the relevancy of the search results.

Skills Required

  • BeautifulSoup
  • Python

How to do it?

  • Create a new function named gsearch
  • Replace the current search mechanism with gsearch function call

Things to remember

  • Use site:stackoverflow.com in the query while using google search
  • You must randomize user agents to prevent unwanted captcha.

Implement Terminal Mode

Make SoCLI a REPL.
Command : socli --terminal
To Quit : Ctrl + c

Implementation :
I will be using the Python Prompt Toolkit to develop this feature.
It will use the interactive mode feature to display questions and answers.

Any kind of query on this feature will be appreciated.

Change the year in LICENSE

Reserved for first time open source contributors...

How to do

  • Edit LICENSE and change the LICENSE year to 2017
  • Submit a new pull request

Skills Required

  • GitHub

Use colorama instead of natively printing ASCII Color Codes

Use Colorama https://pypi.python.org/pypi/colorama to improve color support.

Currently the color is not supported by windows platform.

If you like to take up this issue, leave a comment below ⭐️

How to do

Just update the printing functions with corresponding colorama API call, Eg of a printing function:

def print_header(str):
    print(format_str(str, bcolors.HEADER))

Replace print(format_str(str, bcolors.HEADER)) with colorama API call.

python 2 interactive mode exits automatically

from the email from @cpu82

Well, it seems that some socli features using interactive mode don't
work with python2, but they do using python3.

E.g. Options like "open in browser" fail to run: if I type 'o' then
socli exits automatically.

BeautifulSoup findAll returning empty list of links

I repeatedly ran the command "socli python for loop" and sometimes it would come up with a "No results found..." message. I noticed that if you run multiple queries within a certain interval, it would return this message with a high percentage, but this issue is not only limited to when you run multiple queries within a certain interval. It appears as though calling findAll() on the BeautifulSoup object in the socli function is returning an empty list. Tested this issue on both Python 2.7 and 3.6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.