mirror of https://github.com/scrapy/scrapy.git
added to_date adaptor to format a date suitable for DateField
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40926
This commit is contained in:
parent
3e8945a477
commit
6d2a3e093b
|
|
@ -1,4 +1,5 @@
|
|||
from scrapy.contrib_exp.adaptors.extraction import extract, ExtractImageLinks
|
||||
from scrapy.contrib_exp.adaptors.markup import remove_tags, remove_root, unquote
|
||||
from scrapy.contrib_exp.adaptors.misc import to_unicode, clean_spaces, strip, drop_empty, delist, Regex
|
||||
from scrapy.contrib_exp.adaptors.date import to_date
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
import time
|
||||
|
||||
def to_date(format):
|
||||
"""
|
||||
Converts a date string to a YYYY-MM-DD one suitable for DateField
|
||||
|
||||
format is the format string passed to time.strptime
|
||||
|
||||
Input: string/unicode
|
||||
Output: string
|
||||
"""
|
||||
def _to_date(value):
|
||||
return time.strftime('%Y-%m-%d', time.strptime(value, format))
|
||||
return _to_date
|
||||
Loading…
Reference in New Issue