Skip to content

Latest commit

 

History

History
71 lines (52 loc) · 2.17 KB

Aqi_Readme.md

File metadata and controls

71 lines (52 loc) · 2.17 KB

##What the script does The script scraps http://aqicn.org mobile page to get the air quality index in big cities.

The results are written in a JSON file (YYYY-MM-DD-HH.json).

This script could be run every hour. ##Files ###Specific files

  • AqiCapture.py
  • AqiCaptor.py
  • FoursquareDatabaseManager.py

###Common files

  • Captor.py
  • FileManager.py
  • ExitLogger.py
  • LoggerBuilder.py

###Additional Python modules

  • requests
  • lxml

###Logs

  • ./logs/aqi.log for complete logs
  • ./logs/aqi-exit.json for time and exit status of the last execution

###Other files and directories

  • ./aqi/ and the sub-folders for each city where the JSON files will be written
  • ./aqi/locations.json

##How to use the script

  1. Copy the files

  2. Create the logs folder

  3. Create the aqi folder and its sub-folders for each city

  4. Create the aqi/locations.json file and write a JSON dictionary where the key is the name of the city and the value is the part of the url associated to this city (the ### in http://aqicn.org/city/####/m/), e.g.:

    {
    	"Paris":"france/paris/paris-centre",
    	"Shanghai":"shanghai",
    	"Beijing":"beijing",
    	"NYC":"usa/newyork"
    }
    
  5. Run the script:

    python AqiCapture.py
    

##Exit status and Errors ###Exit status

  • 0 in case of success
  • 1 in case of an InitError (problem with the ./aqi/locations.json file or with the ./aqi/ folder or sub-folders)
  • 2 in case of a RequestException (e.g. network problem, HTTP error, timeout, too many redirections, etc.)
  • 3 in case of another type of Exception

###Errors InitError: File ./aqi/locations.json is missing => You have forgotten to write the ./aqi/locations.json file

InitError: The ./aqi/locations.json file does not contain any correct JSON object

=> See {How to use the script} to verify that your ./aqi/locations.json file is correctly written and check that you use " instead of ' for your keys and values.

InitError: Folder ./aqi/{city} is missing

=> You need to create a sub_folder in /aqi/ for each city

##Good to know

  • The script uses an anonymous user agent to act like a normal browser.

  • For London and Tokyo, I couldn't decide which AQI specific location to use…