Automating Real World Tasks with Python Week2 Solution

In the final course, we’ll tie together the concepts that you’ve learned up until now. You’ll tackle real-world scenarios in Qwiklab’s that will challenge you to use multiple skills at once. This assignment consist of Qwiklab’s Assessment: “Process Text Files with Python Dictionaries and Upload to Running Web Service”.

First, we’ll take a closer look at how to use external Python modules to extend your code’s capabilities, and spend some time learning how to use documentation to learn a new module. For example, we’ll use the Python Image Library (PIL) to create and modify images.

We’ll show you some simple examples of how to perform common tasks in the course material, but it will be up to you to explore the module documentation to figure out how to solve specific problems. Next, we’ll show you how to communicate with the world outside of your code! You’ll use data serialization to turn in-memory objects into messages that can be sent to other programs.

Your program will send messages across the network to Application Programming Interfaces (APIs) offered by other programs. For those times when your code needs to talk to a person instead of a program, you’ll also learn to send email messages. At the end of this course, you’ll be able to take a description of a problem and use your skills to create a solution — just like you would on the job. In your final capstone project, you’ll be given a description of what your customer needs, and it will be up to you to create a program to do it!

~~SKILLS YOU WILL GAIN~~

  • Serialization
  • Building a Solution
  • Creating and Translating Media Files
  • Interacting with Web Services

Course Link Click here

Qwiklab’s Assessment: “Process Text Files with Python Dictionaries and Upload to Running Web Service

Code:-

Type This in Your VM Shell And This Can Help You To Load You IP-Address:
1. sudo apt-get update
2. sudo apt install python-django-common
3. sudo systemctl start google-startup-scripts.service

				
					#! /usr/bin/env python3

import os
import requests

# Path to the data
path = "/data/feedback/"

keys = ["title", "name", "date", "feedback"]

folder = os.listdir(path)
for file in folder:
    keycount = 0
    fb = {}
    with open(path + file) as fl:
        for line in fl:
            value = line.strip()
            fb[keys[keycount]] = value
            keycount += 1
    print(fb)
    response = requests.post("http:///feedback/",
    json=fb)
print(response.request.body)
print(response.status_code)
				
			

Leave a Reply

Your email address will not be published. Required fields are marked *