Skip to content

Commit

Permalink
pylinted parser
Browse files Browse the repository at this point in the history
  • Loading branch information
drveles committed Jun 5, 2024
1 parent fa9893f commit 27cb14f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
10 changes: 4 additions & 6 deletions parser/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@
from parse_raw_from_html import convert_to_json
from parser_sender import update_peers

logging.basicConfig(level=logging.INFO, stream=sys.stdout)
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)

if __name__ == "__main__":
while True:
try:
temp_data = login_and_parse_campus_map()
logging.info("All cluster parsed")
logging.debug("All cluster parsed: %s", temp_data)
temp_json = convert_to_json(temp_data)
logging.info("All converted parsed")
logging.debug("All converted parsed")
update_peers(temp_json)
logging.info("All data from parser sended")
print("All data from parser sended")
logging.debug("All data from parser sended")
except (NoSuchElementException, ElementNotInteractableException) as all_ex:
print("Parse failed, starting next try.")
logging.error("Parse failed, starting next try. ERROR: %s", all_ex)
finally:
continue
8 changes: 4 additions & 4 deletions parser/parse_edu.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def auth_edu(driver):
time.sleep(0.5)
password_field.send_keys(Keys.ENTER)
time.sleep(3)
except Exception as ex:
except (NoSuchElementException, ElementNotInteractableException) as ex:
logging.error("An error occurred while trying to display floors: %s", ex)


Expand All @@ -80,7 +80,7 @@ def displaying_floors(driver):
By.XPATH, '//*[@id="root"]/div[2]/div/div[2]/div[2]/div[1]/button/div'
).click()
time.sleep(1)
except Exception as ex:
except (NoSuchElementException, ElementNotInteractableException) as ex:
logging.error("An error occurred while trying to display floors: %s", ex)


Expand All @@ -103,7 +103,7 @@ def parse_each_cluster(driver) -> set[tuple]:
try:
for cluster_name, cluster_xpath in clusters_xpaths_dct.items():
driver.find_element(By.XPATH, cluster_xpath).click()
time.sleep(4.5)
time.sleep(5)
html = driver.find_element(By.TAG_NAME, "body").get_attribute("innerHTML")
peers_from_this_cluster = parse_raw_data_from_cluster(cluster_name, html)
if not peers_from_this_cluster:
Expand All @@ -112,7 +112,7 @@ def parse_each_cluster(driver) -> set[tuple]:
)
all_peers.update(peers_from_this_cluster)

except Exception as ex:
except (NoSuchElementException, ElementNotInteractableException) as ex:
logging.error("An error occurred while parsing clusters: %s", ex)

return all_peers
Expand Down
4 changes: 2 additions & 2 deletions parser/parser_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def update_peers(data_in_json: dict):
## Sending parsed data to redis API
"""

API_ADDRESS = os.getenv("API_ADDRESS", "localhost")
api_address = os.getenv("API_ADDRESS", "localhost")

url_to_api = f"{API_ADDRESS}:8000"
url_to_api = f"{api_address}:8000"
headers = {"Content-Type": "application/json", "Sender": "update_peers()"}

try:
Expand Down
3 changes: 2 additions & 1 deletion redis/backup_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def redis_restore(backup_file="/backups/redis_backup.rdb"):
shutil.copy2(backup_file, redis_dump_file)
r = create_redis_connect()
logger.info("Restored Redis from backup: %s", backup_file)
return True
except (redis.RedisError, IOError, FileNotFoundError) as ex:
logger.error("An error occurred while restoring: %s", ex)
return False
return True


if __name__ == "__main__":
Expand Down

0 comments on commit 27cb14f

Please sign in to comment.