Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help finding data
#1
Hi I am a student and I have obtained this script from online.

I want to be able to find the symbol of a company. For example when I search Facebook, all the data related to facebook from that code is displayed. Please help I am an amateur at python and i am feeling really lost now Sad

Hi sorry i was not aware of the tags needed when posting the python codes
 
def get_data():    
    try:
        # For Python 3.0 and later
        from urllib.request import urlopen
    except ImportError:
        # Fall back to Python 2's urllib2
        from urllib2 import urlopen

    import json

    def get_jsonparsed_data(url):
        """
        Receive the content of ``url``, parse it as JSON and return the object.

        Parameters
        ----------
        url : str

        Returns
        -------
        dict
        """
        response = urlopen(url)
        data = response.read().decode("utf-8")
        return json.loads(data)

    url = ("https://financialmodelingprep.com/api/v3/company/stock/list?apikey=a76d61b58d4a34dd9b8a260033a24b57")
    print(get_jsonparsed_data(URL))
Reply
#2
Hi

Well your first issue would be that you are calling your print line and the "get_jsonparsed_data" method with a parmeter that is not defined as you have "URL" in caps and I presume you mean to call it with url in lower case that defined by the finacialmodeling...... string

I am not sure what editor you are using, but try something like pycharm or visual studio code (am sure plenty of others recommended) as it will using intellisense at least inform you of artefacts that are not defined or wrong order etc etc, so you try to follow the PEP standards as much as possible (one of them being that imports should be first in the file, its not enforceable as such but just good habit)

Other things it will highlight is that it tests the python version and falls back to v2 if v3 is not there, but ideally for safety sake it too should be in a try / except statement as the user may not even have a python implementation at all, there are better ways to ascertain the user environment than this I think.

I would advise start small with something like the below which is along your lines but I have not fully tested so....
import json
from urllib.request import urlopen


def get_jsonparsed_data(url):
    """
    Receive the content of ``url``, parse it as JSON and return the object.

    Parameters
    ----------
    url : str

    Returns
    -------
    dict
    """
    response = urlopen(url)
    data = response.read().decode("utf-8")
    return json.loads(data)

url = ("https://financialmodelingprep.com/api/v3/company/stock/list?apikey=a76d61b58d4a34dd9b8a260033a24b57")
print(get_jsonparsed_data(url))
Regards
-------- *
“Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.”
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Moving data from one Excel to another and finding maximum profit azizrasul 7 1,415 Oct-06-2022, 06:13 PM
Last Post: azizrasul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020