Created
May 28, 2013 08:19
-
-
Save elpargo/5661274 to your computer and use it in GitHub Desktop.
API de provincias de RD.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import falcon #webframework | |
import json #json duh! | |
import requests #sane http get/post/etc. | |
from bs4 import BeautifulSoup #sane htmlparser | |
def get_soup(): | |
#Link u guys provided.... get me the .json !!!! | |
html_doc = requests.get("http://www.jmarcano.com/mipais/geografia/province/municipios/").text | |
if not html_doc: | |
#lame sanity check. TODO: make proper | |
raise ValueError | |
soup = BeautifulSoup(html_doc) | |
return soup | |
def get_response(): | |
soup = get_soup() | |
#this crap is in a table full of arrgssss luckily for us is the only strong in the whole page :D | |
res = soup.find_all('strong') | |
res = [item.text for item in res] #get the actual text not the tag | |
print res | |
return json.dumps(res)#json go! | |
class ProvinciasResource: | |
def on_get(self, req, resp): | |
resp.status = falcon.HTTP_200 | |
resp.body = get_response() | |
app = api = falcon.API() | |
provs = ProvinciasResource() | |
api.add_route('/provincias', provs) | |
if __name__ == '__main__': | |
get_response() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment