CH3 Intro

1. What to do?

These are 3 aspects:1.REQUESTS Module; 2.API; 3.deal with JSON.

(1) Use requests module to send the request, take the agrument and receive the value result(data) that returns.Read the interface of requests. (2) How to choose the suitable API?To learn what API are and why they're important. (3) The data will be return as the JSON form,how to deal with it?

2.How to do?

(1) Install REQUESTS Module in program from the 3rdParty. use the code:

pip install requests

and then:

 import requests

(2) To construct and send requests, you need to pass parameters in URL,or pass a list of items as a value. (3) Choose the API. API ~ Application Programming Interface

Tips: To choose the suitable API, these principles should be considered:

  1. Dose the API including the python demo?
  2. Is that any limition? Does it free or you have to pay for it?
  3. Is the data reliable?
  4. Try these API : 心知天气/彩云,or OpenWeatherMap as a foreign API.

(4)Response Content as JSON.

  1. How to get the data?
  2. What is JOSN? Why almost API choose josn to delieve data?
  3. How to deal JSON data in python? List or dict?

3.Ready to go?

This week will accord the second principle of Zen of Python : Explicit is better than implicit.

(1)Import the requests/time/json modules. (2)Def the functions,including: data entry and processing module(DMP);"Help/Quit/History" files;deal with the results and convert into string. (3)Use API key to fetch the data as the dict form. (4)Get the data and save is in the search history.

results matching ""

    No results matching ""