SCalkins Posted June 23, 2014 Share Posted June 23, 2014 Ok, so I'm needing help building a workflow where I type a {query} in the search window, and it returns results from monster.com autofill. Here are the request headers and response headers/response body. Can anyone point me in the right direction on how to do something like this? Accept: application/json, text/javascript, */* Accept-Encoding: gzip,deflate,sdch Connection: keep-alive Content-Type: application/json; charset=UTF-8 Referer: http://www.monster.com Host: www.monster.com Orgin: http://www.monster.com Content-Length: 10 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 X-Requested-With: XMLHttpRequest Accept-Language: en-US,en;q=0.8 { "q": "jav" } HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 Content-Type: application/json; charset=utf-8 X-Powered-By: ASP.NET X-AspNetMvc-Version: 3.0 Connection: keep-alive P3P: CP=CAO DSP COR CURa ADMa DEVa TAIa IVAa IVDa CONo HISa TELo PSAa PSDa DELa UNRa PUBi OTRa BUS LEG PHY ONL UNI PUR COM NAV INT DEM CNT STA HEA PRE GOV OTC Date: Mon, 23 Jun 2014 13:24:35 GMT Set-Cookie: DOMAINALIAS=; path=/, DOMAINALIAS=; expires=Sun, 22-Jun-2014 13:24:35 GMT; path=/ Content-Length: 186 Cache-Control: private, max-age=3600 X-AspNet-Version: 4.0.30319 { "Result": { "Items": [ { "Text": "Java Architect", "ID": 170038, "Data": null }, { "Text": "Java Software Engineer", "ID": 167790, "Data": null }, { "Text": "JavaScript Developer", "ID": 166359, "Data": null } ] } } Link to comment
jdfwarrior Posted June 23, 2014 Share Posted June 23, 2014 Ok, so I'm needing help building a workflow where I type a {query} in the search window, and it returns results from monster.com autofill. Here are the request headers and response headers/response body. Can anyone point me in the right direction on how to do something like this? Accept: application/json, text/javascript, */* Accept-Encoding: gzip,deflate,sdch Connection: keep-alive Content-Type: application/json; charset=UTF-8 Referer: http://www.monster.com Host: www.monster.com Orgin: http://www.monster.com Content-Length: 10 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 X-Requested-With: XMLHttpRequest Accept-Language: en-US,en;q=0.8 { "q": "jav" } HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 Content-Type: application/json; charset=utf-8 X-Powered-By: ASP.NET X-AspNetMvc-Version: 3.0 Connection: keep-alive P3P: CP=CAO DSP COR CURa ADMa DEVa TAIa IVAa IVDa CONo HISa TELo PSAa PSDa DELa UNRa PUBi OTRa BUS LEG PHY ONL UNI PUR COM NAV INT DEM CNT STA HEA PRE GOV OTC Date: Mon, 23 Jun 2014 13:24:35 GMT Set-Cookie: DOMAINALIAS=; path=/, DOMAINALIAS=; expires=Sun, 22-Jun-2014 13:24:35 GMT; path=/ Content-Length: 186 Cache-Control: private, max-age=3600 X-AspNet-Version: 4.0.30319 { "Result": { "Items": [ { "Text": "Java Architect", "ID": 170038, "Data": null }, { "Text": "Java Software Engineer", "ID": 167790, "Data": null }, { "Text": "JavaScript Developer", "ID": 166359, "Data": null } ] } } Are you familiar with any scripting/programming languages? This would be best done by sending an http request to monster then reading the result (json formatted) and displaying those using script filter feedback in Alfred. Link to comment
SCalkins Posted June 24, 2014 Author Share Posted June 24, 2014 I am "somewhat" I'm having trouble trying to figure out the process of getting it inside Alfred. I can return the results I want in terminal using curl and then using grep to filter out the json.. Beyond that I'm lost... Can you think of a workflow that what use a similar setup that I could look at ? Link to comment
deanishe Posted June 24, 2014 Share Posted June 24, 2014 (edited) You'd be much better off using a language that can parse JSON, like Ruby or Python, than trying to make sense of it in bash. I wrote a Python library for Alfred that should let you do this in very few lines of code. Check out this example, which reads JSON from Pinboard's API and displays that in Alfred. I think that's about 80–90% of what you need code-wise to get started and it's only about 10 lines The library's tutorial is also all about grabbing JSON from a webservice and displaying it in Alfred, so that might be worth reading. Edited June 24, 2014 by deanishe SCalkins 1 Link to comment
rice.shawn Posted June 25, 2014 Share Posted June 25, 2014 (edited) You'd be much better off using a language that can parse JSON, like Ruby or Python, than trying to make sense of it in bash. Or PHP. Dean, you always forget that one on purpose. For PHP, just look into the curl class. The curl_init function has a nice little example. You'd also just set all the fields you need with curl_setopt. It makes it pretty easy, then you'd just use json_decode to deal with the JSON return. If you really want to use Bash, then you can use a nice little utility called jq to parse the JSON for you, although, sticking with Bash does make it much harder. Ultimately, however, just use whatever language you know best. If you need to start learning one, then actually go with Python (unless you want to move toward some more "standard" web development, then go with PHP). Edited June 25, 2014 by Shawn Rice Link to comment
MuppetGate Posted June 25, 2014 Share Posted June 25, 2014 Have to say that I've become a big Python fan over the past week or so. Once I got over the indenting thing ... Link to comment
deanishe Posted June 25, 2014 Share Posted June 25, 2014 I've never understood the aversion to the indenting thing. I mean, don't you indent code in other languages properly, too? Or am I just excessively anal about indentation in all my code because I mostly write in Python? Link to comment
MuppetGate Posted June 26, 2014 Share Posted June 26, 2014 (edited) I've never understood the aversion to the indenting thing. I mean, don't you indent code in other languages properly, too? Or am I just excessively anal about indentation in all my code because I mostly write in Python? Oh, I always indent code, but I've never come across a language that uses whitespace to decide intent. I'm used to stuff like IF ... ENDIF or braces for that kind of stuff. It just struck me as really bizarre. Still, I also like cheese and jam in the same sandwich, so what is really just a language quirk didn't strike me as a good reason not to give it a go. Having played with Python for a week or so, here's what I've noticed about this whole whitespace thing: Because I don't have to use extra statements to denote the end of a code block, I type less code. If it really bothered me that much, I figured I could always put in a comment to fake it. (#ENDIF for example). As it happened, it took about five minutes to get used it, so I didn't bother. In my opinion, Python code is the easiest to read. It is much easier to see the structure of properly-indented code if extraneous stuff, like endifs and brackets, is taken out. This is just my opinion of course. So I'm something of a convert, I think. Edited June 26, 2014 by MuppetGate Link to comment
deanishe Posted June 26, 2014 Share Posted June 26, 2014 (edited) I love the meaningful indentation. It forces people to indent their code properly. I have to maintain a pretty big PHP webapp at the moment, and the indentation appears to be entirely random. It drives me nuts trying to follow the control flow The best thing about Python, imo, is exactly that it almost forces you to write readable code. It's actually harder to obfuscate it. Give this a try in Python: from __future__ import braces Edited June 26, 2014 by deanishe Link to comment
MuppetGate Posted June 27, 2014 Share Posted June 27, 2014 Thanks, but I think I prefer Python as nature intended, now that I'm getting used to it. But that __future__ stuff is really . . . wow. Link to comment
deanishe Posted June 27, 2014 Share Posted June 27, 2014 It's an easter egg. >>> from __future__ import braces File "<stdin>", line 1 SyntaxError: not a chance >>> 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