Reputation: 15559
I have multiple web scraping projects (python + scrapy)
I have a common helper file, that I include in all of these projects, the helper file is something like this:
helper.py
def has_any_numbers(input_str):
if input_str:
return any(char.isdigit() for char in input_str)
else:
return False
def read_env_config(spider):
config = AutoConfig(search_path='../.env')
# output file specifics
spider.region_name = config('REGION_NAME')
spider.aws_access_key_id = config('AWS_ACCESS_KEY_ID')
spider.aws_secret_access_key = config('AWS_SECRET_ACCESS_KEY')
spider.bucket_name = config('BUCKET_NAME')
There are some common config, such as the s3 output path and credentials that I am reading in the helper file... spider
is the main class that I pass into this helper function... not sure if it would be possible to share a static class which has all the config values?
At the moment, I am copying this helper file in every project, is there a way to share this file among multiple project?
Upvotes: 2
Views: 218
Reputation: 563
you could save this file in your python libs folder or site-packages folder. This is where all your python packages are stored. you can then import this file anywhere in your python projects or any of your python projects.
Upvotes: 1