0

I need to do a pokemon api in postgres from this url "https://pokeapi.co/" The details of database (hidden.py) and the utils (myutils.py) they work right, the error is when i do in the console:

python3 pokeapi.py

File "/home/mcala88/pokeapi.py", line 67 cur.close() ^ SyntaxError: EOF while scanning triple-quoted string literal


import psycopg2
import hidden
import time
import myutils
import requests
import json
# Load the secrets
secrets = hidden.secrets()
conn = psycopg2.connect(host=secrets['host'],
        port=secrets['port'],
        database=secrets['database'],
        user=secrets['user'],
        password=secrets['pass'],
        connect_timeout=3)
cur = conn.cursor()
defaulturl = 'https://pokeapi.co/api/v2/pokemon/1/'
print('If you want to restart the spider, run')
print('DROP TABLE IF EXISTS pokeapi CASCADE;')
print(' ')
sql = '''
CREATE TABLE IF NOT EXISTS pokeapi (id INTEGER, body JSONB);
print(sql)
cur.execute(sql)
# Check to see if we have ids in the table, if not add starting points
# for each of the object trees
sql = 'SELECT COUNT(id) FROM pokeapi;'
count = myutils.queryValue(cur, sql)
if count < 1:
    objects = ['pokemon', 'region', 'type']
    for obj in objects:
        sql = f"INSERT INTO pokeapi (id) VALUES ( 'https://pokeapi.co/api/v2/{obj}/1/' )";
        print(sql)
        cur.execute(sql, (defaulturl))
    conn.commit()
cur.close()

1 Answer 1

1

You forgot to close off your triple quotes.

sql = '''
CREATE TABLE IF NOT EXISTS pokeapi (id INTEGER, body JSONB);

should be

sql = '''
CREATE TABLE IF NOT EXISTS pokeapi (id INTEGER, body JSONB);
'''
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.