SlideShare a Scribd company logo
SMAC LAB, LSU

Sep 7, 2018
SMAC Talks
Using APIs to Gather Data
Instructor: Dr. Ke (Jenny) Jiang
Using APIs to Gather Data
Installation
Download Anaconda Python 3.6 to run Python scripts. Anaconda is free to
download. Once you’ve installed Anaconda, you can create/edit scripts in Spyder.
Spyder
Using APIs to Gather Data
Open the files
Spyder
Using APIs to Gather Data
Open the files
Spyder
Let’s Play..
Copy & Paste the Syntax to
the Console
Using APIs to Gather Data
Using APIs to Gather Data
More efficient way to run the Syntax
Using APIs to Gather Data
Search Text in the Syntax
Using APIs to Gather Data
The search Results being
Highlighted
Using APIs to Gather Data
Go to “variables_strings-numbers.py” first
Using APIs to Gather Data
Application Programming Interfaces
* allow you to access data or services on other servers on the web
URL
http://api.nytimes.com/svc/community/v3/user-content/by-date.json
returns data when loaded
API Documentation
* what you can and can't do with the API
NYT APIs Documentation
http://developer.nytimes.com
Community API
http://developer.nytimes.com/community_api_v3.json#/README
Something to be aware of…
* APIs are usually rate limited
(not to request data to an api too frequently)
* Sign up for an authorization key to use APIs
Request an API Key
http://developer.nytimes.com
Request an API Key
Request an API Key
Name
Email
Web
Community API
Click
Find the Requested API Key
Click
Check Your Mailbox
API Key
use aip to collect nyt comments.py
Download Code:
Open the Code in Spyder
Click
Step 1: Import Packages
Step 2: Get Data
Copy the string key into the variable api_key
Get data in .json format in a specific day (2018-08-31)
Step 3: Get Data as a JSON object
* We’ve collected 25 comments from the date we specified in the URL
* BUT there were many more comments made that day
* We want to loop through and collect them all
Step 4: Parse it into a Pandas DataFrame
Step 5: How Many Comments?
*Output: We need to collect 331 times, since we only get 25 comments at a time.
* If you are making more than 1,000 calls per day (via an application or any other
method) to an individual API, NYT will notice that and assume you're using our API
for a commercial purpose. Please contact NYT if you have hit that limit but do not
think you are using the API for a commercial purpose.
Step 6: Collect All the Comments
Slow our script down
Line 90: Use your own path to save the comments
Step 7: Who Are Most Active?
Most active users
Users comments >= 5
What kind of comments
Step 8: Open Saved Comments

More Related Content

PPTX
Oracle IDM: Notifications
PDF
WordPress REST API
PDF
Article workflow
PDF
Recommend 10 splunk apps-Bangkok Splunk Meetup#1
PDF
WordPress News - March 2017
DOCX
Dotnetques
PDF
Prepare to defend thyself with Blue/Green
PDF
Building a mini-theme with WordPress REST API
Oracle IDM: Notifications
WordPress REST API
Article workflow
Recommend 10 splunk apps-Bangkok Splunk Meetup#1
WordPress News - March 2017
Dotnetques
Prepare to defend thyself with Blue/Green
Building a mini-theme with WordPress REST API

Similar to Using ap is to gather data (20)

PDF
2022 APIsecure_API Discovery: First step towards API Security
PPTX
search_demystified_presentation for SEO SE<
PPTX
Data-Analytics using python (Module 4).pptx
PPTX
Api Testing
PPTX
Api Testing
PPTX
Robert Fornal - ChatGPT as a Testing Tool.pptx
PPTX
2022 APIsecure_Securing APIs with Open Standards
PDF
Webinar: “Introduction to the Postman API Network”
PPTX
DevNet 1056 WIT Spark API and Chat Bot Workshop
PPTX
How to leverage APIs & Scrapers in App Store Optimization
PPTX
Toronto Anypoint DataGraph (1).pptx
PPTX
Datasets, APIs, and Web Scraping
PPTX
Integrating Splunk into your Spring Applications
PPTX
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
PPTX
apidays Paris 2024 - Design, Debug, Test and Mock APIs with Kong Insomnia, Pi...
PDF
FastAPI - Rest Architecture - in english.pdf
PPT
Opensocial Haifa Seminar - 2008.04.08
PPTX
WaveMaker API Success
PDF
Go Building Web Applications 1st Edition Nathan Kozyra Mat Ryer
PDF
Big data made easy with a Spark
2022 APIsecure_API Discovery: First step towards API Security
search_demystified_presentation for SEO SE<
Data-Analytics using python (Module 4).pptx
Api Testing
Api Testing
Robert Fornal - ChatGPT as a Testing Tool.pptx
2022 APIsecure_Securing APIs with Open Standards
Webinar: “Introduction to the Postman API Network”
DevNet 1056 WIT Spark API and Chat Bot Workshop
How to leverage APIs & Scrapers in App Store Optimization
Toronto Anypoint DataGraph (1).pptx
Datasets, APIs, and Web Scraping
Integrating Splunk into your Spring Applications
DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python
apidays Paris 2024 - Design, Debug, Test and Mock APIs with Kong Insomnia, Pi...
FastAPI - Rest Architecture - in english.pdf
Opensocial Haifa Seminar - 2008.04.08
WaveMaker API Success
Go Building Web Applications 1st Edition Nathan Kozyra Mat Ryer
Big data made easy with a Spark
Ad

More from Ke Jiang (13)

PDF
1109 survey and communication network analysis
PDF
1102 Gephi Tutorial
PDF
1102 Gephi tutorial
PDF
1026 telling story from text 2
PDF
1018telling story from text 2
PDF
1018telling story from text
PDF
Crimson hexagon
PDF
Introduction to Crimson Hexagon
PDF
Lsu tcat
PDF
Tcat
PDF
Collect twitter data using python
PDF
Collect twitter data using python
PDF
creating infographics from text
1109 survey and communication network analysis
1102 Gephi Tutorial
1102 Gephi tutorial
1026 telling story from text 2
1018telling story from text 2
1018telling story from text
Crimson hexagon
Introduction to Crimson Hexagon
Lsu tcat
Tcat
Collect twitter data using python
Collect twitter data using python
creating infographics from text
Ad

Recently uploaded (20)

PDF
Complications of Minimal Access Surgery at WLH
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Insiders guide to clinical Medicine.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Pharma ospi slides which help in ospi learning
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
RMMM.pdf make it easy to upload and study
PPTX
Cell Structure & Organelles in detailed.
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
master seminar digital applications in india
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
Complications of Minimal Access Surgery at WLH
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Insiders guide to clinical Medicine.pdf
01-Introduction-to-Information-Management.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Pharma ospi slides which help in ospi learning
Sports Quiz easy sports quiz sports quiz
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Renaissance Architecture: A Journey from Faith to Humanism
TR - Agricultural Crops Production NC III.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Anesthesia in Laparoscopic Surgery in India
RMMM.pdf make it easy to upload and study
Cell Structure & Organelles in detailed.
human mycosis Human fungal infections are called human mycosis..pptx
master seminar digital applications in india
2.FourierTransform-ShortQuestionswithAnswers.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025

Using ap is to gather data

  • 1. SMAC LAB, LSU Sep 7, 2018 SMAC Talks Using APIs to Gather Data Instructor: Dr. Ke (Jenny) Jiang
  • 2. Using APIs to Gather Data Installation Download Anaconda Python 3.6 to run Python scripts. Anaconda is free to download. Once you’ve installed Anaconda, you can create/edit scripts in Spyder.
  • 3. Spyder Using APIs to Gather Data Open the files
  • 4. Spyder Using APIs to Gather Data Open the files
  • 5. Spyder Let’s Play.. Copy & Paste the Syntax to the Console Using APIs to Gather Data
  • 6. Using APIs to Gather Data More efficient way to run the Syntax
  • 7. Using APIs to Gather Data Search Text in the Syntax
  • 8. Using APIs to Gather Data The search Results being Highlighted
  • 9. Using APIs to Gather Data Go to “variables_strings-numbers.py” first
  • 10. Using APIs to Gather Data Application Programming Interfaces * allow you to access data or services on other servers on the web URL http://api.nytimes.com/svc/community/v3/user-content/by-date.json returns data when loaded
  • 11. API Documentation * what you can and can't do with the API
  • 12. NYT APIs Documentation http://developer.nytimes.com Community API http://developer.nytimes.com/community_api_v3.json#/README
  • 13. Something to be aware of… * APIs are usually rate limited (not to request data to an api too frequently) * Sign up for an authorization key to use APIs
  • 14. Request an API Key http://developer.nytimes.com Request an API Key
  • 15. Request an API Key Name Email Web Community API Click
  • 16. Find the Requested API Key Click Check Your Mailbox API Key
  • 17. use aip to collect nyt comments.py Download Code:
  • 18. Open the Code in Spyder Click
  • 19. Step 1: Import Packages Step 2: Get Data Copy the string key into the variable api_key Get data in .json format in a specific day (2018-08-31)
  • 20. Step 3: Get Data as a JSON object * We’ve collected 25 comments from the date we specified in the URL * BUT there were many more comments made that day * We want to loop through and collect them all Step 4: Parse it into a Pandas DataFrame
  • 21. Step 5: How Many Comments? *Output: We need to collect 331 times, since we only get 25 comments at a time. * If you are making more than 1,000 calls per day (via an application or any other method) to an individual API, NYT will notice that and assume you're using our API for a commercial purpose. Please contact NYT if you have hit that limit but do not think you are using the API for a commercial purpose.
  • 22. Step 6: Collect All the Comments Slow our script down Line 90: Use your own path to save the comments
  • 23. Step 7: Who Are Most Active? Most active users Users comments >= 5 What kind of comments
  • 24. Step 8: Open Saved Comments