Skip to content

Commit

Permalink
refactor: for loop instead of while to get machine locations
Browse files Browse the repository at this point in the history
  • Loading branch information
jannisborn committed Nov 16, 2023
1 parent ec9941f commit 136a562
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion backend/pennyme/github_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Any, Dict, List, Tuple

import requests

from pennyme.utils import get_next_free_machine_id

with open("github_token.json", "r") as infile:
Expand Down Expand Up @@ -356,6 +355,8 @@ def get_pr_id(
Args:
branch_name: Name of the branch to check.
owner: Owner of the repository. Defaults to REPO_OWNER.
repo: Name of the repository. Defaults to REPO_NAME.
headers: Headers for the request.
Returns:
Expand Down
18 changes: 9 additions & 9 deletions backend/pennyme/pennycollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def get_raw_locations_from_location_website(website) -> List[bs4.element.Tag]:
return location_raw_list[5:]


def get_location_list_from_location_website(website) -> List[List[str]]:
def get_location_list_from_location_website(
website: bs4.BeautifulSoup,
) -> List[List[str]]:
"""
Retrieves a list of locations from a website of any location, e.g.:
http://209.221.138.252/Locations.aspx?area=42
Expand All @@ -93,15 +95,13 @@ def get_location_list_from_location_website(website) -> List[List[str]]:

# 5 Tags always make up one location
location_list = []
ind = -1
while ind < len(raw_locations) - 1:
ind += 1
content = str(raw_locations[ind])
if ind % 5 == 0:
if ind > 0:
location_list.append(content)
location = []
location = [] # Initialize the location list outside the loop
for ind, content in enumerate(raw_locations):
content = str(content)
location.append(content)
if (ind + 1) % 5 == 0: # Check if 5 tags have been added
location_list.append(location)
location = [] # Reset location for the next set of tags
return location_list


Expand Down

0 comments on commit 136a562

Please sign in to comment.