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

Ayushh0406 patch 57 #3242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ayushh0406 wants to merge 134 commits into avinashkranjan:main from ayushh0406:ayushh0406-patch-57

Conversation

Copy link

@ayushh0406 ayushh0406 commented Jul 27, 2025
edited by sourcery-ai bot
Loading

Description

Please include a summary of the change and which issue is fixed. List any dependencies that are required for this change.

Fixes #(issue_no)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Documentation Update

Checklist:

  • My code follows the style guidelines(Clean Code) of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have created a helpful and easy to understand README.md
  • My documentation follows Template for README.md
  • I have added the project meta data in the PR template.
  • I have created the requirements.txt file if needed.

Project Metadata

If there is no-file/nothing to fill the below fields with, then type: none

Example: If no requirements.txt needed/present, then type none in Requirments.

Category:

  • Calculators
  • AI/ML
  • Scrappers
  • Social_Media
  • PDF
  • Image_Processing
  • Video_Processing
  • Games
  • Networking
  • OS_Utilities
  • Automation
  • Cryptography
  • Computer_Vision
  • Fun
  • Others

Title: <write script title here>

Folder: <type the folder name that contains your script>

Requirements: <type the name of text file containing the required to install python packages, type None if no file required>

Script: <Enter the name of the .py file (The main entry point of the program)>

Arguments: <enter any arguments that the script needs but - separeted like: h-c-m>

Contributor: <Enter your Github handle/username without url>

Description: <Enter a one line description that describes your script. Also, explain the arguments usage here>

Summary by Sourcery

Refactor and modernize multiple Python utility and learning scripts by improving code organization, error handling, logging, and input validation.

Enhancements:

  • Modularize Chess Game with dynamic image loading, simplified drawing routines, and a streamlined main loop
  • Convert Address-Book into an AddressBook class with encapsulated DB operations, UI setup, validation, and error dialogs
  • Integrate structured logging into the hash cracker for progress reporting and remove verbose inline docstrings
  • Standardize Selenium-based scrapers and automation scripts (Coursera, LinkedIn, Cookie Clicker) with consistent exception handling, driver teardown, and updated selectors
  • Add input validation, error feedback, and rounding improvements to utility scripts (BMI calculator, age calculator, number guessing)
  • Clean up imports, remove dead code, and apply uniform formatting across dozens of mini-projects

ayushh0406 and others added 30 commits February 17, 2025 00:56
These changes introduce logging for better tracking and debugging, ensuring the progress of the cracking process is efficiently logged. Additionally, you can explore multithreading, GUI development, or other enhancements based on your needs
Refining the Drum Pattern: Let's create a more complex drum pattern for a richer accompaniment.
Adding More Genres and Chord Progressions: Expanding the available genres and their chord progressions.
Enhancing Error Handling: Improving the robustness of user input validation.
This code provides a basic setup for a graphical chess board using pygame. From here, you can expand the functionality to include piece movement, game rules, and player interaction.
Exception Handling: Added try-except blocks to catch and display errors during the main processes.
Text Cleanup: Removed commas from numbers for easier conversion to integers.
Driver Cleanup: Added a finally block to ensure the WebDriver quits even if an error occurs.
ayushh0406 added 26 commits May 2, 2025 22:27
Copy link

sourcery-ai bot commented Jul 27, 2025
edited
Loading

Reviewer's Guide

This PR applies broad refactoring and stability improvements across multiple utility scripts, focusing on modularization, consistent error handling, proper resource cleanup, logging integration, and validation enhancements.

Class diagram for refactored AddressBook application

classDiagram
 class AddressBook {
 - root
 - list_of_names
 - name
 - number
 - conn
 + __init__(root)
 + create_connection(db_file)
 + create_table()
 + on_click_added()
 + on_click_deleted()
 + create_task()
 + validate_input()
 + show_error(message)
 + select_task_by_name()
 + update_task()
 + delete_task()
 + select_all_tasks()
 + exit_app()
 + reset_fields()
 + setup_ui()
 }
Loading

Class diagram for refactored Cracker class with logging

classDiagram
 class Cracker {
 - __charset
 - __curr_iter
 - __prev_iter
 - __curr_val
 - __progress_interval
 - __progress_timer
 - __hash_type
 - __hash
 - __hashers
 - logger
 + __init__(hash_type, hash, charset, progress_interval)
 + __init_logger()
 + __init_hasher()
 + __encode_utf16le(data)
 + __search_space(charset, maxlength)
 + __attack(q, max_length)
 + start_reporting_progress()
 + stop_reporting_progress()
 + work(work_q, done_q, max_length)
 }
Loading

Class diagram for refactored Courses scraper

classDiagram
 class Courses {
 - keyword
 - page_count
 + __init__(keyword, page_count)
 - __scrape_page()
 + scrape_all()
 }
Loading

Class diagram for refactored Cookie Clicker automation

classDiagram
 class CookieClicker {
 + cookie_click()
 + purchase_item()
 }
Loading

Class diagram for refactored Auto-LinkedIn script

classDiagram
 class AutoLinkedIn {
 + main()
 + login(username_input, password_input)
 + goto_network()
 + send_requests(n)
 }
Loading

File-Level Changes

Change Details Files
Modular rewrite of Chess game application
  • Introduce constants for board dimensions and colors
  • Encapsulate image loading, board drawing, and piece rendering into dedicated functions
  • Replace monolithic event loop and state management with a simplified 2D board representation and main() entry point
Chess-Game/main.py
Convert Address Book to class-based design with improved validation
  • Wrap database logic and UI setup into an AddressBook class
  • Implement input validation and error dialogs for name/phone fields
  • Enforce unique-name constraint and update list_of_names dynamically
Address-Book/addressbook.py
Integrate logging into hash cracker and remove inline prints
  • Initialize a logger with stream handler and formatted output
  • Replace progress and completion print statements with logger.info calls
  • Strip out large docstring blocks to streamline methods
9_Typesof_Hash_Craker/9_Types_of_Hash_Cracker.py
Enhance Coursera scraper with cleaned-up selectors and robust exception handling
  • Condense driver initialization into a single line
  • Merge repeated script executions into list comprehensions
  • Add exception message capture and ensure driver.quit() in a finally block
Coursera Scraper/courses.py
Refactor LinkedIn automation for service-based driver setup and error resilience
  • Use selenium Service API to initialize WebDriver
  • Parameterize login credentials and add sleep delays post-actions
  • Wrap navigation and click routines in try/except with error logging
Auto-Linkedin/Auto-LinkedIn.py
Add error handling and cleanup to Cookie Clicker automation
  • Surround click loops and purchase logic with try/except blocks
  • Parse cookie count and price strings robustly (handle commas)
  • Ensure driver.quit() is called in a finally clause
Cookie_Clicker/main.py
Standardize imports and add missing dependencies across scripts
  • Insert missing imports such as os, pandas, matplotlib, logging, etc.
  • Remove unused imports and commented example code
  • Update readme headings and typos in Markdown files
Bag of words model/bow.py
Age_Calculator/Age_Calculator.py
BMI Calculator/app.py
AI Based Music Composer/music_composer.py
Birthday Wisher Bot/main.py
AI_Guess_a_number/Guess_a_number.py
Gmplot-Track the Route/main.py
Coding Language Learning Game/coding_language_learning_game.py
Binary-Calculator-GUI/script.py
Dev.to Scraper/scraper.py
Facebook-Autologin/facebookAuto.py
Fleury-Algorithm/README.md
Icc_ranking_scraper/rankings.py
Amazon Price Tracker/script.py
Auto_Backup/Auto_Backup.py
... and several other utility scripts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ayushh0406 - I've reviewed your changes - here's some feedback:

  • This PR bundles refactors for too many unrelated scripts—consider splitting it into smaller, focused PRs so each module can be reviewed and tested independently.
  • In AddressBook.create_task, if a name already exists the method exits silently—add an error dialog or message so the user knows why the action didn’t complete.
  • The Cracker.__init_logger method adds a new handler on every instantiation, leading to duplicate log entries—move logger setup to the module level or guard against adding handlers more than once.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- This PR bundles refactors for too many unrelated scripts—consider splitting it into smaller, focused PRs so each module can be reviewed and tested independently.
- In AddressBook.create_task, if a name already exists the method exits silently—add an error dialog or message so the user knows why the action didn’t complete.
- The Cracker.__init_logger method adds a new handler on every instantiation, leading to duplicate log entries—move logger setup to the module level or guard against adding handlers more than once.
## Individual Comments
### Comment 1
<location> `Chess-Game/main.py:50` </location>
<code_context>
+
+def main():
+ clock = pygame.time.Clock()
+ board = [
+  ['br', 'bn', 'bb', 'bq', 'bk', 'bb', 'bn', 'br'],
+  ['bp', 'bp', 'bp', 'bp', 'bp', 'bp', 'bp', 'bp'],
+  ['--', '--', '--', '--', '--', '--', '--', '--'],
+  ['--', '--', '--', '--', '--', '--', '--', '--'],
+  ['--', '--', '--', '--', '--', '--', '--', '--'],
+  ['--', '--', '--', '--', '--', '--', '--', '--'],
+  ['wp', 'wp', 'wp', 'wp', 'wp', 'wp', 'wp', 'wp'],
+  ['wr', 'wn', 'wb', 'wq', 'wk', 'wb', 'wn', 'wr']
+ ]
+
</code_context>
<issue_to_address>
The board initialization places the queen and king in non-standard positions for white and black.
The queen and king positions are reversed from standard chess. Swap their positions so the queen is on her own color for both white and black.
</issue_to_address>
### Comment 2
<location> `Address-Book/addressbook.py:53` </location>
<code_context>
+  tkinter.messagebox.showinfo("Info", f"{self.name.get()} got deleted")
+
+ def create_task(self):
+  if self.name.get() in self.list_of_names or not self.validate_input():
+  return
</code_context>
<issue_to_address>
The create_task method silently returns if the name already exists, without user feedback.
Consider displaying an error message or dialog to inform users when a duplicate name is entered.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
 def create_task(self):
 if self.name.get() in self.list_of_names or not self.validate_input():
 return
=======
 def create_task(self):
  if self.name.get() in self.list_of_names:
  tkinter.messagebox.showerror("Error", f"The name '{self.name.get()}' already exists.")
  return
  if not self.validate_input():
  return
>>>>>>> REPLACE

</suggested_fix>
### Comment 3
<location> `Address-Book/addressbook.py:67` </location>
<code_context>
+  print(e)
+
+ def validate_input(self):
+  if not self.name.get() or not self.number.get() or len(self.number.get()) != 10:
+  self.show_error("Name and Phone Number must be valid and Phone Number should be 10 digits.")
+  return False
</code_context>
<issue_to_address>
Phone number validation only checks length, not numeric content.
Please add a check to ensure the phone number contains only digits, not just the correct length.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
 def validate_input(self):
 if not self.name.get() or not self.number.get() or len(self.number.get()) != 10:
 self.show_error("Name and Phone Number must be valid and Phone Number should be 10 digits.")
 return False
 return True
=======
 def validate_input(self):
  number = self.number.get()
  if (
  not self.name.get()
  or not number
  or len(number) != 10
  or not number.isdigit()
  ):
  self.show_error("Name and Phone Number must be valid and Phone Number should be 10 digits (numbers only).")
  return False
  return True
>>>>>>> REPLACE

</suggested_fix>
### Comment 4
<location> `9_Typesof_Hash_Craker/9_Types_of_Hash_Cracker.py:25` </location>
<code_context>
 self.__hash_type = hash_type
 self.__hash = hash
 self.__hashers = {}
+  self.__init_logger()
+
+ def __init_logger(self):
</code_context>
<issue_to_address>
Logger initialization adds a new handler every time a Cracker is instantiated.
This can cause duplicate log messages. Please check for existing handlers before adding a new one.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

sourcery-ai[bot] reacted with thumbs up emoji sourcery-ai[bot] reacted with thumbs down emoji
Comment on lines +50 to +58
board = [
['br', 'bn', 'bb', 'bq', 'bk', 'bb', 'bn', 'br'],
['bp', 'bp', 'bp', 'bp', 'bp', 'bp', 'bp', 'bp'],
['--', '--', '--', '--', '--', '--', '--', '--'],
['--', '--', '--', '--', '--', '--', '--', '--'],
['--', '--', '--', '--', '--', '--', '--', '--'],
['--', '--', '--', '--', '--', '--', '--', '--'],
['wp', 'wp', 'wp', 'wp', 'wp', 'wp', 'wp', 'wp'],
['wr', 'wn', 'wb', 'wq', 'wk', 'wb', 'wn', 'wr']
Copy link

@sourcery-ai sourcery-ai bot Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: The board initialization places the queen and king in non-standard positions for white and black.

The queen and king positions are reversed from standard chess. Swap their positions so the queen is on her own color for both white and black.

sourcery-ai[bot] reacted with thumbs up emoji sourcery-ai[bot] reacted with thumbs down emoji
Comment on lines +52 to 55
def create_task(self):
if self.name.get() in self.list_of_names or not self.validate_input():
return

Copy link

@sourcery-ai sourcery-ai bot Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The create_task method silently returns if the name already exists, without user feedback.

Consider displaying an error message or dialog to inform users when a duplicate name is entered.

Suggested change
def create_task(self):
if self.name.get() in self.list_of_names or not self.validate_input():
return
def create_task(self):
if self.name.get() in self.list_of_names:
tkinter.messagebox.showerror("Error", f"The name '{self.name.get()}' already exists.")
return
if not self.validate_input():
return

sourcery-ai[bot] reacted with thumbs up emoji sourcery-ai[bot] reacted with thumbs down emoji
Comment on lines +66 to +70
def validate_input(self):
if not self.name.get() or not self.number.get() or len(self.number.get()) != 10:
self.show_error("Name and Phone Number must be valid and Phone Number should be 10 digits.")
return False
return True
Copy link

@sourcery-ai sourcery-ai bot Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Phone number validation only checks length, not numeric content.

Please add a check to ensure the phone number contains only digits, not just the correct length.

Suggested change
def validate_input(self):
if not self.name.get() or not self.number.get() or len(self.number.get()) != 10:
self.show_error("Name and Phone Number must be valid and Phone Number should be 10 digits.")
return False
return True
def validate_input(self):
number = self.number.get()
if (
not self.name.get()
or not number
or len(number) != 10
or not number.isdigit()
):
self.show_error("Name and Phone Number must be valid and Phone Number should be 10 digits (numbers only).")
return False
return True

sourcery-ai[bot] reacted with thumbs up emoji sourcery-ai[bot] reacted with thumbs down emoji
@@ -50,6 +22,16 @@ def __init__(self, hash_type, hash, charset, progress_interval):
self.__hash_type = hash_type
self.__hash = hash
self.__hashers = {}
self.__init_logger()
Copy link

@sourcery-ai sourcery-ai bot Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Logger initialization adds a new handler every time a Cracker is instantiated.

This can cause duplicate log messages. Please check for existing handlers before adding a new one.

sourcery-ai[bot] reacted with thumbs up emoji sourcery-ai[bot] reacted with thumbs down emoji
Comment on lines +82 to +83
rows = cursor.fetchall()
if rows:
Copy link

@sourcery-ai sourcery-ai bot Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Use named expression to simplify assignment and conditional (use-named-expression)

Suggested change
rows = cursor.fetchall()
if rows:
if rows := cursor.fetchall():

sourcery-ai[bot] reacted with thumbs up emoji sourcery-ai[bot] reacted with thumbs down emoji

def send_requests(n):
try:
for i in range(int(n)):
Copy link

@sourcery-ai sourcery-ai bot Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Replace unused for index with underscore (for-index-underscore)

Suggested change
for i in range(int(n)):
for _ in range(int(n)):

sourcery-ai[bot] reacted with thumbs up emoji sourcery-ai[bot] reacted with thumbs down emoji
Comment on lines +25 to +28
images = {}
for piece in pieces:
images[piece] = pygame.transform.scale(pygame.image.load(f'images/{piece}.png'), (SQUARE_SIZE, SQUARE_SIZE))
return images
Copy link

@sourcery-ai sourcery-ai bot Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): We've found these issues:

Suggested change
images = {}
for piece in pieces:
images[piece] = pygame.transform.scale(pygame.image.load(f'images/{piece}.png'), (SQUARE_SIZE, SQUARE_SIZE))
return images
return {
piece: pygame.transform.scale(
pygame.image.load(f'images/{piece}.png'),
(SQUARE_SIZE, SQUARE_SIZE),
)
for piece in pieces
}

sourcery-ai[bot] reacted with thumbs up emoji sourcery-ai[bot] reacted with thumbs down emoji
Comment on lines +26 to +30
for i in range(len(purchase_list)):
last_item_price = int(driver.find_element(By.CSS_SELECTOR, f"#productPrice{len(purchase_list)-1}").text.replace(",", ""))
if current_money > last_item_price:
purchase_list[-1].click()
current_money -= last_item_price
Copy link

@sourcery-ai sourcery-ai bot Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Replace unused for index with underscore (for-index-underscore)

sourcery-ai[bot] reacted with thumbs up emoji sourcery-ai[bot] reacted with thumbs down emoji
@@ -33,23 +25,16 @@ def scrape_all(self):
try:
j = 0
for i in range(self.page_count):
Copy link

@sourcery-ai sourcery-ai bot Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Replace unused for index with underscore (for-index-underscore)

Suggested change
for i in range(self.page_count):
for _ in range(self.page_count):

sourcery-ai[bot] reacted with thumbs up emoji sourcery-ai[bot] reacted with thumbs down emoji
@ayushh0406 ayushh0406 deleted the ayushh0406-patch-57 branch August 1, 2025 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@sourcery-ai sourcery-ai[bot] sourcery-ai[bot] left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

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