deadesq Posted May 22, 2015 Share Posted May 22, 2015 Hello, all. I'm trying to do a workflow that will allow me to search Google Flights by passing multiple queries to Alfred. The URL for Google Flights looks like: https://www.google.com/flights/#search;f=LAX;t=MAD;d=2015-06-17;r=2015-06-30 Summary: f is the outgoing airport code, t is the destination airport code, d is the departure date, and r is the return date. I've modified the Kitten image workflow I found elsewhere in the forums to try to use multiple queries, so my bash script looks like: #!/bin/bash # split the query into an argument array IFS=',' read -a qarg <<< "{query}" # set the x and y sizes from the array w=${qarg[0]} x=${qarg[1]} y=${qarg[2]} z=${qarg[3]} # open the url with the two arguments open "https://www.google.com/flights/#search;f=$w;t=$x;d=$y;r=$z" When I run the script, though, it puts all the queries in for $w, and the other three don't get populated. What am I doing wrong? Any ideas? Thanks. Link to comment
deanishe Posted May 22, 2015 Share Posted May 22, 2015 It works correctly. You are entering your query with commas between the parts, aren't you? E.g. lax,mad,2015-05-24,2015-06-19 Link to comment
deadesq Posted May 22, 2015 Author Share Posted May 22, 2015 Oh, jeez. Now I feel like an idiot. I wasn't putting in the commas. Thank you. It works great. I appreciate the save. Link to comment
deanishe Posted May 22, 2015 Share Posted May 22, 2015 I'd be lying if I said I didn't do exactly the same at first. Link to comment
deadesq Posted May 22, 2015 Author Share Posted May 22, 2015 Here's the workflow packaged up if someone can use it. http://deadesq.com/files/Google_Flights.alfredworkflow Link to comment
deanishe Posted May 22, 2015 Share Posted May 22, 2015 You should probably put that in the Share your Workflows forum. A lot more people will see it in there. Link to comment
t3k Posted November 27, 2017 Share Posted November 27, 2017 Hi sorry to bump the old thread, but what this: IFS=',' read -a qarg <<< "{query}" means? And what happen if user not input all argument completely? (only several ones) Link to comment
deanishe Posted November 27, 2017 Share Posted November 27, 2017 1 hour ago, t3k said: means? It splits the input {query} on commas (IFS) and reads it into the array qarg. Link to comment
t3k Posted November 28, 2017 Share Posted November 28, 2017 (edited) 9 hours ago, deanishe said: It splits the input {query} on commas (IFS) and reads it into the array qarg. Thanks, will it work if it have a space between them? Like "1234, 5678" ? Edited November 28, 2017 by t3k Link to comment
deanishe Posted November 28, 2017 Share Posted November 28, 2017 41 minutes ago, t3k said: Thanks, will it work if it have a space between them? Like "1234, 5678" ? Maybe. Maybe not. The variable will have a space at the front in any case. Link to comment
t3k Posted November 28, 2017 Share Posted November 28, 2017 34 minutes ago, deanishe said: Maybe. Maybe not. The variable will have a space at the front in any case. I've tried and in my case it didn't work. Link to comment
deanishe Posted November 28, 2017 Share Posted November 28, 2017 (edited) Try this Python script instead (be sure to set Language = /usr/bin/python): import re import sys from webbrowser import open_new_tab URL = 'https://www.google.com/flights/#search;f={};t={};d={};r={}' query = sys.argv[1] params = re.split(r'[^A-Za-z0-9-]+', query) # Ensure params has 4 elements params += (4 - len(params)) * [''] if len(params) > 4: params = params[:4] open_new_tab(URL.format(*params)) It works with spaces, commas, commas and spaces. Anything that isn't a letter, number or a dash, basically. Edited November 28, 2017 by deanishe Link to comment
Siraj Samsudeen Posted August 21, 2020 Share Posted August 21, 2020 On 11/28/2017 at 7:01 PM, deanishe said: Try this Python script instead (be sure to set Language = /usr/bin/python): import re import sys from webbrowser import open_new_tab URL = 'https://www.google.com/flights/#search;f={};t={};d={};r={}' query = sys.argv[1] params = re.split(r'[^A-Za-z0-9-]+', query) # Ensure params has 4 elements params += (4 - len(params)) * [''] if len(params) > 4: params = params[:4] open_new_tab(URL.format(*params)) It works with spaces, commas, commas and spaces. Anything that isn't a letter, number or a dash, basically. Thanks a lot for this pointer to Python. I was able to get my custom search to work. However, I had to use Python2. How do I make this work with Python3? Link to comment
deanishe Posted August 21, 2020 Share Posted August 21, 2020 2 hours ago, Siraj Samsudeen said: How do I make this work with Python3? What error are you getting with Python 3? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now