Skip to content
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

Opens Chrome for testing in a broken state on Arch Linux #38

Open
annashumate1 opened this issue Jan 18, 2025 · 3 comments
Open

Opens Chrome for testing in a broken state on Arch Linux #38

annashumate1 opened this issue Jan 18, 2025 · 3 comments

Comments

@annashumate1
Copy link

annashumate1 commented Jan 18, 2025

Expected Behavior

Open Chrome for testing in a working state to login into SimpCity session

Actual Behavior

Opens Chrome for testing and messes up the webpage to where I cannot type anything and some features are missing.

Steps to Reproduce the Problem

  1. Enter Link in url field
  2. Choose download location
  3. Press download

Specifications

  • Version: V0.8.5.1 (using Wine)
  • Platform: Arch Linux (EndeavourOS)

Image

@annashumate1 annashumate1 changed the title Opens Chrome for testing instead of Chrome on Arch Linux Opens Chrome for testing in a broken state instead of Chrome on Arch Linux Jan 18, 2025
@annashumate1 annashumate1 changed the title Opens Chrome for testing in a broken state instead of Chrome on Arch Linux Opens Chrome for testing in a broken state on Arch Linux Jan 18, 2025
@annashumate1
Copy link
Author

annashumate1 commented Jan 18, 2025

Working Example of Code that uses the chromium browser instead of the testing branch for simpcity

import os
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import requests

def login_to_simpcity(driver, username, password):
    print("Logging in...")

    username_field = driver.find_element(By.NAME, "login")  
    password_field = driver.find_element(By.NAME, "password")  
    login_button = driver.find_element(By.XPATH, "//button[@type='submit' and contains(@class, 'button--primary')]")

    username_field.send_keys(username)
    password_field.send_keys(password)
    login_button.click()

    time.sleep(3)  
    print("Login successful.")

def get_image_src(driver, image_element):
    try:
        return image_element.get_attribute("src")
    except Exception:
        return driver.execute_script("return arguments[0].getAttribute('src');", image_element)

def download_images_from_simpcity(url, output_dir, username, password):
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    driver = webdriver.Chrome()
    
    try:
        driver.get("https://simpcity.su/login/")  
        time.sleep(3)

        login_to_simpcity(driver, username, password)

        driver.get(url)
        time.sleep(3)  

        images = driver.find_elements(By.TAG_NAME, "img")

        print(f"Found {len(images)} images. Starting download...")

        for i, img in enumerate(images):
            try:
                img_url = get_image_src(driver, img)

                if img_url:
                    response = requests.get(img_url, stream=True)
                    if response.status_code == 200:
                        image_path = os.path.join(output_dir, f"image_{i + 1}.jpg")

                        with open(image_path, "wb") as file:
                            for chunk in response.iter_content(1024):
                                file.write(chunk)

                        print(f"Downloaded: {image_path}")
                    else:
                        print(f"Failed to download image: {img_url}")
            except Exception as e:
                print(f"Error downloading image {i + 1}: {e}")

    finally:

        driver.quit()

if __name__ == "__main__":
    simpcity_url = input("Enter the Simpcity post URL: ").strip()
    username = input("Enter your username: ").strip()
    password = input("Enter your password: ").strip()
    output_directory = "/path/to/destination"
    download_images_from_simpcity(simpcity_url, output_directory, username, password)
    print(f"Images have been downloaded to the '{output_directory}' folder.")

This example is for simpcity exclusively
It's not perfect as it also downloads any emoji's used but it's a rough showcase of the Chromium browser being used instead of testing

@annashumate1
Copy link
Author

Still not working so I created my own repo for it

@Emy69
Copy link
Owner

Emy69 commented Jan 19, 2025

Hello.
I have not had time to fix the error, anyway thanks for reporting it, likewise if you find it useful you can use the CLI that I uploaded from simpcity for your project if you want, again thanks for reporting the error, when I have time I will fix it c:
https://github.com/Emy69/SimpCityCLI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants