0

I have the following starting code:

@app.route('/venues')
def venues():
  # TODO: replace with real venues data.
  #       num_shows should be aggregated based on number of upcoming shows per venue.
  data=[{
    "city": "San Francisco",
    "state": "CA",
    "venues": [{
      "id": 1,
      "name": "The Musical Hop",
      "num_upcoming_shows": 0,
    }, {
      "id": 3,
      "name": "Park Square Live Music & Coffee",
      "num_upcoming_shows": 1,
    }]
  }, {
    "city": "New York",
    "state": "NY",
    "venues": [{
      "id": 2,
      "name": "The Dueling Pianos Bar",
      "num_upcoming_shows": 0,
    }]
  }]
  return render_template('pages/venues.html', areas=data);

how do i take this data and import it into my database? I have columns for the information to go into but cant seem to figure out how to get values inside.

marz
  • 1
  • See [this](https://stackoverflow.com/questions/33432297/insert-dictionary-within-list-to-database-in-python). This should get you going – AzyCrw4282 Feb 24 '20 at 21:02
  • Welcome to StackOverflow. The code you are showing is not related to the question: querying and inserting data are not necessarily related unless you have a CRUD API. Please show what you have tried and where you are stuck (see [how do I ask a good question ?](https://stackoverflow.com/help/how-to-ask)); you can also search similar questions before posting your own. – Michael Doubez Feb 24 '20 at 21:06

1 Answers1

0

you should create an intermediate/staging data structure, e.g. a list or a csv file. And map that to your database structure. Then you can import/insert into your database.

fullstack
  • 11
  • 3
  • Sometimes this is the right thing, but certainly not always -- some types of databases can store structured JSON as-is; for that matter, modern PostgreSQL is capable of operating that way, though it's certainly also capable of being operated more traditionally. The bigger issue is that schema design is a major topic -- books and university classes center around it, making it too broad a topic to fold into a SO answer. – Charles Duffy Feb 25 '20 at 02:25
  • As described in the "Answer Well-Asked Questions" section of [How to Answer](https://stackoverflow.com/help/how-to-answer), questions that are too broad or vague to answer completely and comprehensively are better closed rather than answered. – Charles Duffy Feb 25 '20 at 02:27