Let’s say Ia have the following string to be passed as query for an API call using python:
<code>import psycopg2
from gql import Client, gql
from gql.transport.requests import RequestsHTTPTransport
from datetime import datetime
start_year = str(datetime.now().year -4)
end_year = str(datetime.now().year)
query_str = """
query events{
api_version
public_DB(
filters: {
iso: ["Nation1","Nation2","Nation3"]
from: 2020,
to: 2024,
classif: ["car","bus","train",]
include_hist: true
}
) {
total_available
info {
timestamp
filters
cursor
}
data {
disno
iso
start_year
start_month
start_day
end_year
end_month
end_day
type
subtype
entry_date
last_update
}
}
}
"""
query = gql(query_str)
transport = RequestsHTTPTransport(
url='https://api.open_DB.it/v1',
headers={'Authorization': api_key},
use_json=True,
)
# Create a GraphQL client using the defined transport
client = Client(transport=transport, fetch_schema_from_transport=True)
# Execute the query
response = client.execute(query)
</code>
<code>import psycopg2
from gql import Client, gql
from gql.transport.requests import RequestsHTTPTransport
from datetime import datetime
start_year = str(datetime.now().year -4)
end_year = str(datetime.now().year)
query_str = """
query events{
api_version
public_DB(
filters: {
iso: ["Nation1","Nation2","Nation3"]
from: 2020,
to: 2024,
classif: ["car","bus","train",]
include_hist: true
}
) {
total_available
info {
timestamp
filters
cursor
}
data {
disno
iso
start_year
start_month
start_day
end_year
end_month
end_day
type
subtype
entry_date
last_update
}
}
}
"""
query = gql(query_str)
transport = RequestsHTTPTransport(
url='https://api.open_DB.it/v1',
headers={'Authorization': api_key},
use_json=True,
)
# Create a GraphQL client using the defined transport
client = Client(transport=transport, fetch_schema_from_transport=True)
# Execute the query
response = client.execute(query)
</code>
import psycopg2
from gql import Client, gql
from gql.transport.requests import RequestsHTTPTransport
from datetime import datetime
start_year = str(datetime.now().year -4)
end_year = str(datetime.now().year)
query_str = """
query events{
api_version
public_DB(
filters: {
iso: ["Nation1","Nation2","Nation3"]
from: 2020,
to: 2024,
classif: ["car","bus","train",]
include_hist: true
}
) {
total_available
info {
timestamp
filters
cursor
}
data {
disno
iso
start_year
start_month
start_day
end_year
end_month
end_day
type
subtype
entry_date
last_update
}
}
}
"""
query = gql(query_str)
transport = RequestsHTTPTransport(
url='https://api.open_DB.it/v1',
headers={'Authorization': api_key},
use_json=True,
)
# Create a GraphQL client using the defined transport
client = Client(transport=transport, fetch_schema_from_transport=True)
# Execute the query
response = client.execute(query)
What I would like to do is to pass two variables string (start_year, end_year) for the start year (“from: 2020”) and the end year (to: 2024) that I can change at the beginning of the code