0
import json
import urllib
import sqlite3

import temp


def loading():
    url = 'https://jobs.github.com/positions.json?page=1'  # URL for API 1-5json_obj = urllib.urlopen(url)
    response = urllib.urlopen(url)
    data = json.load(response)  # loads the url and set it into data variable

    for item in data[0].keys():
        print(item)
        return data  # Get the keys


# def loading():
# print " LOADING API(s)"
# urllib.urlopen('https://jobs.github.com/positions.json?page=1')
# temp = json.dumps(data[1])
# print (json.dumps(data[1]))
# print (" ")
def createDB(data):
    conn = sqlite3.connect('test.db')
    c = conn.cursor()
    # Create table
    c.execute('''CREATE TABLE example
        (description text, title text, url text, company_logo text, company text, id integer primary key, company_url text, how_to_apply text,
        location text, type text, created_at timestamp)''')
    temp_values = list(tuple())
    for item in temp:

        list_of_values = [v for k, v in item.items()]
        tuple_of_values = tuple(list_of_values)
        temp_values.append(tuple_of_values)
        c.executemany('INSERT INTO table_name VALUES (?,?,?,?,?,?,?,?,?,?,?)', temp_values)


def main():
    data = loading()
    createDB(data)


main()

I ran the code it creates the database but nothing seems to be in it this is the error I get as well File

Traceback (most recent call last): File "/Users/issac_rodriguez/PycharmProjects/N/Sprint2/database.py", line 45, in main() File "/Users/issac_rodriguez/PycharmProjects/N/Sprint2/database.py", line 42, in main createDB(data) File "/Users/issac_rodriguez/PycharmProjects/N/Sprint2/database.py", line 32, in createDB for item in temp: TypeError: 'module' object is not iterable

1
  • It's a typo, you go for item in temp, but you probably want for item in temp_values. This is why you should always use meaningful names instead of x, temp, etc. - temp is actually a meaningful name for the module (if it is the module I think it is). Commented Feb 5, 2020 at 0:15

1 Answer 1

2

Take a look at the loop your createDB() function. You tried to iterate through temp which is referring to the module temp that you imported above. Perhaps you meant to iterate through temp_values? You may also need to pass your argument data into temp_values. Here is a potential solution:

temp_values = list(tuple(data))
for item in temp_values:
...

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.