Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit 56130f8

Browse files
Merge pull request #4 from lokeshR2004/main
Updated tasks
2 parents a094f10 + 7dea503 commit 56130f8

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

‎R.LOKESH/task5/weatherapp.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import requests
2+
import json
3+
4+
def fetch_weather_data(api_key, city):
5+
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
6+
response = requests.get(url)
7+
data = response.json()
8+
return data
9+
10+
def display_weather(data):
11+
print("Current Weather Conditions:")
12+
print("---------------------------")
13+
print(f"Weather: {data['weather'][0]['description']}")
14+
print(f"Temperature: {data['main']['temp']}°C")
15+
print(f"Humidity: {data['main']['humidity']}%")
16+
print(f"Wind Speed: {data['wind']['speed']} m/s")
17+
18+
def main():
19+
api_key = "YOUR_API_KEY"
20+
city = input("Enter city name: ")
21+
weather_data = fetch_weather_data(api_key, city)
22+
if weather_data['cod'] == 200:
23+
display_weather(weather_data)
24+
else:
25+
print("Error fetching weather data. Please check your input.")
26+
27+
if __name__ == "__main__":
28+
main()

‎R.LOKESH/task6/webscrapper.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
import csv
4+
5+
def scrape_website(url):
6+
# Send a GET request to the URL
7+
response = requests.get(url)
8+
9+
# Check if request was successful (status code 200)
10+
if response.status_code == 200:
11+
# Parse the HTML content of the page
12+
soup = BeautifulSoup(response.text, 'html.parser')
13+
14+
# Find the elements containing the data you want to extract
15+
# Replace 'example' with actual HTML tags and classes/IDs
16+
data_elements = soup.find_all('div', class_='example')
17+
18+
# Extract data from the elements and store in a list of dictionaries
19+
scraped_data = []
20+
for element in data_elements:
21+
# Example: Extract text from a specific tag within the element
22+
data = {
23+
'title': element.find('h2').text.strip(),
24+
'description': element.find('p').text.strip()
25+
}
26+
scraped_data.append(data)
27+
28+
return scraped_data
29+
else:
30+
print("Error: Failed to fetch website")
31+
return []
32+
33+
def save_to_csv(data, filename):
34+
# Define CSV header based on keys of the first dictionary in the list
35+
fields = list(data[0].keys())
36+
37+
# Write data to CSV file
38+
with open(filename, 'w', newline='') as csvfile:
39+
writer = csv.DictWriter(csvfile, fieldnames=fields)
40+
41+
# Write header
42+
writer.writeheader()
43+
44+
# Write rows
45+
for row in data:
46+
writer.writerow(row)
47+
48+
def main():
49+
url = "https://example.com"
50+
filename = "data.csv"
51+
52+
# Scrape website
53+
scraped_data = scrape_website(url)
54+
55+
# Save data to CSV
56+
save_to_csv(scraped_data, filename)
57+
58+
print(f"Data has been scraped and saved to {filename}")
59+
60+
if __name__ == "__main__":
61+
main()

‎R.LOKESH/task7/chatbot.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import nltk
2+
from nltk.chat.util import Chat, reflections
3+
4+
# Define pairs of patterns and responses
5+
pairs = [
6+
(r"hi|hello|hey", ["Hello!", "Hi there!", "Hey!"]),
7+
(r"how are you?", ["I'm doing well, thank you!", "I'm good, thanks for asking."]),
8+
(r"what is your name?", ["My name is Chatbot.", "I'm Chatbot, nice to meet you!"]),
9+
(r"bye|goodbye", ["Goodbye!", "See you later!", "Bye!"]),
10+
(r"(.*)", ["I'm sorry, I don't understand."])
11+
]
12+
13+
# Create a chatbot using the defined pairs
14+
chatbot = Chat(pairs, reflections)
15+
16+
# Start the conversation loop
17+
print("Chatbot: Hello! I'm Chatbot. How can I help you today?")
18+
while True:
19+
user_input = input("You: ")
20+
response = chatbot.respond(user_input)
21+
print("Chatbot:", response)

‎R.LOKESH/task8/pdfmerger.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import PyPDF2
2+
3+
def merge_pdfs(input_files, output_file):
4+
merger = PyPDF2.PdfFileMerger()
5+
for input_file in input_files:
6+
merger.append(input_file)
7+
merger.write(output_file)
8+
merger.close()
9+
print(f"PDF files merged successfully into {output_file}")
10+
11+
def split_pdf(input_file, output_prefix):
12+
input_pdf = PyPDF2.PdfFileReader(input_file)
13+
for page_number in range(input_pdf.numPages):
14+
output_pdf = PyPDF2.PdfFileWriter()
15+
output_pdf.addPage(input_pdf.getPage(page_number))
16+
output_filename = f"{output_prefix}_{page_number + 1}.pdf"
17+
with open(output_filename, "wb") as output_file:
18+
output_pdf.write(output_file)
19+
print(f"Page {page_number + 1} split into {output_filename}")
20+
21+
def main():
22+
# Merge PDF files
23+
input_files = ["input1.pdf", "input2.pdf", "input3.pdf"]
24+
merge_output_file = "merged_output.pdf"
25+
merge_pdfs(input_files, merge_output_file)
26+
27+
# Split PDF file
28+
input_file = "input.pdf"
29+
split_output_prefix = "split_output"
30+
split_pdf(input_file, split_output_prefix)
31+
32+
if __name__ == "__main__":
33+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /