Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. @app.route('/cegekapi/<cegid>.json')       
  2. def list_apicegek_reszlet(cegid):
  3.     """Lists the first 50 persons in the database"""
  4.     conn = get_db()
  5.     try:
  6.         cur = conn.cursor()
  7.         try:
  8.             cur.execute('''SELECT ID, NEV, KAPCSOLATTARTO FROM CEGEK WHERE CEGEK.ID = :cegid_in''', cegid_in = cegid)
  9.             results = []
  10.             for id, nev, kapcsolattarto in cur:
  11.            
  12.                 try:
  13.                     params = {'q': nev,'format': 'json', 'key':request.get('https://cse.google.com/cse/')}
  14.                     # API docs: http://www.mediawiki.org/wiki/API:Tutorial
  15.                     # Example for 1st April:
  16.                     # http://en.wikipedia.org/w/api.php?action=query&format=json&prop=extlinks&titles=April%201
  17.                     res = requests.get('https://seeks.hsbp.org', params=params, verify = "/home/vsza/cacert.pem")
  18.                     url = res.json()
  19.                    
  20.                 except:
  21.                     pass # necessary if a clause would be empty in Python
  22.  
  23.                 results.append({'ID': id, 'NEV': nev, 'KAPCSOLATTARTO': kapcsolattarto, 'URL': url["results"][0]["url"]})
  24.             return jsonify(cegek=results)
  25.         finally:
  26.             cur.close()
  27.     finally:
  28.         # this is also a naive implementation, a more Pythonic solution:
  29.         # http://docs.python.org/2/library/contextlib.html#contextlib.closing
  30.         conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement