Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @app.route('/cegekapi/<cegid>.json')
- def list_apicegek_reszlet(cegid):
- """Lists the first 50 persons in the database"""
- conn = get_db()
- try:
- cur = conn.cursor()
- try:
- cur.execute('''SELECT ID, NEV, KAPCSOLATTARTO FROM CEGEK WHERE CEGEK.ID = :cegid_in''', cegid_in = cegid)
- results = []
- for id, nev, kapcsolattarto in cur:
- try:
- params = {'q': nev,'format': 'json', 'key':request.get('https://cse.google.com/cse/')}
- # API docs: http://www.mediawiki.org/wiki/API:Tutorial
- # Example for 1st April:
- # http://en.wikipedia.org/w/api.php?action=query&format=json&prop=extlinks&titles=April%201
- res = requests.get('https://seeks.hsbp.org', params=params, verify = "/home/vsza/cacert.pem")
- url = res.json()
- except:
- pass # necessary if a clause would be empty in Python
- results.append({'ID': id, 'NEV': nev, 'KAPCSOLATTARTO': kapcsolattarto, 'URL': url["results"][0]["url"]})
- return jsonify(cegek=results)
- finally:
- cur.close()
- finally:
- # this is also a naive implementation, a more Pythonic solution:
- # http://docs.python.org/2/library/contextlib.html#contextlib.closing
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement