Giter Club home page Giter Club logo

postgresql-plpython-webservice's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

sh-bravoalpha

postgresql-plpython-webservice's Issues

Not performing get request

Hello,

When I run the code, it show that the create function had worked. However I am not getting data back from the request. I did change the plpython2u to plpython3u, but i don't think that caused he problem.

I would think that this is a simple call, as it is going to https://services.nvd.nist.gov/rest/json/cves/2.0
and for my test, I only grabbed a handful of the header
{"resultsPerPage": 2000, "totalResults": 226528, "format": "NVD_CVE", "version": "2.0"}

This is new to me, so it might be something on my end, but I would appreeciate your help.

Thank you

Full code
`CREATE OR REPLACE FUNCTION web_service(format text, resultsPerPage int, version text, totalResults int)
RETURNS TABLE(like mytable1)
AS $$

for arg in [format, resultsPerPage, version, totalResults]:
if arg == "" or arg is None:
return []

import requests
import datetime
storage_table_name = 'mytable1'

rest_endpoint = 'https://services.nvd.nist.gov/rest/json/cves/2.0?hasKev'.format(series_name)
unique_request_id = "{}{}{}_{}".format(format, resultsPerPage, version, totalResults)
if response.status_code >= 400:
return []
rest_json = response.json()

insert_query = "INSERT INTO {} VALUES(NOW(), $1, $2, $3, $4, $5, $6, $7, $8)".format(storage_table_name)

insert_types = ["text", "int", "text", "int", "text", "text", "text", "text"]

plan = plpy.prepare(insert_query, insert_types)

for first_level in rest_json:
	data_in_first_level = rest_json[first_level]
for second_level in data_in_first_level['data']:
	insert_list = [unique_request_id, ]
	insert_list.extend(second_level)
	plpy.execute(plan, insert_list)

return_query = """
SELECT * FROM
{}
WHERE unique_request_id = '{}'
""".format(storage_table_name, unique_request_id)

return plpy.execute(return_query)

$$ LANGUAGE plpython3u;`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.