Giter Site home page Giter Site logo

class7-python-module-week3's Introduction

Class7-Python-Module-Week3

Random User Creator App

We are going to create an app which will make an API call to http://jsonplaceholder.typicode.com/users and get a list of random users. Then our app will clean up the returned list of users and store them in a .json file.

Steps to follow:

Create an API function:

  • Import necessary library for making an API call.
  • Make the API call to this URL -> http://jsonplaceholder.typicode.com/users
  • Check the status code, return object (res.json())
  • Wrap the API function in try/except block.
  • Return the return object.

Create a cleanup function:

  • Take the return object as parameter and transform the return object. (Before starting with transforming this return object, check its data type as it may not be a dictionary. Plan your code according to its data type)
  • Create a new Python dictionary containing all 10 users and their details from the return object. (Items to be included: id, name, username, email)
  • Return the Python dictionary

Creata a function to write the users dictionary to a .json file:

  • Take a dictionary as the parameter
  • Open up a new file (or create if it isn't existing)
  • Dump the Python dictionary into this file

Create a main.py file:

  • Import all your modules
  • Create the main app logic here

Things to remember:

  • Use a virtual environment.
  • Create separate functions for all the steps.
  • Modularize your code (either create a separate file for each function or create a file called utils.py and store all the functions in this file)
  • Wrap the necessary parts of your functions in try/except blocks.
  • Create a requirements.txt file at the end of your project to store all the dependancy information. (pip freeze > requirements.txt)

class7-python-module-week3's People

Contributors

sigma21 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.