Get data from an external api into my database.

141 views
Skip to first unread message

Mukesh Jha

unread,
Mar 20, 2018, 8:05:23 AM3/20/18
to Django users
I want to access a api from http://open-platform.theguardian.com/ or https://newsapi.org/ and load it into my sqlite database. The data in these site is in json format and I want them to get converted into my database model format and store in it and later on use them as when queried. I am clueless as I am quite new in this development system. Please help if possible.

Jani Tiainen

unread,
Mar 20, 2018, 3:01:14 PM3/20/18
to django...@googlegroups.com
Hi.

Requests library will be your friend.

ti 20. maaliskuuta 2018 klo 14.05 Mukesh Jha <talklik...@gmail.com> kirjoitti:
I want to access a api from http://open-platform.theguardian.com/ or https://newsapi.org/ and load it into my sqlite database. The data in these site is in json format and I want them to get converted into my database model format and store in it and later on use them as when queried. I am clueless as I am quite new in this development system. Please help if possible.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6ca83919-9b2a-42c3-bfde-0c66faef4910%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tom Evans

unread,
Mar 20, 2018, 3:16:38 PM3/20/18
to django...@googlegroups.com
Adjust for your needs:

data = requests.get(url).json()
for datum in data:
MyModel.objects.save(**datum)

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages