Estoy buscando ejecutar un script de python que llame a los scripts desde la misma carpeta. Sin embargo no sé a qué nivel me tengo que poner para ejecutarlo. De hecho, cuando ejecuto el script en el nivel de su carpeta, tengo los siguientes errores:
[email protected]:~/environment/jom/scraper (master) $ python3 scraper_run.py
Traceback (most recent call last):
File "scraper_run.py", line 3, in <module>
from scraper.scraper_sephora_USA import sephora_usa
[email protected]:~/environment/jom/scraper (master) $ ls
common.py config.py consistency_checks.py constants.py scraper_jom_london.py scraper_run.py scraper_sephora_USA.py
Incluso con un archivo __init__.py
y incluso cuando intento hacerlo desde ~/environment/jom/
:
[email protected]:~/environment/jom (master) $ python scraper/scraper_run.py
File "scraper/scraper_run.py", line 37
logger.info(f"scraping: {perfume_type}, {perfume_name}, {perfume_id}")
^
SyntaxError: invalid syntax
[email protected]:~/environment/jom (master) $ python
Python 2.7.17 (default, Feb 27 2021, 15:10:58)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
[email protected]:~/environment/jom (master) $ python3 scraper/scraper_run.py
Traceback (most recent call last):
File "scraper/scraper_run.py", line 3, in <module>
from scraper.scraper_sephora_USA import sephora_usa
ModuleNotFoundError: No module named 'scraper'
[email protected]:~/environment/jom (master) $ ls
Makefile README.md convert-attribute-emoticlaims-mapping.py docs frontend jom notebooks scraper setup.py
Aqui esta el script:
import click
import os
from scraper.scraper_sephora_USA import sephora_usa
from scraper.scraper_jom_london import jomalone
from scraper.common import load_fragrances, save_to_json
from scraper.constants import SEPHORA_USA_PATH, JOM_LONDON_PATH, SAVE_PATH
from scraper.config import logger
from jom.products import productKey
@click.command()
@click.option("-s", "--site",
required=True,
help="sephora_usa / jomalone")
@click.option("-f", "--filter",
multiple=True,
default=[],
help="multiple choice of fragrance id to scraping")
def run_scraper_sephora(site, filter):
sites_data = {"sephora_usa": {"path": SEPHORA_USA_PATH,
"func": sephora_usa}}
logger.info("loading fragrances data")
df = load_fragrances(sites_data[site]["path"])
if len(filter) != 0:
df = df[df["id"].isin(filter)]
for i, product in df[df["id"].notna()].iterrows():
perfume_name = product["name"]
perfume_id = product["id"]
perfume_type = product["type"]
name_key = productKey(perfume_name)
from scraper_sephora_USA import sephora_usa
.