Skip to content

Commit cafe236

Browse files
author
INNOVINATI
committed
Added support for image customization
1 parent 59982fa commit cafe236

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
# scrapy-google-chat
1+
# scrapy-googlechat
22
Send crawl reports from Scrapy spiders to Google Chat
33

44
## Usage
55
Create a webhook in Google Chat: https://developers.google.com/hangouts/chat/how-tos/webhooks
66

77
Within your Scrapy project, install the package:
88
```bash
9-
pip install scrapy-google-chat
9+
pip install scrapy-googlechat
1010
```
1111

1212
Register and configure the extension in `settings.py`:
13-
```bash
13+
```python
1414
EXTENSIONS = {
1515
...
1616
'scrapy_google_chat.GoogleChatBot': 100,
1717
...
1818
}
1919
...
20-
GOOGLE_CHAT_WEBHOOK = <YOUR_WEBHOOK>
20+
GOOGLE_CHAT_WEBHOOK = 'YOUR_WEBHOOK'
21+
22+
# Optional: change the image displayed in Google Chat
23+
GOOGLE_CHAT_IMAGE = 'https://img.icons8.com/ios/452/spider.png'
2124
```
2225

2326
You're good to go. Happy crawling!

scrapy_google_chat.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ class GoogleChatBot(object):
1616
1717
"""
1818

19-
def __init__(self, url, stats):
19+
def __init__(self, url, stats, image):
2020
self.url = url
21+
self.image = image
2122
self.crawl_stats = stats
2223
self.item_stats = {'scraped': 0, 'dropped': 0, 'errors': 0}
2324

2425
@classmethod
2526
def from_crawler(cls, crawler):
2627
if not (url := crawler.settings.get('GOOGLE_CHAT_WEBHOOK')):
2728
raise NotConfigured
28-
ext = cls(url, crawler.stats)
29+
image = crawler.settings.get('GOOGLE_CHAT_IMAGE', 'https://img.icons8.com/ios/452/spider.png')
30+
ext = cls(url, crawler.stats, image)
2931
crawler.signals.connect(ext.spider_closed, signal=signals.spider_closed)
3032
crawler.signals.connect(ext.item_scraped, signal=signals.item_scraped)
3133
crawler.signals.connect(ext.item_dropped, signal=signals.item_dropped)
@@ -59,15 +61,14 @@ def _get_duration(self):
5961
minutes, seconds = divmod(remainder, 60)
6062
return f"{hours}h {minutes}m {seconds}s"
6163

62-
@staticmethod
63-
def _get_message(spider_name, stats):
64+
def _get_message(self, spider_name, stats):
6465
return {
6566
'cards': [
6667
{
6768
'header': {
6869
"title": "Spider Report",
6970
"subtitle": f'Name: {spider_name}',
70-
"imageUrl": 'https://img.icons8.com/ios/452/spider.png',
71+
"imageUrl": self.image,
7172
"imageStyle": "IMAGE"
7273
},
7374
'sections': [

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='scrapy-googlechat',
10-
version='1.0',
10+
version='1.1',
1111
description='Send crawl reports from Scrapy spiders to Google Chat',
1212
long_description=long_description,
1313
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)