0% found this document useful (0 votes)
9 views11 pages

Presentation Unix

Uploaded by

coyog64466
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

Presentation Unix

Uploaded by

coyog64466
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

BANGALORE INSTITUTE OF TECHNOLOGY

DEPARTMENT OF INFORMATION SCIENCE AND ENGINEERING


K.R.ROAD, V.V.PURAM, BANGALORE - 560004

UNIX SYSTEM PROGRAMMING(BCS515C)


“Weather Fetcher”
Using Shell Scripting and System Calls in C
Presented By
NAME USN
Hansika S V 1BI22IS033
Harish Chandra Thakur 1BI22IS034
Hemanth M P 1BI22IS035
Indu Gulapalyam 1BI22IS036
INTRODUCTION
The Weather Fetcher project is a simple and practical tool designed to provide real-time
weather information for any city using the OpenWeatherMap API.
The project demonstrates two methods to retrieve and display this weather data:
• first, using shell scripting, which employs command-line tools like curl to make API
requests and jq to parse JSON responses;
• and second, using system calls in C, showcasing how system-level programming can
execute external commands to fetch and process weather data.
This project bridges the gap between scripting and low-level programming, illustrating the
strengths of both approaches
PROBLEM STATEMENT :

The goal of the Weather Fetcher project is to create a tool that allows users to retrieve real-
time weather information for any city. The tool should fetch weather data from the
OpenWeatherMap API and display it in a user-friendly format. The project provides two
methods for fetching the data: one using a shell script and the other using system calls in
C. The user should be able to choose between these two methods to view weather details
such as temperature, humidity, wind speed, and weather description for the selected city.
The project aims to demonstrate the integration of external APIs with both scripting and
system-level programming techniques.
PROPOSED SOLUTION
The Weather Fetcher project will be implemented by integrating the OpenWeatherMap
API to retrieve real-time weather data for any given city. The solution will consist of
two parts: one using shell scripting and the other using system calls in C.
1. Shell Script:
• A shell script will be written to execute the curl command to fetch the weather data
from the OpenWeatherMap API.
• The output will be processed and formatted using the jq tool, which parses the JSON
response to display the weather information in a readable format.
• The script will prompt the user to enter a city name, fetch the weather data, and
display the results, including temperature, humidity, wind speed, and weather
description.
2.System Calls in C Method:

• A C program will be created that uses system calls to execute the same curl command
from within the C code.

• The program will open a pipe using the popen function to execute the command and read
its output.

• The output will be processed using the fgets function, and the weather information will
be displayed to the user.

Both methods will allow the user to view the weather data by simply entering a city name.
The solution will provide flexibility, showing how weather data can be retrieved using both
a higher-level shell scripting approach and a lower-level system programming approach.
Flow Chart
1. Start the Program
2.Display Main Menu
3. User Chooses an Option
4. Option 1 - Shell Script
5. Option 2 - System Calls
6.Option 3-Exit
6. Handle Invalid Choices
METHODS

1. Shell Script Execution


• Method:Executes a shell script using the system() function in C.
• Purpose: The shell script fetches weather data using curl and processes the response with jq to
display the data in a readable format.
• Key Function: system("./fetch_weather_shell.sh");
2. System Calls in C:
a. Method: Uses system calls and external command execution (popen, fgets) to fetch and process
weather data.
b. Steps Involved:
• User Input: Reads the city name using scanf().
• Command Construction: Constructs a curl command to fetch weather data from the
OpenWeatherMap API.

• Command Execution: Executes the curl command with popen() to fetch the API response.

• Output Reading: Reads the response line by line using fgets() and displays it.

3. Menu Display:
• Method: Uses printf() to display a menu to the user and scanf() to capture the user's
choice.
• Purpose: Provides an interactive interface for the user to select between fetching weather
data via the shell script or system calls.
4.String Manipulation:
• Method: Uses snprintf() to safely construct the API call command string.
• Purpose: Avoids buffer overflows by limiting the size of the constructed string.
RESULTS:
Conclusion

In conclusion, the weather dashboard program demonstrates a practical and efficient way
to fetch and display real-time weather information using both shell scripting and system
calls in C. By integrating external tools like `curl` and `jq`, it effectively processes and
presents data from the OpenWeatherMap API in a user-friendly format. The program
highlights essential programming concepts such as menu-driven interaction, string
manipulation, command execution, and error handling. This project serves as an excellent
example of leveraging both scripting and programming approaches to achieve a seamless
and interactive user experience.
Thank
you

You might also like