Página 1 de 1

Hablemos de programación

Publicado: Lun Jun 06, 2022 4:50 pm
por verdinegro
Abro el tema porque sé que hay al menos 5 computistas en el foro y sería divertido hablar de programación y no sólo de política.

Aquí el código que usaba en ND para verificar los mensajes pendientes que tenía en cada cuenta en ND. También sirve acá (aunque sólo uso una cuenta). Con creatividad se puede modificar el código para hacer cosas más interesantes. Se puede abrir una cuenta GitHub y crear PR's.

Código: Seleccionar todo

#!/usr/bin/env python3
#
# To use:
# 1. Run `pip install --user selenium
# 2. Download geckodriver from https://github.com/mozilla/geckodriver/releases
# 3. Uncompress the above and copy the binary to your $PATH

import os
import sys
from concurrent.futures import ProcessPoolExecutor as Executor
from multiprocessing import cpu_count

from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.by import By


CREDENTIALS = [
    ['verdinegro', 'mypassword'],
]
BROWSER = os.getenv("BROWSER", "firefox")
USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0'
#URL = "https://www.noticierodigital.com/forum/ucp.php?mode=login"
URL = "https://forond.com/ucp.php?mode=login"


def try_user(credentials):
    username, password = credentials
    if BROWSER == "firefox":
        options = webdriver.FirefoxOptions()
        options.headless = True
        options.set_preference("general.useragent.override", USER_AGENT)
        driver = webdriver.Firefox(options=options, service_log_path=os.devnull)
    else:
        options = webdriver.ChromeOptions()
        options.headless = True
        options.add_argument(f"user-agent='{USER_AGENT}'")
        driver = webdriver.Chrome(options=options)
    with driver:
        driver.get(URL)
        driver.find_element(by=By.ID, value="username").send_keys(username)
        driver.find_element(by=By.ID, value="password").send_keys(password)
        driver.find_element(by=By.NAME, value="login").click()
        try:
            elem = driver.find_element(by=By.ID, value="message")
            print(f"{username}: {elem.text.splitlines()[1]}")
        except WebDriverException:
            elem = driver.find_element(by=By.CLASS_NAME, value='badge')
            print(f"{username}: {elem.text if elem.text else '0'}")


def main():
    if len(CREDENTIALS) == 1:
        try_user(CREDENTIALS[0])
    else:
        cpus = min(cpu_count(), len(CREDENTIALS))
        with Executor(max_workers=cpus) as executor:
            executor.map(try_user, CREDENTIALS)


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        sys.exit(1)

Re: Hablemos de programación

Publicado: Mié Jun 08, 2022 3:39 pm
por computista

Re: Hablemos de programación

Publicado: Vie Jun 10, 2022 8:09 pm
por nerd
Con pyautogui puedes ir a ver una pelí mientras trabajas remoto.
:twisted: :twisted: :twisted:

Código: Seleccionar todo

#! python3

def main():
    import pyautogui

    print('Press Ctrl-C to quit.')
    try:
        while True:
            pyautogui.moveTo(100, 200)
            pyautogui.countdown(10)
            pyautogui.moveTo(100, 250)
            pyautogui.countdown(10)

    except KeyboardInterrupt:
        print('\n')


if __name__ == '__main__':
    main()

Re: Hablemos de programación

Publicado: Sab Jun 11, 2022 3:46 am
por Caminante
Interesante, ojala puedan desarrollarlo.

Esperaré un tema sonre linux ;)

Re: Hablemos de programación

Publicado: Vie Jun 17, 2022 4:09 pm
por verdinegro
Carajo pensé que me habían volado el tema porque lo abrí en HDLQQ.

Cuando me meta en la laptop pruebo eso que trajo nerd.

Re: Hablemos de programación

Publicado: Sab Jun 18, 2022 9:12 am
por verdinegro
nerd escribió: Vie Jun 10, 2022 8:09 pm Con pyautogui puedes ir a ver una pelí mientras trabajas remoto.
:twisted: :twisted: :twisted:
:lol:

En menos líneas:

Código: Seleccionar todo

while True:
    print(" ".join(map(str, range(10, 0, -1))))