Skip to content

Commit de9e57d

Browse files
committed
scrapy
1 parent fb751aa commit de9e57d

File tree

15 files changed

+335
-0
lines changed

15 files changed

+335
-0
lines changed

scrapy/save-categories-in-separated-files/category/__init__.py

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Define here the models for your scraped items
4+
#
5+
# See documentation in:
6+
# http://doc.scrapy.org/en/latest/topics/items.html
7+
8+
import scrapy
9+
10+
class CategoryItem(scrapy.Item):
11+
Title = scrapy.Field()
12+
Date = scrapy.Field()
13+
# extra field used as filename
14+
Category = scrapy.Field()
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Define here the models for your spider middleware
4+
#
5+
# See documentation in:
6+
# http://doc.scrapy.org/en/latest/topics/spider-middleware.html
7+
8+
from scrapy import signals
9+
10+
11+
class CategorySpiderMiddleware(object):
12+
# Not all methods need to be defined. If a method is not defined,
13+
# scrapy acts as if the spider middleware does not modify the
14+
# passed objects.
15+
16+
@classmethod
17+
def from_crawler(cls, crawler):
18+
# This method is used by Scrapy to create your spiders.
19+
s = cls()
20+
crawler.signals.connect(s.spider_opened, signal=signals.spider_opened)
21+
return s
22+
23+
def process_spider_input(self, response, spider):
24+
# Called for each response that goes through the spider
25+
# middleware and into the spider.
26+
27+
# Should return None or raise an exception.
28+
return None
29+
30+
def process_spider_output(self, response, result, spider):
31+
# Called with the results returned from the Spider, after
32+
# it has processed the response.
33+
34+
# Must return an iterable of Request, dict or Item objects.
35+
for i in result:
36+
yield i
37+
38+
def process_spider_exception(self, response, exception, spider):
39+
# Called when a spider or process_spider_input() method
40+
# (from other spider middleware) raises an exception.
41+
42+
# Should return either None or an iterable of Response, dict
43+
# or Item objects.
44+
pass
45+
46+
def process_start_requests(self, start_requests, spider):
47+
# Called with the start requests of the spider, and works
48+
# similarly to the process_spider_output() method, except
49+
# that it doesn’t have a response associated.
50+
51+
# Must return only requests (not items).
52+
for r in start_requests:
53+
yield r
54+
55+
def spider_opened(self, spider):
56+
spider.logger.info('Spider opened: %s' % spider.name)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Define your item pipelines here
4+
#
5+
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
6+
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
7+
8+
import csv
9+
10+
class CategoryPipeline(object):
11+
12+
def process_item(self, item, spider):
13+
14+
# get category and use it as filename
15+
filename = item['Category'] + '.csv'
16+
17+
# open file for appending
18+
with open(filename, 'a') as f:
19+
writer = csv.writer(f)
20+
21+
# write only selected elements
22+
row = [item['Title'], item['Date']]
23+
writer.writerow(row)
24+
25+
#write all data in row
26+
#warning: item is dictionary so item.values() don't have to return always values in the same order
27+
#writer.writerow(item.values())
28+
29+
return item
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Scrapy settings for category project
4+
#
5+
# For simplicity, this file contains only settings considered important or
6+
# commonly used. You can find more settings consulting the documentation:
7+
#
8+
# http://doc.scrapy.org/en/latest/topics/settings.html
9+
# http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
10+
# http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html
11+
12+
BOT_NAME = 'category'
13+
14+
SPIDER_MODULES = ['category.spiders']
15+
NEWSPIDER_MODULE = 'category.spiders'
16+
17+
18+
# Crawl responsibly by identifying yourself (and your website) on the user-agent
19+
#USER_AGENT = 'category (+http://www.yourdomain.com)'
20+
21+
# Obey robots.txt rules
22+
ROBOTSTXT_OBEY = True
23+
24+
# Configure maximum concurrent requests performed by Scrapy (default: 16)
25+
#CONCURRENT_REQUESTS = 32
26+
27+
# Configure a delay for requests for the same website (default: 0)
28+
# See http://scrapy.readthedocs.org/en/latest/topics/settings.html#download-delay
29+
# See also autothrottle settings and docs
30+
#DOWNLOAD_DELAY = 3
31+
# The download delay setting will honor only one of:
32+
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
33+
#CONCURRENT_REQUESTS_PER_IP = 16
34+
35+
# Disable cookies (enabled by default)
36+
#COOKIES_ENABLED = False
37+
38+
# Disable Telnet Console (enabled by default)
39+
#TELNETCONSOLE_ENABLED = False
40+
41+
# Override the default request headers:
42+
#DEFAULT_REQUEST_HEADERS = {
43+
# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
44+
# 'Accept-Language': 'en',
45+
#}
46+
47+
# Enable or disable spider middlewares
48+
# See http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html
49+
#SPIDER_MIDDLEWARES = {
50+
# 'category.middlewares.CategorySpiderMiddleware': 543,
51+
#}
52+
53+
# Enable or disable downloader middlewares
54+
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
55+
#DOWNLOADER_MIDDLEWARES = {
56+
# 'category.middlewares.MyCustomDownloaderMiddleware': 543,
57+
#}
58+
59+
# Enable or disable extensions
60+
# See http://scrapy.readthedocs.org/en/latest/topics/extensions.html
61+
#EXTENSIONS = {
62+
# 'scrapy.extensions.telnet.TelnetConsole': None,
63+
#}
64+
65+
# Configure item pipelines
66+
# See http://scrapy.readthedocs.org/en/latest/topics/item-pipeline.html
67+
ITEM_PIPELINES = {
68+
'category.pipelines.CategoryPipeline': 300,
69+
}
70+
71+
# Enable and configure the AutoThrottle extension (disabled by default)
72+
# See http://doc.scrapy.org/en/latest/topics/autothrottle.html
73+
#AUTOTHROTTLE_ENABLED = True
74+
# The initial download delay
75+
#AUTOTHROTTLE_START_DELAY = 5
76+
# The maximum download delay to be set in case of high latencies
77+
#AUTOTHROTTLE_MAX_DELAY = 60
78+
# The average number of requests Scrapy should be sending in parallel to
79+
# each remote server
80+
#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
81+
# Enable showing throttling stats for every response received:
82+
#AUTOTHROTTLE_DEBUG = False
83+
84+
# Enable and configure HTTP caching (disabled by default)
85+
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
86+
#HTTPCACHE_ENABLED = True
87+
#HTTPCACHE_EXPIRATION_SECS = 0
88+
#HTTPCACHE_DIR = 'httpcache'
89+
#HTTPCACHE_IGNORE_HTTP_CODES = []
90+
#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This package will contain the spiders of your Scrapy project
2+
#
3+
# Please refer to the documentation for information on how to create and manage
4+
# your spiders.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
import scrapy
3+
4+
class ExampleSpider(scrapy.Spider):
5+
name = 'example'
6+
allowed_domains = ['blog.furas.pl']
7+
start_urls = ['http://blog.furas.pl/category/python.html','http://blog.furas.pl/category/html.html','http://blog.furas.pl/category/linux.html']
8+
9+
def parse(self, response):
10+
11+
# get category from url
12+
category = response.url.split('/')[-1][:-5]
13+
14+
urls = response.css('article a::attr(href)').extract() # links to den subpages
15+
16+
for url in urls:
17+
# skip some urls
18+
if ('/tag/' not in url) and ('/category/' not in url):
19+
url = response.urljoin(url)
20+
# add category (as meta) to send it to callback function
21+
yield scrapy.Request(url=url, callback=self.parse_details, meta={'category': category})
22+
23+
def parse_details(self, response):
24+
25+
# get category
26+
category = response.meta['category']
27+
28+
# get only first title (or empty string '') and strip it
29+
title = response.css('h1.entry-title a::text').extract_first('')
30+
title = title.strip()
31+
32+
# get only first date (or empty string '') and strip it
33+
date = response.css('.published::text').extract_first('')
34+
date = date.strip()
35+
36+
yield {
37+
'Title': title,
38+
'Date': date,
39+
'Category': category,
40+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Jak uzyskać polskie znaki w Google Web Fonts,2012.09.05 środa
2+
Jak zrobić authorship dla wszystkich stron,2012.09.17 poniedziałek
3+
"Chowanie napisu ""NIEAKTUALNE"" z oferty otodom.pl",2012.10.14 niedziela
4+
"Status Skype'a w postaci ikony, tekstu lub liczby",2012.10.14 niedziela
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Przycinanie nazwy pliku i katalogu w Bash,2012.09.17 poniedziałek
2+
Przestrzeń wolna (free) a dostępna (available) na dysku pod Linux,2015.07.24 piątek
3+
Sprawdzanie pod Linux rodzaju pamięci RAM,2015.07.27 poniedziałek
4+
Wyszukiwanie w Linux pakietu zawierającego brakujący plik dla Pythona,2015.08.05 środa
5+
Ściąga z komend Unix'a,2015.08.08 sobota
6+
WiFi - standardowe narzędzie,2011.02.25 piątek
7+
Uruchamianie windowsowej gry firmy Artifex Mundi pod Linux 64bit,2015.08.25 wtorek
8+
Nauka Linuksa za darmo na LinuxJourney.com,2016.06.08 środa
9+
Instalacja programu .msi w linuxie,2012.08.12 niedziela
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Shedulers - wykonywanie zadań w odstępie czasu,2016.07.01 piątek
2+
"Książka ""Python For Everyone"" - zabójcza cena.",2016.07.16 sobota
3+
Bitly_API on Python 3,2017.01.01 niedziela
4+
Newslettery na temat Pythona,2016.06.24 piątek
5+
Nieoficjalne repozytorium wersji binarnych Pythona dla Ubuntu i Linux Mint,2016.01.30 sobota
6+
Open Browser czyli przeglądarka Web w Pythonie,2016.05.21 sobota
7+
"12 Portali, które uczą programowania za darmo (według Fortune)",2016.05.22 niedziela
8+
http-prompt - interaktywna linia komend HTTP w Pythonie,2016.05.22 niedziela
9+
httpie - narzędzie w stylu cURL,2016.05.22 niedziela
10+
Python Prompt Toolkit,2016.05.22 niedziela
11+
urlparse przykład,2016.05.22 niedziela
12+
PyCon 2016 nagrania video na YouTube,2016.06.01 środa
13+
Listy darmowych ebooków na temat Pythona,2016.05.27 piątek
14+
Dzień Informatyka 2016,2016.06.06 poniedziałek
15+
Różności - Python - 2016.06.12,2016.06.12 niedziela
16+
Wyniki ankiety PyCharm,2016.06.14 wtorek
17+
"Promocja 45% ""Złota 10-tka"" w helion.pl",2016.06.14 wtorek
18+
Książki w przygotowaniu,2016.06.24 piątek
19+
Promocja 45% na ebooki w ebookpoint.pl,2016.06.15 środa
20+
Helion promocja Wakacje [2016],2016.06.24 piątek
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Automatically created by: scrapy startproject
2+
#
3+
# For more information about the [deploy] section see:
4+
# https://scrapyd.readthedocs.org/en/latest/deploy.html
5+
6+
[settings]
7+
default = category.settings
8+
9+
[deploy]
10+
#url = http://localhost:6800/
11+
project = category

tkinter/grid-columnconfigure-rowconfigure/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,37 @@ root.mainloop()
211211
![#1](images/main-10.png?raw=true)
212212

213213

214+
---
215+
216+
```python
217+
import tkinter as tk
218+
219+
root = tk.Tk()
220+
221+
root.rowconfigure(1, weight=1)
222+
root.rowconfigure(2, weight=4)
223+
root.rowconfigure(3, weight=8)
224+
225+
b0 = tk.Button(root, text="weight=0")
226+
b0.grid(column=0, row=0, stick='ns')
227+
228+
b1 = tk.Button(root, text="weight=1")
229+
b1.grid(column=0, row=1, stick='ns')
230+
231+
b2 = tk.Button(root, text="weight=4")
232+
b2.grid(column=0, row=2, stick='ns')
233+
234+
b3 = tk.Button(root, text="weight=8")
235+
b3.grid(column=0, row=3, stick='ns')
236+
237+
root.mainloop()
238+
```
239+
240+
| at start |
241+
| --- |
242+
| ![#1](images/main-11.png?raw=true) |
243+
244+
| resized (using mouse) |
245+
| --- |
246+
| ![#1](images/main-12.png?raw=true) |
247+
Loading
Loading

tkinter/themes/main-1.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
3+
import tkinter as tk
4+
import tkinter.ttk as ttk
5+
6+
def red_buttons():
7+
s.configure('TButton', background='red')
8+
root.after(200, green_buttons)
9+
10+
def green_buttons():
11+
s.configure('TButton', background='green')
12+
root.after(200, red_buttons)
13+
14+
root = tk.Tk()
15+
16+
s = ttk.Style()
17+
s.configure('TButton', background='pink')#, foreground='red')
18+
19+
ttk.Button(root, text="1").pack()
20+
ttk.Button(root, text="2").pack()
21+
22+
root.after(2000, red_buttons)
23+
24+
root.mainloop()

0 commit comments

Comments
 (0)