Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Option to open in browser by entering a number #1

Merged
merged 1 commit into from
Aug 25, 2015

Conversation

jeremija
Copy link
Contributor

Hi there, I added the ability to open a specific result in browser by entering an integer instead of n or p.

@jarun
Copy link
Owner

jarun commented Aug 23, 2015

Awesome change! And you read my mind in the "numbers instead if asterisks" part. Can we make this a little more user-friendly? And a few more suggestions...

  1. When the user enters the number to open the link in the browser, but do not exit, fall back to the same prompt. He might want to open more links or keep navigating.
  2. The following:
    print " 1-10 press a number and Enter to open that result in browser\n"
    could be:
    print " 1-N press a number and Enter to open that result in browser\n"
  3. Description for point 2 need to be added in the manpage too.
  4. I can see some conflicts from this pull request now. Probably due to the last pull request I merged just now.

@jeremija
Copy link
Contributor Author

When the user enters the number to open the link in the browser, but do not exit, fall back to the same prompt. He might want to open more links or keep navigating.

I agree, I'll take a look.

The following:
print " 1-10 press a number and Enter to open that result in browser\n"
could be:
print " 1-N press a number and Enter to open that result in browser\n"

If we make the results from 1-N, I believe it would make sense to disable the p (previous) command because the previous page will be in the terminal output anyway. And right now it doesn't really go back if -s is used.

I say we make the Enter without any command load next results, int opens a web browser, and Ctrl-C exits gracefully.

Description for point 2 need to be added in the manpage too.

Sure.

I can see some conflicts from this pull request now. Probably due to the last pull request I merged just now.

Will rebase to master.

@jarun
Copy link
Owner

jarun commented Aug 24, 2015

Regarding point 2:

I need to take a look why it is not going back if -s is used. Even if -s is used, I implemented with the first result as base, may be there's a glitch. Thanks for pointing it out! This is also the reason why p cannot be removed, even if the user starts at 50th result, he might want to check out the 40th results by navigating back.

The N comes into picture when -n is used, for example, if '-n 15' is used, the index will range from 1 to 15, so it is not limited to 10.

When the user inputs n or p, please reset the index as if the next set of results is a fresh set. This will reduce complexity of bookeeping and the user doesn't need to scrollback a lot. The idea is to treat each page of results as a new page.

Thank you for the valuable insights :).

@jeremija jeremija force-pushed the open-in-browser-by-index branch from 3e4858f to f4af7ef Compare August 24, 2015 18:53
@jeremija
Copy link
Contributor Author

@jarun please see the changes.

@jarun
Copy link
Owner

jarun commented Aug 24, 2015

I need some pointers from you on "And right now it doesn't really go back if -s is used." in your second comment. I just checked the following:

$ ./google -s 20 hello world

Search URL: https://www.google.com/search?start=20&q=hello+world


new url: https://www.google.co.in/search?start=10&q=hello+world&gws_rd=cr&ei=MJjbVfHcJJSBuwTJnpCgAw


new url: https://www.google.co.in/search?start=0&q=hello+world&gws_rd=cr&ei=MJjbVfHcJJSBuwTJnpCgAw

  • Hello, World! program - Wikipedia, the free encyclopedia
    URL: https://en.wikipedia.org/wiki/%22Hello,_World!%22_program
    A Hello, World! program is a computer program that outputs Hello, World! (or some variant thereof) on a display device. Because it is typically one of
    the...
  • where I can see that -s (start) is changing and is reflected in the results... did I miss something here?

@jeremija
Copy link
Contributor Author

Yes, you're right, it does work. I just tested again both with master and this branch. Last time I tried it looked like I was seeing the first page all over again. I must have done something wrong before.

@jarun
Copy link
Owner

jarun commented Aug 24, 2015

You'll see the first page over and over if you've already hit the first page ;).
I'm testing the changes now.

@jarun
Copy link
Owner

jarun commented Aug 24, 2015

I could see some issues:

Test 1

$ ./google print restore this
...
Press 'n', 'p', or number and Enter to continue... 6
Press 'n', 'p', or number and Enter to continue... Fontconfig error: Cannot load default config file
9
Press 'n', 'p', or number and Enter to continue... Created new window in existing browser session.

arun@Tux~/D/google-cli> // google-cli exits

Test 2

Press 'n', 'p', or number and Enter to continue... 6
Press 'n', 'p', or number and Enter to continue... Fontconfig error: Cannot load default config file
8
Press 'n', 'p', or number and Enter to continue... 7
Press 'n', 'p', or number and Enter to continue...
// no exit

I tested with Yandex browser beta. In the first test, the utility exited when it opened a new tab. In the second case, it kept working as I closed the browser each time after opening a URL.

Then, continuing with second test, I pressed n and got an error:

Test 3

Press 'n', 'p', or number and Enter to continue... 7
Press 'n', 'p', or number and Enter to continue... n

 *****     *****     *****     *****     

Traceback (most recent call last):
File "./google", line 310, in
results = fetch_results()
File "./google", line 274, in fetch_results
resp = conn.getresponse()
File "/usr/lib/python2.7/httplib.py", line 1051, in getresponse
response.begin()
File "/usr/lib/python2.7/httplib.py", line 415, in begin
version, status, reason = self._read_status()
File "/usr/lib/python2.7/httplib.py", line 379, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine: ''

@jarun
Copy link
Owner

jarun commented Aug 24, 2015

Does the following issue seem similar?
Schnouki/git-annex-remote-hubic#3

Please check if the redirection solution works with Google Chrome. I can also see that Python 3.5 RC1 is available.

I do have a pull request for Python 3.x support which I will test shortly. For us the browser output exit will look bad (as users would definitely use the open in browser with index feature ;)) but I would put this in the readme/man maybe if it's unavoidable.

@jarun
Copy link
Owner

jarun commented Aug 24, 2015

Another Chrome related problem:
Press 'n', 'p', or number and Enter to continue... 6
Press 'n', 'p', or number and Enter to continue... [1:2:0825/042917:ERROR:channel.cc(300)] RawChannel read error (connection broken)
[1:2:0825/042917:ERROR:channel.cc(300)] RawChannel read error (connection broken)

  • got this with Python 3.4.0 as well.

Note that I am merging the changes for Python 3.x support from #4. But as I can see you haven't added a lot of prints in your pull request so that should be fine.

@jeremija
Copy link
Contributor Author

Press 'n', 'p', or number and Enter to continue... Created new window in existing browser session.

arun@Tux~/D/google-cli> // google-cli exits

It seems you pressed an enter here and the program exited because of empty string?

browser error messages

The problem is that webbrowser.open() pipes the output of stderr to console. We could use xdg-open with subprocess.Popen and disable the stderr, but this would then only work on linux. I'm not sure what else could be done here.

httplib.BadStatusLine

I cannot reproduce this. The only thing that crosses my mind is that you experienced a connection failure. But this should have nothing to do with this pull request.

@jarun
Copy link
Owner

jarun commented Aug 25, 2015

I guess I did press enter. I guess you are right about the other cases. I think making a note about using FF should be the right way. I will keep fixing the issues that I see during my tests as well.
Thanks a lot for this valuable change.

Would you mind resolving the conflicts? I believe those came from Python 3 support changes I merged this morning.

Updated man page with numeric commands

Able to open multiple links before quitting
@jeremija jeremija force-pushed the open-in-browser-by-index branch from f4af7ef to f028b25 Compare August 25, 2015 15:16
@jeremija
Copy link
Contributor Author

I guess I did press enter. I guess you are right about the other cases. I think making a note about using FF should be the right way. I will keep fixing the issues that I see during my tests as well.
Thanks a lot for this valuable change.

You're welcome. I'd like to recommend you to use a linter such as flake8 to verify the syntax. It has sane defaults, configurable rules and makes it a lot of easier for multiple people to use the same coding style. Best of all, it automatically alerts you about syntax errors.

Would you mind resolving the conflicts? I believe those came from Python 3 support changes I merged this morning.

I believe that's it. I tested it with both python versions and it seemed to work.

@jarun
Copy link
Owner

jarun commented Aug 25, 2015

Thanks for the flake8 suggestion. Being a C/C++ dev with a customized vim I am indeed having a hard time keeping a tab on the Python syntax. ;)

And thank you so much for your valuable time on this new feature!

jarun added a commit that referenced this pull request Aug 25, 2015
Option to open in browser by entering a number
@jarun jarun merged commit 4cee610 into jarun:master Aug 25, 2015
@jarun
Copy link
Owner

jarun commented Aug 25, 2015

Merged.

@jeremija
Copy link
Contributor Author

Thanks for the flake8 suggestion. Being a C/C++ dev with a customized vim I am indeed having a hard time keeping a tab on the Python syntax. ;)

If you're using syntastic, you an easily set your python linter via: let g:syntastic_python_checkers = ['flake8'] and then you can run it with :SyntasticCheck(). I'm sure there are other plugins which do the same thing.

@jarun
Copy link
Owner

jarun commented Aug 25, 2015

I'll check it out!

@jarun
Copy link
Owner

jarun commented Aug 26, 2015

$ /usr/bin/python3 -m pyflakes google
works for me. Thank you for the suggestion!

@jeremija
Copy link
Contributor Author

You're welcome. Glad you got it working! BTW I believe flake8 does more than pyflakes - see here.

@jarun
Copy link
Owner

jarun commented Aug 26, 2015

True!

jarun added a commit that referenced this pull request Mar 9, 2016
Option to open in browser by entering a number
@lock lock bot locked and limited conversation to collaborators Nov 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants