The World Clock Scraper is a Python program developed as part of the CS50 Introduction to Python Programming course. It serves the purpose of scraping real-time world clock information from a website, creating a dictionary that pairs city names with their respective times, and offering the choice of presenting the information in either text or audio format using text-to-speech.
Web scraping: The program leverages the BeautifulSoup library for web scraping and extracting world clock data.
Data extraction: It parses the HTML content using lxml to fetch city names and their corresponding times.
Dictionary creation: The program structures the retrieved data into a dictionary, with city names as keys and times as values.
Command-line interface: Users can provide command-line arguments to specify the city and the desired output format.
Text output: It presents city names and current times in text format, enhancing visual representation with ASCII art generated by the pyfiglet library.
Audio output: With the assistance of the pyttsx3 library, the program can convert time information into speech for audio output.
Error handling: The program includes error-handling mechanisms through the sys module to manage situations involving invalid city names and network connection errors.
Dependencies
The World Clock Scraper relies on the following Python libraries:
BeautifulSoup4: Used for web scraping and parsing HTML content.
pyfiglet: Utilized for creating ASCII art to visually represent city names and times.
requests: Employed for making HTTP requests to retrieve website content.
pyttsx3: Used for converting time information into speech for audio output.
sys: Employed for error handling and program termination in the event of exceptions.
Usage
To use the World Clock Scraper, follow these steps:
1. Install the required dependencies by executing pip install -r requirements.txt in your terminal.
2. Run the program with the command python main.py --sound --city [CITY] to obtain both audio and text output, or python main.py --city [CITY] to receive only text output.
3. Replace [CITY] with the name of the desired city to retrieve its current time.
4. The program will display the city name and time in text format. If the --sound flag is provided, it will also vocalize the time using text-to-speech.
Example
To retrieve the current time in New York with both audio and text output, execute the following command:
python project.py --sound --city Bucharest