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

Draft: Added files to create a conda package #15

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Asynchronous mysql [Scrapy](https://doc.scrapy.org/en/latest/) item pipeline

#### Installation

```bash
pip install scrapy-mysql-pipeline
```
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$PYTHON setup.py install # Python command to install the script.
7 changes: 7 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: scrapy-mysql-pipeline
channels:
- conda-forge
dependencies:
- python>=3.8
- scrapy
- sqlalchemy
24 changes: 24 additions & 0 deletions meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package:
name: scrapy-mysql-pipeline
version:

source:
git_rev: conda_package
git_url: https://github.com/phelps-sg/scrapy-mysql-pipeline

requirements:
build:
- python=3.8
- setuptools

run:
- python>=3.8
- scrapy
- sqlalchemy

#test:
# imports:
# -

about:
home:
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

4 changes: 0 additions & 4 deletions requirements_dev.txt

This file was deleted.

20 changes: 19 additions & 1 deletion scrapy_mysql_pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,30 @@ def __init__(self, crawler):
self.retries = self.settings.get('MYSQL_RETRIES', 3)
self.close_on_error = self.settings.get('MYSQL_CLOSE_ON_ERROR', True)
self.upsert = self.settings.get('MYSQL_UPSERT', False)
self.table = self.settings.get('MYSQL_TABLE', None)
table_specifier = self.settings.get('MYSQL_TABLE', None)
if table_specifier is not None:
if '%' in table_specifier:
# Allow spider's name to be substituted using sprintf
self.get_table = lambda: table_specifier % self.spider.name
else:
# Table name is the same for all spiders
self.get_table = lambda: table_specifier
else:
# Default is to use the spider's name as the table name
self.get_table = lambda: self.spider.name

self.db = adbapi.ConnectionPool('pymysql', **db_args)

def close_spider(self, spider):
self.db.close()

def open_spider(self, spider):
self.spider = spider

@property
def table(self):
return self.get_table()

@staticmethod
def preprocess_item(item):
"""Can be useful with extremly straight-line spiders design without item loaders or items at all
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
else:
os.environ.update(SKIP_WRITE_GIT_CHANGELOG='1')
os.environ.update(SKIP_GENERATE_AUTHORS='1')
setuptools.setup(
setup_requires=['pbr', ],
pbr=True
)
# setuptools.setup(
# setup_requires=['pbr', ],
# pbr=True
# )