Skip to content
This repository was archived by the owner on Jun 29, 2024. It is now read-only.
Open
43 changes: 43 additions & 0 deletions ManaswiniPeddi/task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
mport requests

def get_weather_data(api_key, city_name):
url = f"http://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={api_key}&units=metric"
response = requests.get(url)
data = response.json()
return data

def display_current_weather(data):
print("Current Weather Conditions:")
print("---------------------------")
print(f"Weather: {data['weather'][0]['description']}")
print(f"Temperature: {data['main']['temp']}°C")
print(f"Humidity: {data['main']['humidity']}%")
print(f"Wind Speed: {data['wind']['speed']} m/s")

def get_forecast(api_key, city_name):
url = f"http://api.openweathermap.org/data/2.5/forecast?q={city_name}&appid={api_key}&units=metric"
response = requests.get(url)
data = response.json()
return data

def display_forecast(data):
print("\nWeather Forecast for the next 5 days:")
print("-------------------------------------")
for forecast in data['list']:
print(f"Date: {forecast['dt_txt']}")
print(f"Weather: {forecast['weather'][0]['description']}")
print(f"Temperature: {forecast['main']['temp']}°C")
print("")

def main():
api_key = 'b73f861c9b47fe465e680a5d330e01eb'
city_name = input("Enter city name: ")

current_weather_data = get_weather_data(api_key, city_name)
display_current_weather(current_weather_data)

forecast_data = get_forecast(api_key, city_name)
display_forecast(forecast_data)

if _name_ == "_main_":
main()
5 changes: 5 additions & 0 deletions MeghanaK/output1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Title
S,e,a,r,c,h, ,c,o,d,e,",", ,r,e,p,o,s,i,t,o,r,i,e,s,",", ,u,s,e,r,s,",", ,i,s,s,u,e,s,",", ,p,u,l,l, ,r,e,q,u,e,s,t,s,.,.,.
P,r,o,v,i,d,e, ,f,e,e,d,b,a,c,k
S,a,v,e,d, ,s,e,a,r,c,h,e,s
L,e,t,’,s, ,b,u,i,l,d, ,f,r,o,m, ,h,e,r,e
43 changes: 43 additions & 0 deletions MeghanaK/task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import requests

def get_weather_data(api_key, city_name):
url = f"http://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={api_key}&units=metric"
response = requests.get(url)
data = response.json()
return data

def display_current_weather(data):
print("Current Weather Conditions:")
print("---------------------------")
print(f"Weather: {data['weather'][0]['description']}")
print(f"Temperature: {data['main']['temp']}°C")
print(f"Humidity: {data['main']['humidity']}%")
print(f"Wind Speed: {data['wind']['speed']} m/s")

def get_forecast(api_key, city_name):
url = f"http://api.openweathermap.org/data/2.5/forecast?q={city_name}&appid={api_key}&units=metric"
response = requests.get(url)
data = response.json()
return data

def display_forecast(data):
print("\nWeather Forecast for the next 5 days:")
print("-------------------------------------")
for forecast in data['list']:
print(f"Date: {forecast['dt_txt']}")
print(f"Weather: {forecast['weather'][0]['description']}")
print(f"Temperature: {forecast['main']['temp']}°C")
print("")

def main():
api_key = 'b73f861c9b47fe465e680a5d330e01eb'
city_name = input("Enter city name: ")

current_weather_data = get_weather_data(api_key, city_name)
display_current_weather(current_weather_data)

forecast_data = get_forecast(api_key, city_name)
display_forecast(forecast_data)

if __name__ == "__main__":
main()
48 changes: 48 additions & 0 deletions MeghanaK/task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import requests
from bs4 import BeautifulSoup
import csv
import json

def scrape_website(url):
# Send a GET request to the URL
response = requests.get(url)

# Parse HTML content
soup = BeautifulSoup(response.text, 'html.parser')

titles = [title.text.strip() for title in soup.find_all('h1')]

return titles

def save_to_csv(data, filename):
# Write data to a CSV file
with open(filename, 'w', newline='', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Title'])
writer.writerows(data)

def save_to_json(data, filename):
# Write data to a JSON file
with open(filename, 'w', encoding='utf-8') as jsonfile:
json.dump(data, jsonfile, indent=4)

def main( ):
url = input("Enter the URL of the website you want to scrape: ")


output_format = input("Enter 'csv' or 'json' to choose the output format: ").lower()
if output_format not in ['csv','json']:
print("Invalid output format. Please enter 'csv' or 'json'.")
return
extracted_data = scrape_website(url)
if output_format == 'csv':
filename = input("Enter the filename to store the data (without extension): ") + '.csv'
save_to_csv(extracted_data, filename)
print(f"Data has been saved to {filename}")
elif output_format == 'json':
filename = input("Enter the filename to store the data (without extension): ") + '.json'
save_to_json(extracted_data, filename)
print(f"Data has been saved to {filename}")
if __name__ == "__main__":
main()

28 changes: 28 additions & 0 deletions MeghanaK/task3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import nltk
from nltk.chat.util import Chat, reflections

# Define patterns and responses
patterns = [
(r'hi|hello|hey', ['Hello!', 'Hi there!', 'Hey!']),
(r'how are you?', ["I'm doing well, thank you!", "I'm great, thanks for asking!"]),
(r'what is your name?', ["I'm just a simple chatbot.", "I'm a chatbot designed to assist you."]),
(r'bye|goodbye', ["Goodbye!", "See you later!", "Bye!"]),
# Add more patterns and responses as needed
]

# Create a chatbot
chatbot = Chat(patterns, reflections)

# Define a function to chat with the user
def chat():
print("Hello! How can I assist you today?")
while True:
user_input = input("> ")
response = chatbot.respond(user_input)
print(response)
if user_input.lower() == 'bye':
break

# Start the chat
if __name__ == "__main__":
chat()
35 changes: 35 additions & 0 deletions MeghanaK/task4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import PyPDF2
import os

def merge_pdfs(input_paths, output_path):
pdf_writer = PyPDF2.PdfWriter()

for path in input_paths:
pdf_reader = PyPDF2.PdfReader(path)
for page in pdf_reader.pages:
pdf_writer.add_page(page)

with open(output_path, 'wb') as out_pdf:
pdf_writer.write(out_pdf)

def split_pdf(input_path, output_folder):
pdf_reader = PyPDF2.PdfReader(input_path)

for i, page in enumerate(pdf_reader.pages):
pdf_writer = PyPDF2.PdfWriter()
pdf_writer.add_page(page)

output_path = os.path.join(output_folder, f'page_{i+1}.pdf')
with open(output_path, 'wb') as out_pdf:
pdf_writer.write(out_pdf)

# Example usage:
# Merge PDFs
input_files = ['file1.pdf', 'file2.pdf']
output_merged = 'merged.pdf'
merge_pdfs(input_files, output_merged)

# Split PDF
input_pdf = 'large_file.pdf'
output_folder = 'split_pages'
split_pdf(input_pdf, output_folder)