#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Felix Muzny 11/22/2022 DS 2000 Lecture 21 - JSON and APIs Logistics: - Do what you need to do for yourself over break - OH for the rest of the semester - 4 - 8pm - we're happy to help you with DS 2001 projects AND expect to explain your project/goal to the TA a bit to get help to start with :) - remote attendance (https://bit.ly/remote-ds2000-muzny) Three ways to participate in multiple choice questions 1) via the PollEverywhere website: https://pollev.com/muzny 2) via text: text "muzny" to the number 22333 to join the session 3) via Poll Everywhere app (available for iOS or Android) """ """ Warm-up 0 ---- What is your favorite kind of pie? A. A savory pie! B. Apple! C. I'm team berries! D. Peaches! E. I don't love pie. """ """ Getting information from the internet: APIs --- Application Programming Interface Let's talk about Twitter (No, for real, let's talk about Twitter) To use an API: 1) Look up the url that you'll be talking to ("endpoint") 2) Look up the kind of request that you'll be making 3) Look up whether or not you need to authenticate yourself first -> https://requests.readthedocs.io/en/latest/user/authentication/ 4) Send your request and hope that your response comes back To send requests in python: requests library documentation: https://pypi.org/project/requests/ Felix also likes this documentation: https://requests.readthedocs.io/en/latest/ The API that we'll be talking to today: Poke API documentation: https://pokeapi.co/docs/v2#pokemon """ import requests # r = requests.get('https://pokeapi.co/api/v2/pokemon/squirtle') """ JSON --- Javascript Object Notation python_object = json.loads(string) """ import json # poke_dict = json.loads(r.text) # make a pokemon based on the actual stats of a pokemon # make it so that we can give it different health, attack, and name """ Writing a larger program - pokemon_part2.py --- Update our Pokemon battle program so that it: 1) prompts the user for the names of two pokemon to battle 2) Creates Pokemon with the appropriate health, attack, and name from the information given by the Pokemon API 3) Battles the Pokemon and gives a nicely formatted display """ """ For Post-break DS 2000, would you prefer lecture focus on... (there will be some of all of these, but I can shift the *focus*) --- A. Programming concepts B. Real world data science applications C. Visualization concepts D. idk? *shrug* """ # Next Time # --- # - Cool data science applications # - Pandas # - DataFrames