This project is a web-based application that allows users to explore, filter, compare, and manage a shopping cart for phones scraped from multiple online web stores. The application provides features such as currency conversion, PDF export, and real-time cart updates. The backend is powered by Flask and SQLite, while the frontend is built with HTML, CSS, and JavaScript.
website link -> https://omerelshly11.pythonanywhere.com/
📊 Total Features Overview The platform includes 14 main features across different areas, with hosting, categorized as follows:
-
Web Scraping: Extracting phone data from multiple web stores to collect raw data efficiently.
-
CSV Export: Storing cleaned and organized data into CSV files for backup and easy transfer.
-
Data Cleaning: Handling missing values, fixing inconsistencies, and standardizing formats to ensure data accuracy and reliability.
-
Data Organization: Categorizing data into structured tables for easier database integration and queries.
-
Adding Unique IDs: Assigning unique IDs to phones for maintaining relationships across different data tables.
-
Database Creation: Importing the CSV data into an SQLite database with proper relationships for structured storage and retrieval.
- Homepage: Displays a list of all available phones with pagination and highlights for new or featured items.
- Search Functionality: Enables users to search phones by name or keyword for quick access to desired models.
- Filter Functionality: Allows users to filter phones by criteria such as:
- Brand: Focus on phones from specific manufacturers.
- Webstore: View availability on a preferred online store.
- Price range: Find phones within a budget-friendly range.
- Phone Details Page: Shows detailed specifications, prices, and brand information for a selected phone, including promotions and savings.
- Comparison Page:
- Compare up to 4 phones side by side.
- Highlight specifications, prices, and promotions for informed decision-making.
- Shopping Cart Page:
- Add or remove phones seamlessly.
- View the total price with a breakdown of items.
- Perform currency conversion specifically for eBay listings (e.g., USD → EGP).
- PDF Export for Comparison:
- Error Handling
- Generate a downloadable PDF comparison report of selected phones for offline viewing using the WeasyPrint library.
- Also, return
No phone selected for comparison
when there is no phone to export as pdf.@app.route('/export_comparison', methods=['GET']) def export_comparison(): # Check if compare list exists in the session if 'compare_list' not in session or len(session['compare_list']) == 0: return "No phones selected for comparison.", 400 # Retrieve the phone details for the comparison phone_ids = session['compare_list'] phones = Info.query.filter(Info.id.in_(phone_ids)).all() phone_details = [] for phone in phones: details = Details.query.filter_by(details_id=phone.id).first() price = Price.query.filter_by(price_id=phone.id).first() brand = Brand.query.filter_by(brand_id=phone.id).first() rating = Rating.query.filter_by(ratings_id=phone.id).first() phone_details.append({ 'phone': phone, 'details': details, 'price': price, 'brand': brand, 'rating': rating }) html_content = render_template('compare.html', phone_details=phone_details, for_pdf=True) css_path = os.path.join(basedir, 'static', 'pdf_styles.css') try: pdf_css = CSS(filename=css_path) except FileNotFoundError: return "CSS file not found. Please ensure the static/pdf_styles.css file exists.", 500 # Generate the PDF using WeasyPrint with the custom CSS pdf = HTML(string=html_content).write_pdf(stylesheets=[pdf_css]) response = make_response(pdf) response.headers['Content-Type'] = 'application/pdf' response.headers['Content-Disposition'] = 'attachment; filename=comparison.pdf' return response
- Dynamic Cart Management:
- Update cart contents in real time using AJAX
document.querySelectorAll('.remove-button').forEach(button => { button.addEventListener('click', () => { const phoneId = button.getAttribute('data-phone-id'); fetch('/remove_from_cart', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ phone_id: phoneId }), }) .then(response => response.json()) .then(data => { if (data.success) { button.closest('.cart-item').remove(); location.reload(); // Reload to update total price } else { alert(data.error); } }); }); });
@app.route('/remove_from_cart', methods=['POST']) def remove_from_cart(): data = request.json phone_id = data.get('phone_id') if not phone_id: return jsonify({'error': 'Phone ID is required'}), 400 # Ensure cart exists in session if 'cart' not in session: session['cart'] = [] cart = session['cart'] if phone_id in cart: cart.remove(phone_id) session['cart'] = cart session.modified = True return jsonify({'success': True}) else: return jsonify({'error': 'Phone not found in cart'}), 400
- Update cart contents in real time using AJAX
- Framework: Flask
- Database: SQLite
- Data Handling: Python for cleaning and organizing data
- HTML: Structure of the web pages
- CSS: Styling for a user-friendly interface
- JavaScript: Dynamic cart updates and user interactions
- Flask: For routing and backend logic
- SQLAlchemy: ORM for database interactions
- WeasyPrint: PDF generation for comparison reports
- jQuery: AJAX requests for cart updates
- Clone the repository:
git clone https://github.com/yourusername/project.git
- Navigate to the project directory:
cd project
- Install required Python packages:
Flask Flask-SQLAlchemy WeasyPrint selenium beautifulsoup4 undetected-chromedriver pandas re concurrent.futures threading
- Run the application:
python app.py
- Open the application in your browser at
http://127.0.0.1:5000/
.
- Add user authentication for personalized experiences.
- Enable real-time currency conversion with API integration.
- Improve the UI with modern frameworks like React or Vue.js.
- Enhance filtering options with more criteria.
- Flask: For its simplicity and flexibility.
- WeasyPrint: For enabling seamless PDF generation.
- SQLite: For lightweight database management.
- jQuery: For facilitating AJAX operations.